Comparing version 1.5.0 to 1.6.0
@@ -18,7 +18,11 @@ 'use strict'; | ||
* @Constructor | ||
* @param {Mixed} HTMLParser2 instance, i.e. to support SVG if required. | ||
* @param {Object} options parsing options, optional | ||
* @api public | ||
*/ | ||
function Minimize(options) { | ||
options = options || {}; | ||
function Minimize(parser, options) { | ||
if ('object' !== typeof options) { | ||
options = parser || {}; | ||
parser = void 0; | ||
} | ||
@@ -32,3 +36,3 @@ this.helpers = new Helpers(options); | ||
// | ||
this.htmlparser = new html.Parser( | ||
this.htmlparser = parser || new html.Parser( | ||
new html.DomHandler(this.emits('read')) | ||
@@ -106,12 +110,19 @@ ); | ||
// | ||
// Run the registered plugins before the element is processed. | ||
// Note that the plugins are not run in order. | ||
// | ||
if (!plugins.length) return enter(); | ||
async.eachSeries(plugins, function plug(plugin, next) { | ||
debug('Running plugin for element %s', element.name); | ||
minimize.plugins[plugin].element.call(minimize, element, next); | ||
}, enter); | ||
/** | ||
* Close element in HTML. | ||
* | ||
* @param {Error} error | ||
* @param {String} html | ||
* @api private | ||
*/ | ||
function close(error, html) { | ||
if (error) { | ||
debug('Error received by #close %s', error.message); | ||
return step(error); | ||
} | ||
html += minimize.helpers.close(element); | ||
step(null, html); | ||
} | ||
/** | ||
@@ -139,18 +150,11 @@ * Enter element in HTML. | ||
/** | ||
* Close element in HTML. | ||
* | ||
* @param {Error} error | ||
* @param {String} html | ||
* @api private | ||
*/ | ||
function close(error, html) { | ||
if (error) { | ||
debug('Error received by #close %s', error.message); | ||
return step(error); | ||
} | ||
html += minimize.helpers.close(element); | ||
step(null, html); | ||
} | ||
// | ||
// Run the registered plugins before the element is processed. | ||
// Note that the plugins are not run in order. | ||
// | ||
if (!plugins.length) return enter(); | ||
async.eachSeries(plugins, function plug(plugin, next) { | ||
debug('Running plugin for element %s', element.name); | ||
minimize.plugins[plugin].element.call(minimize, element, next); | ||
}, enter); | ||
}, done); | ||
@@ -157,0 +161,0 @@ }; |
{ | ||
"name": "minimize", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Minimize HTML", | ||
@@ -5,0 +5,0 @@ "main": "./lib/minimize", |
# HTML minifier | ||
[![Version npm][version]](http://browsenpm.org/package/minimize)[![Build Status][build]](https://travis-ci.org/Moveo/minimize)[![Dependencies][david]](https://david-dm.org/moveo/minimize)[![Coverage Status][cover]](https://coveralls.io/r/moveo/minimize?branch=master) | ||
[![Version npm][version]](http://browsenpm.org/package/minimize)[![Build Status][build]](https://travis-ci.org/Swaagie/minimize)[![Dependencies][david]](https://david-dm.org/Swaagie/minimize)[![Coverage Status][cover]](https://coveralls.io/r/Swaagie/minimize?branch=master) | ||
[version]: http://img.shields.io/npm/v/minimize.svg?style=flat-square | ||
[build]: http://img.shields.io/travis/Moveo/minimize/master.svg?style=flat-square | ||
[david]: https://img.shields.io/david/moveo/minimize.svg?style=flat-square | ||
[cover]: http://img.shields.io/coveralls/Moveo/minimize/master.svg?style=flat-square | ||
[build]: http://img.shields.io/travis/Swaagie/minimize/master.svg?style=flat-square | ||
[david]: https://img.shields.io/david/Swaagie/minimize.svg?style=flat-square | ||
[cover]: http://img.shields.io/coveralls/Swaagie/minimize/master.svg?style=flat-square | ||
@@ -56,2 +56,17 @@ Minimize is a HTML minifier based on the node-htmlparser. This depedency will | ||
Supplying a custom instance to do the HTML parsing is possible. I.e. this can | ||
be useful if the HTML contains SVG or if you need to specific options to the parser. | ||
```javascript | ||
var Minimize = require('minimize') | ||
, html = require('htmlparser2') | ||
, minimize = new Minimize(new html.Parser( | ||
new html.FeedHandler((this.emits('read')) | ||
), { /* options */ }); | ||
minimize.parse(content, function (error, data) { | ||
console.log(data); | ||
}); | ||
``` | ||
## Options | ||
@@ -214,3 +229,3 @@ | ||
var Minimize = require('minimize') | ||
, minimize = new Minimize({ plugins: [ | ||
, minimize = new Minimize({ plugins: [{ | ||
id: 'remove', | ||
@@ -221,3 +236,3 @@ element: function element(node, next) { | ||
} | ||
]}); | ||
}]}); | ||
@@ -224,0 +239,0 @@ minimize.parse( |
@@ -9,3 +9,3 @@ 'use strict'; | ||
, Minimize = require('../lib/minimize') | ||
, minimize = new Minimize(); | ||
, minimize | ||
@@ -16,2 +16,10 @@ chai.use(sinonChai); | ||
describe('Minimize', function () { | ||
beforeEach(function () { | ||
minimize = new Minimize(); | ||
}); | ||
afterEach(function () { | ||
minimize = void 0; | ||
}); | ||
describe('is module', function () { | ||
@@ -52,2 +60,9 @@ it('which has a constructor', function () { | ||
it('can be supplied with a custom DOM parser', function () { | ||
minimize = new Minimize({ custom: 'instance' }, { some: 'options'}); | ||
expect(minimize).to.have.property('htmlparser'); | ||
expect(minimize.htmlparser).to.have.property('custom', 'instance'); | ||
}); | ||
it('should start traversing the DOM as soon as HTML parser is ready', function (done) { | ||
@@ -54,0 +69,0 @@ var emit = sinon.spy(minimize, 'emit'); |
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
80909
1640
278