diff --git a/_makeDocs.js b/_makeDocs.js index febdaa3..f9e6063 100644 --- a/_makeDocs.js +++ b/_makeDocs.js @@ -2,8 +2,8 @@ var fs = require("fs"); var cp = require("child_process"); var doc = "./doc/yuidoc.json"; var marked = require("marked"); -var dust = require("dustjs-linkedin"); -dust.optimizers.format = function(ctx, node) { return node; }; +// var dust = require("dustjs-linkedin"); +// dust.optimizers.format = function(ctx, node) { return node; }; var mdTemp = fs.readFileSync("./tmpl/readme.txt", "utf-8"); var readme = fs.readFileSync("./README.md", "utf-8"); @@ -48,4 +48,4 @@ cp.spawn('gulp', ['docs'], {stdio: 'inherit'}).on('close', function () { fs.writeFileSync("./README.md", newReadme); }); -}); \ No newline at end of file +}); diff --git a/example-stream.js b/example-stream.js index 059855c..4208292 100644 --- a/example-stream.js +++ b/example-stream.js @@ -12,9 +12,14 @@ var config = { mode: "sprite" }; +console.info('creating svg sprite from ' + paths.svgSrc); + + fs.src("test/fixtures/basic/*.svg") .pipe(svgSprites(config)) .pipe(fs.dest(paths.svgDest)) .pipe(filter("**/*.svg")) .pipe(svg2png()) .pipe(fs.dest(paths.svgDest)); + +console.info('files are saved to ' + paths.svgDest); diff --git a/index.js b/index.js index d75d868..dfff63c 100755 --- a/index.js +++ b/index.js @@ -2,19 +2,11 @@ var SpriteData = require("svg-sprite-data"); var through2 = require("through2"); var gutil = require("gulp-util"); var File = gutil.File; -var dust = require("dustjs-linkedin"); var fs = require("fs"); var Q = require("q"); var _ = require("lodash"); var path = require("path"); -/** - * Make Dust templates retain whitespace - * @param ctx - * @param node - * @returns {*} - */ -dust.optimizers.format = function(ctx, node) { return node; }; var PLUGIN_NAME = "gulp-svg-sprites"; @@ -350,20 +342,25 @@ function makeFile(template, fileName, stream, data) { var deferred = Q.defer(); var id = _.uniqueId(); + var out = ""; + + try{ + var compiled = _.template(template); + out = compiled(data); + }catch(e){ + deferred.reject(e); + return deferred.promise; + } - dust.compileFn(template, id, false); - - dust.render(id, data, function (err, out) { - stream.push(new File({ - cwd: "./", - base: "./", - path: fileName, - contents: new Buffer(out) - })); + stream.push(new File({ + cwd: "./", + base: "./", + path: fileName, + contents: new Buffer(out) + })); - deferred.resolve(out); - }); + deferred.resolve(out); return deferred.promise; } @@ -402,13 +399,15 @@ module.exports = function (config) { var stream = this; spriter.compile(config, function (err, svg) { - var onDoneTransformData = function (data) { - config.afterTransform(data, config, onDoneAfterTransformData); - }; var onDoneAfterTransformData = function (data) { writeFiles(stream, config, svg.svg, data, cb.bind(null, null)); }; + var onDoneTransformData = function (data) { + config.afterTransform(data, config, onDoneAfterTransformData); + }; + + if (config.asyncTransforms) { config.transformData(svg.data, config, onDoneTransformData); } else { diff --git a/package.json b/package.json index 7b62470..2d62812 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gulp-svg-sprites", "description": "Create SVG sprites with PNG fallbacks", - "version": "3.0.0", + "version": "4.0.0", "homepage": "", "repository": { "type": "git", @@ -17,23 +17,21 @@ } ], "scripts": { - "test": "gulp lint && mocha --recursive test/specs" + "test": "gulp lint && mocha --recursive test/specs", + "example": "node example-stream.js" }, "main": "index.js", "engines": { "node": ">= 0.10.0" }, "dependencies": { - "dust": "^0.3.0", - "dustjs-linkedin": "^2.4.0", - "gulp-util": "^3.0.0", - "libxmljs": "^0.14.1", - "lodash": "^2.4.1", - "q": "^1.0.1", - "svg-sprite-data": "^2.0.0", - "svgo": "^0.5.0", - "through2": "^0.4.1", - "vinyl": "^0.2.3" + "gulp-util": "3.0.7", + "lodash": "4.14.1", + "q": "1.4.1", + "svg-sprite-data": "3.0.0", + "svgo": "0.6.6", + "through2": "2.0.1", + "vinyl": "1.2.0" }, "keywords": [ "svg", @@ -41,18 +39,19 @@ "gulpplugin" ], "devDependencies": { - "chai": "~1.9.0", - "gulp": "^3.8.6", - "gulp-clean": "^0.3.1", - "gulp-contribs": "0.0.2", - "gulp-filter": "^0.5.0", - "gulp-jshint": "~1.4.0", - "gulp-svg2png": "^0.3.0", - "gulp-yuidoc": "^0.1.2", - "img-compare": "^1.2.0", - "marked": "^0.3.2", - "mocha": "~1.18.0", - "sinon": "~1.8.2", - "vinyl-fs": "^0.1.4" + "chai": "3.5.0", + "gulp": "3.9.1", + "gulp-clean": "0.3.2", + "gulp-contribs": "0.0.3", + "gulp-filter": "4.0.0", + "gulp-jshint": "2.0.1", + "gulp-svg2png": "2.0.0", + "gulp-yuidoc": "0.1.2", + "img-compare": "1.2.0", + "jshint": "^2.9.1", + "marked": "0.3.6", + "mocha": "3.0.1", + "sinon": "1.17.5", + "vinyl-fs": "2.4.3" } } diff --git a/tmpl/preview-symbol.html b/tmpl/preview-symbol.html index 769df48..2a40ca5 100644 --- a/tmpl/preview-symbol.html +++ b/tmpl/preview-symbol.html @@ -8,7 +8,7 @@