Skip to content

Commit f47f296

Browse files
committed
0.0.3
1 parent 1e59cdc commit f47f296

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
{
22
"name": "gulp-svg-spritesheet",
33
"description": "Gulp SVG sprite sheet generator",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"author": "Darren Hall <[email protected]>",
66
"license": "MIT",
7-
87
"repository": {
98
"type": "git",
109
"url": "https://github.com/iamdarrenhall/gulp-svg-spritesheet.git"
1110
},
12-
1311
"homepage": "https://github.com/iamdarrenhall/gulp-svg-spritesheet",
1412
"bugs": {
1513
"url": "https://github.com/iamdarrenhall/gulp-svg-spritesheet/issues"
1614
},
17-
1815
"keywords": [
1916
"gulpplugin",
2017
"sprite",
2118
"svg"
2219
],
23-
2420
"engines": {
2521
"node": ">=0.10.28"
2622
},
27-
2823
"devDependencies": {
2924
"gulp": "^3.8.9",
3025
"gulp-jshint": "^1.9.0",
3126
"gulp-svgmin": "^0.4.7"
3227
},
33-
3428
"dependencies": {
3529
"cheerio": "^0.17.0",
3630
"gulp-util": "^3.0.1",

0 commit comments

Comments
 (0)