grunt-dom-munger
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -75,4 +75,24 @@ /* | ||
dest: 'tmp/index.html' | ||
}, | ||
test_order: { //order should be read then remove then any other update operations | ||
options: { | ||
read: [ | ||
{selector:'link',attribute:'href',writeto:'links_order',isPath:true}, | ||
{selector:'script',attribute:'src',writeto:'scripts_order',isPath:true} | ||
], | ||
remove: ['script','link'], | ||
append: [ | ||
{selector:'head',html:'<link href="concat.css">'}, | ||
{selector:'body',html:'<script src="concat.js">'} | ||
] | ||
}, | ||
src: 'test/fixtures/order.html', | ||
dest: 'tmp/order.html' | ||
} | ||
}, | ||
write_src: { | ||
test: { | ||
src: ['<%= dom_munger.data.links_order %>','<%= dom_munger.data.scripts_order %>'] | ||
} | ||
}, | ||
concat: { | ||
@@ -104,5 +124,10 @@ test: { | ||
grunt.registerMultiTask('write_src', 'Testing task. Writes src files to file.', function() { | ||
var fs = require('fs'); | ||
fs.writeFileSync('tmp/read_order.txt',JSON.stringify(this.filesSrc)); | ||
}); | ||
// Whenever the "test" task is run, first clean the "tmp" dir, then run this | ||
// plugin's task(s), then test the result. | ||
grunt.registerTask('test', ['clean', 'dom_munger', 'concat', 'nodeunit']); | ||
grunt.registerTask('test', ['clean', 'dom_munger', 'write_src', 'concat', 'nodeunit']); | ||
@@ -109,0 +134,0 @@ // By default, lint and run all tests. |
{ | ||
"name": "grunt-dom-munger", | ||
"description": "Read and manipulate HTML with CSS selectors. Ex. read <script> tags from your html. Remove nodes, add nodes, and more.", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"homepage": "https://github.com/cgross/grunt-dom-munger", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -221,2 +221,12 @@ # grunt-dom-munger [![Build Status](https://travis-ci.org/cgross/grunt-dom-munger.png?branch=master)](https://travis-ci.org/cgross/grunt-dom-munger) | ||
### Quick Note About Ordering | ||
When specifying multiple actions for a single task, the order of the actions is always: | ||
* `read` actions | ||
* `remove` actions | ||
* all other actions | ||
This ensures that you can use one task to read script or link tags, then remove them, then append tags containing the concatentated/minified references. | ||
## Full End-to-End Example for Concatentation and Minification | ||
@@ -230,3 +240,3 @@ | ||
```shell | ||
grunt dom_munger:read copy cssmin uglify dom_munger:update | ||
grunt dom_munger cssmin uglify | ||
``` | ||
@@ -240,26 +250,16 @@ | ||
read: [ | ||
{selector:'link',attribute:'href',writeto:'cssRefs',isPath:true}, | ||
{selector:'script',attribute:'src',writeto:'jsRefs',isPath:true} | ||
] | ||
{selector:'link',attribute:'href',writeto:'cssRefs',isPath:true}, | ||
{selector:'script',attribute:'src',writeto:'jsRefs',isPath:true} | ||
], | ||
remove: ['link','script'], | ||
append: [ | ||
{selector:'head',html:'<link href="css/app.full.min.css" rel="stylesheet">'}, | ||
{selector:'body',html:'<script src="js/app.full.min.js"></script>'} | ||
] | ||
} | ||
}, | ||
src: 'index.html' //read from source index.html | ||
src: 'index.html', //read from source index.html | ||
dest: 'dist/index.html' //update the dist/index.html (the src index.html is copied there) | ||
}, | ||
update: { | ||
options: { | ||
append: [ | ||
{selector:'head',html:'<link href="css/app.full.min.css" rel="stylesheet">'}, | ||
{selector:'body',html:'<script src="js/app.full.min.js"></script>'} | ||
] | ||
}, | ||
src:'dist/index.html' //update the dist/index.html (the src index.html is copied there) | ||
} | ||
}, | ||
copy: { | ||
main: { | ||
files: [ | ||
{src: ['index.html'], dest: 'dist/'} //copy index.html to dist/index.html | ||
] | ||
} | ||
}, | ||
cssmin: { | ||
@@ -281,3 +281,3 @@ main: { | ||
## Release History | ||
* v3.4.0 - Update task actions ordering. Reads always first, removes second, all others after. | ||
* v3.3.0 - All task actions can now be arrays for multiple actions per type. | ||
@@ -284,0 +284,0 @@ * v3.2.0 - Added second `file` argument to callback (#15). |
@@ -55,2 +55,11 @@ /* | ||
if (options.remove){ | ||
options.remove = toArray(options.remove); | ||
options.remove.forEach(function(option) { | ||
$(option).remove(); | ||
grunt.log.writeln('Removed ' + option.cyan); | ||
updated = true; | ||
}); | ||
} | ||
if (options.update){ | ||
@@ -138,11 +147,2 @@ options.update = toArray(options.update); | ||
if (options.remove){ | ||
options.remove = toArray(options.remove); | ||
options.remove.forEach(function(option) { | ||
$(option).remove(); | ||
grunt.log.writeln('Removed ' + option.cyan); | ||
updated = true; | ||
}); | ||
} | ||
if (options.callback){ | ||
@@ -149,0 +149,0 @@ options.callback($, f); |
@@ -47,3 +47,16 @@ 'use strict'; | ||
test.done(); | ||
}, | ||
order: function(test) { | ||
test.expect(2); | ||
var actual = grunt.file.read('tmp/order.html'); | ||
var expected = grunt.file.read('test/expected/order.html'); | ||
test.equal(actual, expected, 'should update the file in the order expected.'); | ||
actual = grunt.file.read('tmp/read_order.txt'); | ||
expected = grunt.file.read('test/expected/read_order.txt'); | ||
test.equal(actual, expected, 'should save the read elements ensuring that the elements were read before the HTML was updated.'); | ||
test.done(); | ||
} | ||
}; |
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
25408
22
352
2