@@ -91,27 +91,30 @@ 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. 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 ( )
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 ( )
107110 . map ( |s| s. to_string_lossy ( ) . to_string ( ) )
108- . unwrap_or_default ( ) ) ;
109- }
111+ . unwrap_or_default ( ) ,
112+ ) ;
110113 }
111114 }
112115 }
113116 }
114-
117+ }
115118
116119 if file_count == 0 {
117120 warn ! ( "Sprite source {id} directory is empty: {disp_path}" ) ;
@@ -145,7 +148,7 @@ impl SpriteSources {
145148 }
146149 }
147150 }
148-
151+
149152 /// Validates a sprite source directory to ensure it contains valid SVG files.
150153 /// Checks include:
151154 /// - Directory existence and accessibility
@@ -162,7 +165,7 @@ impl SpriteSources {
162165 warn ! ( "Sprite source is not a directory: {disp_path}" ) ;
163166 return Err ( SpriteError :: DirectoryValidationFailed (
164167 path. clone ( ) ,
165- "Path is not a directory" . to_string ( )
168+ "Path is not a directory" . to_string ( ) ,
166169 ) ) ;
167170 }
168171
@@ -186,13 +189,17 @@ impl SpriteSources {
186189 warn ! ( "Invalid SVG file {}: {}" , entry_path. display( ) , e) ;
187190 }
188191 } else if ext == "png" || ext == "json" {
189- let filename = entry_path. file_stem ( )
192+ let filename = entry_path
193+ . file_stem ( )
190194 . map ( |s| s. to_string_lossy ( ) . to_string ( ) )
191195 . unwrap_or_default ( ) ;
192196 if filename. contains ( "sprite" ) || filename. contains ( "@2x" ) {
193- sprite_output_files. push ( entry_path. file_name ( )
194- . map ( |s| s. to_string_lossy ( ) . to_string ( ) )
195- . unwrap_or_default ( ) ) ;
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+ ) ;
196203 }
197204 }
198205 }
@@ -204,26 +211,26 @@ impl SpriteSources {
204211 return Err ( SpriteError :: EmptyDirectory ( path. clone ( ) ) ) ;
205212 }
206213
207- if svg_count == 0 &&
208- sprite_output_files. is_empty ( ) {
209- warn ! (
210- "No SVG source files found in sprite directory: {disp_path}. \
214+ if svg_count == 0 && sprite_output_files. is_empty ( ) {
215+ warn ! (
216+ "No SVG source files found in sprite directory: {disp_path}. \
211217 Found pre-generated sprite files: {}. \
212218 Martin requires source SVG files, not pre-generated sprite outputs.",
213- sprite_output_files. join( ", " )
214- ) ;
215- return Err ( SpriteError :: DirectoryValidationFailed (
216- path. clone ( ) ,
217- format ! (
218- "Directory contains pre-generated sprite files ({}) but no source SVG files. \
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. \
219225 Please provide a directory with .svg files instead.",
220- sprite_output_files. join( ", " )
221- )
222- ) ) ;
223- }
224-
226+ sprite_output_files. join( ", " )
227+ ) ,
228+ ) ) ;
229+ }
225230
226- info ! ( "Validated sprite directory {disp_path}: found {svg_count} SVG files out of {total_files} total files" ) ;
231+ info ! (
232+ "Validated sprite directory {disp_path}: found {svg_count} SVG files out of {total_files} total files"
233+ ) ;
227234 Ok ( ( ) )
228235 }
229236
@@ -237,22 +244,22 @@ impl SpriteSources {
237244 if content. is_empty ( ) {
238245 return Err ( SpriteError :: InvalidSvgFormat (
239246 path. clone ( ) ,
240- "File is empty" . to_string ( )
247+ "File is empty" . to_string ( ) ,
241248 ) ) ;
242249 }
243250
244251 if !content. starts_with ( "<?xml" ) && !content. starts_with ( "<svg" ) {
245252 return Err ( SpriteError :: InvalidSvgFormat (
246253 path. clone ( ) ,
247- "Missing SVG or XML declaration" . to_string ( )
254+ "Missing SVG or XML declaration" . to_string ( ) ,
248255 ) ) ;
249256 }
250257
251258 // Check if it contains an SVG tag
252259 if !content. contains ( "<svg" ) {
253260 return Err ( SpriteError :: InvalidSvgFormat (
254261 path. clone ( ) ,
255- "No SVG element found" . to_string ( )
262+ "No SVG element found" . to_string ( ) ,
256263 ) ) ;
257264 }
258265
0 commit comments