Skip to content

Commit 0b46368

Browse files
committed
Merge branch 'sprite_dir_warnings' of https://github.com/nuts-rice/martin into sprite_dir_warnings
2 parents 8f339a1 + 7cff982 commit 0b46368

File tree

1 file changed

+41
-48
lines changed
  • martin-core/src/resources/sprites

1 file changed

+41
-48
lines changed

martin-core/src/resources/sprites/mod.rs

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,27 @@ impl SpriteSources {
9191
let mut sprite_output_files = Vec::new();
9292

9393
for entry in entries.flatten() {
94-
let entry_path = entry.path();
95-
if entry_path.is_file() {
96-
file_count += 1;
97-
if let Some(extension) = entry_path.extension() {
98-
let ext = extension.to_string_lossy().to_lowercase();
99-
if ext == "svg" {
100-
svg_count += 1;
101-
} else if ext == "png" || ext == "json" {
102-
let filename = entry_path
103-
.file_stem()
104-
.map(|s| s.to_string_lossy().to_string())
105-
.unwrap_or_default();
106-
if filename.contains("sprite") || filename.contains("@2x") {
107-
sprite_output_files.push(
108-
entry_path
109-
.file_name()
94+
let entry_path = entry.path();
95+
if entry_path.is_file() {
96+
file_count += 1;
97+
if let Some(extension) = entry_path.extension() {
98+
let ext = extension.to_string_lossy().to_lowercase();
99+
if ext == "svg" {
100+
svg_count += 1;
101+
} else if ext == "png" || ext == "json" {
102+
let filename = entry_path.file_stem()
103+
.map(|s| s.to_string_lossy().to_string())
104+
.unwrap_or_default();
105+
if filename.contains("sprite") || filename.contains("@2x") {
106+
sprite_output_files.push(entry_path.file_name()
110107
.map(|s| s.to_string_lossy().to_string())
111-
.unwrap_or_default(),
112-
);
108+
.unwrap_or_default());
109+
}
113110
}
114111
}
115112
}
116113
}
117-
}
114+
118115

119116
if file_count == 0 {
120117
warn!("Sprite source {id} directory is empty: {disp_path}");
@@ -148,7 +145,7 @@ impl SpriteSources {
148145
}
149146
}
150147
}
151-
148+
152149
/// Validates a sprite source directory to ensure it contains valid SVG files.
153150
/// Checks include:
154151
/// - Directory existence and accessibility
@@ -165,7 +162,7 @@ impl SpriteSources {
165162
warn!("Sprite source is not a directory: {disp_path}");
166163
return Err(SpriteError::DirectoryValidationFailed(
167164
path.clone(),
168-
"Path is not a directory".to_string(),
165+
"Path is not a directory".to_string()
169166
));
170167
}
171168

@@ -189,17 +186,13 @@ impl SpriteSources {
189186
warn!("Invalid SVG file {}: {}", entry_path.display(), e);
190187
}
191188
} else if ext == "png" || ext == "json" {
192-
let filename = entry_path
193-
.file_stem()
189+
let filename = entry_path.file_stem()
194190
.map(|s| s.to_string_lossy().to_string())
195191
.unwrap_or_default();
196192
if filename.contains("sprite") || filename.contains("@2x") {
197-
sprite_output_files.push(
198-
entry_path
199-
.file_name()
200-
.map(|s| s.to_string_lossy().to_string())
201-
.unwrap_or_default(),
202-
);
193+
sprite_output_files.push(entry_path.file_name()
194+
.map(|s| s.to_string_lossy().to_string())
195+
.unwrap_or_default());
203196
}
204197
}
205198
}
@@ -211,26 +204,26 @@ impl SpriteSources {
211204
return Err(SpriteError::EmptyDirectory(path.clone()));
212205
}
213206

214-
if svg_count == 0 && sprite_output_files.is_empty() {
215-
warn!(
216-
"No SVG source files found in sprite directory: {disp_path}. \
207+
if svg_count == 0 &&
208+
sprite_output_files.is_empty() {
209+
warn!(
210+
"No SVG source files found in sprite directory: {disp_path}. \
217211
Found pre-generated sprite files: {}. \
218212
Martin requires source SVG files, not pre-generated sprite outputs.",
219-
sprite_output_files.join(", ")
220-
);
221-
return Err(SpriteError::DirectoryValidationFailed(
222-
path.clone(),
223-
format!(
224-
"Directory contains pre-generated sprite files ({}) but no source SVG files. \
225-
Please provide a directory with .svg files instead.",
226213
sprite_output_files.join(", ")
227-
),
228-
));
229-
}
214+
);
215+
return Err(SpriteError::DirectoryValidationFailed(
216+
path.clone(),
217+
format!(
218+
"Directory contains pre-generated sprite files ({}) but no source SVG files. \
219+
Please provide a directory with .svg files instead.",
220+
sprite_output_files.join(", ")
221+
)
222+
));
223+
}
224+
230225

231-
info!(
232-
"Validated sprite directory {disp_path}: found {svg_count} SVG files out of {total_files} total files"
233-
);
226+
info!("Validated sprite directory {disp_path}: found {svg_count} SVG files out of {total_files} total files");
234227
Ok(())
235228
}
236229

@@ -244,22 +237,22 @@ impl SpriteSources {
244237
if content.is_empty() {
245238
return Err(SpriteError::InvalidSvgFormat(
246239
path.clone(),
247-
"File is empty".to_string(),
240+
"File is empty".to_string()
248241
));
249242
}
250243

251244
if !content.starts_with("<?xml") && !content.starts_with("<svg") {
252245
return Err(SpriteError::InvalidSvgFormat(
253246
path.clone(),
254-
"Missing SVG or XML declaration".to_string(),
247+
"Missing SVG or XML declaration".to_string()
255248
));
256249
}
257250

258251
// Check if it contains an SVG tag
259252
if !content.contains("<svg") {
260253
return Err(SpriteError::InvalidSvgFormat(
261254
path.clone(),
262-
"No SVG element found".to_string(),
255+
"No SVG element found".to_string()
263256
));
264257
}
265258

0 commit comments

Comments
 (0)