grunt-dom-munger
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -36,3 +36,5 @@ /* | ||
update: {selector:'html',attribute:'appmode',value:'production'}, | ||
append: {selector:'body',html:'<div id="appended">Im being appended</div>'}, | ||
prefix: {selector:'link',attribute:'href',value:'project-name/'}, | ||
suffix: {selector:'html',attribute:'version',value:'.0.1'}, | ||
append: {selector:'body',html:'<div id="appended">Im being appended</div>'}, | ||
prepend: {selector:'body',html:'<span>Im being prepended</span>'}, | ||
@@ -45,3 +47,3 @@ text: {selector:'title',text:'CHANGED TITLE'}, | ||
src: 'test/fixtures/index.html', | ||
dest: 'tmp/index.html' | ||
dest: 'tmp/index.html' | ||
}, | ||
@@ -48,0 +50,0 @@ test2: { |
{ | ||
"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.0.1", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/cgross/grunt-dom-munger", | ||
@@ -44,3 +44,4 @@ "author": { | ||
"html", | ||
"jquery" | ||
"jquery", | ||
"cheerio" | ||
], | ||
@@ -47,0 +48,0 @@ "dependencies": { |
@@ -18,3 +18,3 @@ # grunt-dom-munger [![Build Status](https://travis-ci.org/cgross/grunt-dom-munger.png?branch=master)](https://travis-ci.org/cgross/grunt-dom-munger) | ||
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
@@ -38,4 +38,6 @@ ```js | ||
remove: '#removeMe', | ||
update: {selector:'html',attribute:'appmode',value:'production'}, | ||
append: {selector:'body',html:'<div id="appended">Im being appended</div>'}, | ||
update: {selector:'html',attribute:'appmode', value:'production'}, | ||
prefix: {selector:'link',attribute:'href',value:'project-name/'}, | ||
suffix: {selector:'html',attribute:'version',value:'.0.1'}, | ||
append: {selector:'body',html:'<div id="appended">Im being appended</div>'}, | ||
prepend: {selector:'body',html:'<span>Im being prepended</span>'}, | ||
@@ -107,3 +109,3 @@ text: {selector:'title',text:'My App'}, | ||
options: { | ||
update: {selector:'html',attribute:'appmode',value:'production'} //set a appmode="production" on <html> | ||
update: {selector:'html',attribute:'appmode', value:'production'}, //set a appmode="production" on <html> | ||
}, | ||
@@ -117,2 +119,36 @@ src: 'index.html', | ||
#### options.prefix | ||
Prepends to the value of a given attribute for the set of matched elements. | ||
```js | ||
grunt.initConfig({ | ||
dom_munger: { | ||
your_target: { | ||
options: { | ||
prefix: {selector:'link',attribute:'href', value:'project-name/'}, //prepend project-name to the href attribute, for example href="project-name/next/path" on <link> | ||
}, | ||
src: 'index.html', | ||
dest: 'dist/index.html' | ||
}, | ||
}, | ||
}) | ||
``` | ||
#### options.suffix | ||
Appends to the value of a given attribute for the set of matched elements. | ||
```js | ||
grunt.initConfig({ | ||
dom_munger: { | ||
your_target: { | ||
options: { | ||
suffix: {selector:'html',attribute:'version', value:'.0.1'}, //append .0.1 to the version attribute, for example version="1.0.1" on <html> | ||
}, | ||
src: 'index.html', | ||
dest: 'dist/index.html' | ||
}, | ||
}, | ||
}) | ||
``` | ||
#### options.append | ||
@@ -252,2 +288,3 @@ Appends the content to each matched element. | ||
* v3.1.0 - Prefix and suffix options added. Fixes for issues #8, #10, and #11. | ||
* v3.0.0 - Removed `jsdom` engine as `cheerio` is as good without needing contextify. | ||
@@ -254,0 +291,0 @@ * v2.0.0 - Moved to `cheerio` engine. Upgraded jquery to v2. |
@@ -57,2 +57,26 @@ /* | ||
if (options.prefix){ | ||
if (!options.prefix.selector || !options.prefix.attribute || !options.prefix.value){ | ||
grunt.log.error('Prefix config missing selector, attribute, and/or value options'); | ||
} else { | ||
$(options.prefix.selector).each(function () { | ||
$(this).attr(options.prefix.attribute, options.prefix.value + $(this).attr(options.prefix.attribute)); | ||
}); | ||
grunt.log.writeln('Prefixed ' + options.prefix.attribute.cyan + ' with ' + options.prefix.value.cyan); | ||
updated = true; | ||
} | ||
} | ||
if (options.suffix){ | ||
if (!options.suffix.selector || !options.suffix.attribute || !options.suffix.value){ | ||
grunt.log.error('Suffix config missing selector, attribute, and/or value options'); | ||
} else { | ||
$(options.suffix.selector).each(function () { | ||
$(this).attr(options.suffix.attribute, $(this).attr(options.suffix.attribute) + options.suffix.value); | ||
}); | ||
grunt.log.writeln('Suffixed ' + options.suffix.attribute.cyan + ' with ' + options.suffix.value.cyan); | ||
updated = true; | ||
} | ||
} | ||
if (options.append){ | ||
@@ -112,3 +136,2 @@ if (!options.append.selector || !options.append.html){ | ||
var done = this.async(); | ||
var countdown = 0; | ||
@@ -133,19 +156,13 @@ if (this.filesSrc.length > 1 && this.data.dest){ | ||
countdown++; | ||
var srcContents = grunt.file.read(f); | ||
var $ = cheerio.load(srcContents); | ||
var $ = cheerio.load(srcContents,{lowerCaseAttributeNames:false}); | ||
processFile(f,dest,options,$); | ||
countdown --; | ||
if (countdown === 0){ | ||
done(); | ||
} | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
20693
260
290