gulp-svgmin
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -0,9 +1,14 @@ | ||
/* jshint node:true */ | ||
'use strict'; | ||
var es = require('event-stream'); | ||
module.exports = function() { | ||
'use strict'; | ||
var svgo = new (require('svgo'))({ plugins: [arguments[0]] }); | ||
return es.map(function(file, cb) { | ||
svgo.optimize(String(file.contents), function(result) { | ||
if (result.error) return cb(result.error); | ||
if (result.error) { | ||
return cb(result.error); | ||
} | ||
file.contents = new Buffer(result.data); | ||
@@ -10,0 +15,0 @@ cb(null, file); |
{ | ||
"name": "gulp-svgmin", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Minify SVG files with gulp.", | ||
@@ -29,3 +29,3 @@ "license": "MIT", | ||
"chai": "~1.8.1", | ||
"gulp-util": "~2.1.3", | ||
"gulp-util": "~2.2.0", | ||
"mocha": "~1.15.1" | ||
@@ -32,0 +32,0 @@ }, |
65
test.js
@@ -0,6 +1,9 @@ | ||
/* jshint node: true */ | ||
/* global describe, it, before, beforeEach, after, afterEach */ | ||
'use strict'; | ||
var expect = require('chai').expect; | ||
var gutil = require('gulp-util'); | ||
var svgmin = require('./index'); | ||
var expect = require('chai').expect, | ||
gutil = require('gulp-util'), | ||
svgmin = require('./index'); | ||
@@ -10,34 +13,36 @@ var doctype = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'; | ||
var raw = '<?xml version="1.0" encoding="utf-8"?>' + doctype + | ||
'<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"> \ | ||
<circle cx="50" cy="50" r="40" fill="yellow" /> \ | ||
</svg>'; | ||
'<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">' + | ||
'<circle cx="50" cy="50" r="40" fill="yellow" />' + | ||
'</svg>'; | ||
var compressed = '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="#ff00"/></svg>'; | ||
it('should minify svg with svgo', function(cb) { | ||
var stream = svgmin(); | ||
stream.on('data', function(data) { | ||
expect(String(data.contents)).to.equal(compressed); | ||
cb(); | ||
describe('gulp-svgmin', function() { | ||
it('should minify svg with svgo', function(cb) { | ||
var stream = svgmin(); | ||
stream.on('data', function(data) { | ||
expect(String(data.contents)).to.equal(compressed); | ||
cb(); | ||
}); | ||
stream.write(new gutil.File({ | ||
contents: new Buffer(raw) | ||
})); | ||
}); | ||
stream.write(new gutil.File({ | ||
contents: raw | ||
})); | ||
}); | ||
it('should honor disabling plugins, such as keeping the doctype', function(cb) { | ||
var stream = svgmin({ | ||
removeDoctype: false | ||
it('should honor disabling plugins, such as keeping the doctype', function(cb) { | ||
var stream = svgmin({ | ||
removeDoctype: false | ||
}); | ||
stream.on('data', function(data) { | ||
expect(String(data.contents)).to.have.string(doctype); | ||
cb(); | ||
}); | ||
stream.write(new gutil.File({ | ||
contents: new Buffer(raw) | ||
})); | ||
}); | ||
stream.on('data', function(data) { | ||
expect(String(data.contents)).to.have.string(doctype); | ||
cb(); | ||
}); | ||
stream.write(new gutil.File({ | ||
contents: raw | ||
})); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5087
51