@@ -222,26 +222,32 @@ var spriteSVG = function(options) {
222222 if ( file . isStream ( ) ) {
223223 return cb ( new gutil . PluginError ( PLUGIN_NAME , 'Streams are not supported' ) ) ;
224224 }
225+ console . log ( file . path ) ;
225226 // We're using the filename as the CSS class name
226227 var filename = path . basename ( file . relative , path . extname ( file . relative ) ) ,
227228 // Load the file contents
228229 $file = cheerio . load ( file . contents . toString ( 'utf8' ) , { xmlMode : true } ) ( 'svg' ) ,
229- viewBox = $file . attr ( 'viewBox' ) ,
230- coords = viewBox . split ( " " ) ;
231-
232- // Set sprite data to be used by the positioning function
233- var sprite = {
234- fileName : filename ,
235- file : $file . contents ( ) ,
236- h : parseFloat ( coords [ 3 ] ) ,
237- padding : options . padding ,
238- // Round up coordinates to avoid chopping off edges
239- viewBox : Math . ceil ( coords [ 0 ] ) + " " + Math . ceil ( coords [ 1 ] ) + " " + Math . ceil ( coords [ 2 ] ) + " " + Math . ceil ( coords [ 3 ] ) ,
240- w : parseFloat ( coords [ 2 ] )
241- } ;
242-
243- // Add the sprite to our array
244- data . sprites . push ( sprite ) ;
230+ viewBox = $file . attr ( 'viewBox' ) ;
231+
232+ if ( viewBox ) {
233+ var coords = viewBox . split ( " " ) ;
234+
235+ // Set sprite data to be used by the positioning function
236+ var sprite = {
237+ fileName : filename ,
238+ file : $file . contents ( ) ,
239+ h : parseFloat ( coords [ 3 ] ) ,
240+ padding : options . padding ,
241+ // Round up coordinates to avoid chopping off edges
242+ viewBox : Math . ceil ( coords [ 0 ] ) + " " + Math . ceil ( coords [ 1 ] ) + " " + Math . ceil ( coords [ 2 ] ) + " " + Math . ceil ( coords [ 3 ] ) ,
243+ w : parseFloat ( coords [ 2 ] )
244+ } ;
245+
246+ // Add the sprite to our array
247+ data . sprites . push ( sprite ) ;
248+ } else {
249+ gutil . log ( 'Warning: svg "' + file . path + '" has no viewBox, not adding it to sprite' ) ;
250+ }
245251
246252 // Move on to processSprites()
247253 cb ( ) ;
0 commit comments