Comparing version 0.1.0 to 0.1.1
@@ -17,4 +17,8 @@ /* jshint node: true, strict: true */ | ||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
if (file.isStream()) { | ||
return stream.emit("error", new PluginError(pluginName, "Streams are not supported!")); | ||
return stream.emit("error", new PluginError(pluginName, "Streaming not supported")); | ||
} | ||
@@ -21,0 +25,0 @@ |
{ | ||
"name": "gulp-dom", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Gulp plugin for generic DOM manipulation", | ||
@@ -19,2 +19,4 @@ "main": "lib/dom.js", | ||
"gulpplugin", | ||
"gulp", | ||
"jsdom", | ||
"dom", | ||
@@ -28,3 +30,7 @@ "html" | ||
"mocha": "latest", | ||
"chai": "latest" | ||
"request": "latest", | ||
"vinyl-source-stream": "latest", | ||
"vinyl-buffer": "latest", | ||
"chai": "latest", | ||
"gulp": "latest" | ||
}, | ||
@@ -31,0 +37,0 @@ "dependencies": { |
# gulp-dom | ||
Gulp plugin for general DOM manipulation. | ||
Gulp plugin for generic DOM manipulation. | ||
@@ -9,13 +9,22 @@ This [Gulp](http://gulpjs.com/) plugin is a simple wrapper around | ||
This can be used for several things in a build process. Some examples: | ||
* [Append a version number](https://github.com/trygve-lie/gulp-dom/tree/master/examples/append-version) or any other "stamp data" to the document on build time. | ||
* [Extract inline scripts / css](https://github.com/trygve-lie/gulp-dom/tree/master/examples/extract-inline-scripts) and put them in a separate file. | ||
* [Fix unvalid markup.](https://github.com/trygve-lie/gulp-dom/tree/master/examples/fix-unvalid-markup) | ||
* [Remove whitespace](https://github.com/trygve-lie/gulp-dom/tree/master/examples/remove-whitespace) in the document in a safe way. | ||
* [Replace script / css references](https://github.com/trygve-lie/gulp-dom/tree/master/examples/replace-script-tags) with a new reference (to ex a minified version). | ||
* [Web scraping.](https://github.com/trygve-lie/gulp-dom/tree/master/examples/web-scrape) Take a document from a URL and transform it or extract parts of it during build. | ||
## <a name='installation'>Installation</a> | ||
## Installation | ||
```bash | ||
$ npm install gulp-dom | ||
```` | ||
``` | ||
## <a name='basic_example'>Basic example</a> | ||
## Basic example | ||
@@ -40,3 +49,3 @@ Example on adding a `data` attribute with a version number on the `body` tag of | ||
## <a name='usage'>Usage</a> | ||
## Usage | ||
@@ -46,3 +55,3 @@ The plugin has only one method which takes two attributes: | ||
### <a name='mutator'>mutator</a> | ||
### mutator | ||
@@ -82,3 +91,3 @@ Type: `function` | ||
### <a name='serialize'>serialize</a> | ||
### serialize | ||
@@ -109,3 +118,3 @@ Type: `Boolean` | ||
## <a name='jsdom'>A note on jsdom</a> | ||
## A note on jsdom | ||
@@ -122,7 +131,7 @@ This plugin wraps [jsdom](https://github.com/tmpvar/jsdom). Though, this plugin | ||
## <a name='tests'>Tests</a> | ||
## Tests | ||
```bash | ||
$ npm test | ||
```` | ||
``` | ||
@@ -133,3 +142,3 @@ Tests are written in [mocha](http://visionmedia.github.io/mocha/). | ||
## <a name='license'>License</a> | ||
## License | ||
@@ -136,0 +145,0 @@ The MIT License (MIT) |
@@ -8,30 +8,82 @@ /* jshint node: true, strict: true */ | ||
assert = require('chai').assert, | ||
utils = require('gulp-util'), | ||
jsdom = require('jsdom'), | ||
dom = require('../'); | ||
dom = require('../'); | ||
function createFixture(markup) { | ||
return new utils.File({ | ||
cwd: './', | ||
base: './', | ||
path: './', | ||
contents: new Buffer(markup) | ||
}); | ||
} | ||
describe('foo', function(){ | ||
describe('bar', function(){ | ||
it('xyz', function(done){ | ||
var result = '<section id="root"></section>'; | ||
describe('gulp-dom()', function(){ | ||
jsdom.env('<section id="root"></section>', function(error, window){ | ||
var doc = window.document, | ||
root = doc.getElementById('root'), | ||
elements = []; | ||
describe('error handling', function(){ | ||
utils.appendMultipleChildElements(root, elements); | ||
it('should pass file when it isNull()', function(done) { | ||
var stream = dom(); | ||
var mockFile = { | ||
isNull: function() { | ||
return true; | ||
} | ||
}; | ||
assert.equal(result, root.outerHTML); | ||
stream.on('data', function(data) { | ||
assert.equal(data, mockFile); | ||
done(); | ||
}); | ||
stream.write(mockFile); | ||
}); | ||
it('should emit error when file isStream()', function (done) { | ||
var stream = dom(); | ||
var mockFile = { | ||
isNull: function () { | ||
return false; | ||
}, | ||
isStream: function () { | ||
return true; | ||
} | ||
}; | ||
stream.on('error', function (err) { | ||
assert.equal(err.message, 'Streaming not supported'); | ||
done(); | ||
}); | ||
stream.write(mockFile); | ||
}); | ||
}); | ||
describe('parsing', function(){ | ||
it('should manipulate document', function (done) { | ||
var result = '<html><head></head><body><p id="test">foo</p></body></html>'; | ||
var fixture = createFixture('<html><body><p id="test">test</p></body></html>'); | ||
var stream = dom(function(){ | ||
this.getElementById('test').innerHTML = 'foo'; | ||
return this; | ||
}); | ||
stream.on('data', function (data) { | ||
assert.equal(data.contents.toString("utf8"), result); | ||
done(); | ||
}); | ||
stream.write(fixture); | ||
}); | ||
}); | ||
}); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
18093
19
281
159
7
1