From 7225dfe8c33780952f3abff4cc030d37cc3b9676 Mon Sep 17 00:00:00 2001 From: Alex Clapperton Date: Mon, 27 Apr 2020 12:07:24 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20breaking=20change=20fr?= =?UTF-8?q?om=20mkdirp=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ec78776..6246e7e 100644 --- a/index.js +++ b/index.js @@ -278,8 +278,9 @@ var spriteSVG = function(options) { // Render our template and then save the file function renderTemplate(file) { var compiled = mustache.render(file.contents, file.data); - mkdirp(path.dirname(file.dest), function(){ - fs.writeFile(file.dest, compiled); + + mkdirp(path.dirname(file.dest)).then(() => { + fs.writeFile(file.dest, compiled); }); } From fabcb7af0ce03dc39de073d76d40e2fc65230725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D0=BC=D0=B8?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B5=D0=B2?= Date: Sun, 17 Apr 2022 17:40:34 +0500 Subject: [PATCH 2/2] getting the fill attribute from the source svg for the sprite --- index.js | 54 ++++++++++++++++++++++++++++++----------------- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index eadc7eb..9cad8d8 100644 --- a/index.js +++ b/index.js @@ -112,17 +112,23 @@ var spriteSVG = function(options) { // For each sprite for (var i in data.sprites) { - var sprite = data.sprites[i], - // Create, initialise and populate an SVG - $svg = $('') - .attr({ - 'height': sprite.h, - 'viewBox': sprite.viewBox, - 'width': sprite.w, - 'x': Math.ceil(sprite.fit.x)+options.padding, - 'y': Math.ceil(sprite.fit.y)+options.padding - }) - .append(sprite.file); + var sprite = data.sprites[i]; + // Create, initialise and populate an SVG + var spriteAttr = { + 'height': sprite.h, + 'viewBox': sprite.viewBox, + 'width': sprite.w, + 'x': Math.ceil(sprite.fit.x)+options.padding, + 'y': Math.ceil(sprite.fit.y)+options.padding + }; + + if (sprite.fill){ + Object.assign(spriteAttr, {'fill': sprite.fill}); + } + + var $svg = $('') + .attr(spriteAttr) + .append(sprite.file); // Check and set parent SVG width if(sprite.fit.x+sprite.w+options.padding>data.width) { @@ -168,15 +174,21 @@ var spriteSVG = function(options) { sprite.y = y+options.padding; // Create, initialise and populate an SVG + var svgSpriteAttrs = { + 'height': sprite.h, + 'viewBox': sprite.viewBox, + 'width': sprite.w, + 'x': Math.ceil(sprite.x), + 'y': Math.ceil(sprite.y) + }; + + if (sprite.fill) { + Object.assign(svgSpriteAttrs, {'fill': sprite.fill}); + } + var $svg = $('') - .attr({ - 'height': sprite.h, - 'viewBox': sprite.viewBox, - 'width': sprite.w, - 'x': Math.ceil(sprite.x), - 'y': Math.ceil(sprite.y) - }) - .append(sprite.file); + .attr(svgSpriteAttrs) + .append(sprite.file); // Round up coordinates sprite.h = Math.ceil(sprite.h); @@ -250,6 +262,10 @@ var spriteSVG = function(options) { w: parseFloat(width) }; + if ($file.attr('fill') !== undefined) { + Object.assign(sprite, {fill: $file.attr('fill')}); + } + // Add the sprite to our array data.sprites.push(sprite); diff --git a/package-lock.json b/package-lock.json index 4bd6ea0..ea8a647 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gulp-svg-spritesheet", - "version": "0.0.5", + "version": "0.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8965324..b71efe2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gulp-svg-spritesheet", "description": "Gulp SVG sprite sheet generator", - "version": "0.0.5", + "version": "0.0.6", "author": "Darren Hall ", "contributors": [ {