grunt-dom-munger
Advanced tools
+1
-2
| language: node_js | ||
| node_js: | ||
| - "0.11" | ||
| - "0.10" | ||
| - "0.8" | ||
| before_script: | ||
| - npm install -g grunt-cli | ||
| - npm install -g grunt-cli |
+4
-2
@@ -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: { |
+3
-2
| { | ||
| "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": { |
+41
-4
@@ -18,3 +18,3 @@ # grunt-dom-munger [](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. |
+26
-9
@@ -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(); | ||
| }); | ||
| }; |
| <!DOCTYPE html> | ||
| <html appmode="production"> | ||
| <head> | ||
| <html version="1.0.1" appmode="production"> | ||
| <head> | ||
| <title>CHANGED TITLE</title> | ||
| <link href="css1.css" rel="stylesheet"> | ||
| <link href="css2.css" rel="stylesheet"> | ||
| <link href="css3.css" rel="stylesheet"> | ||
| <link href="project-name/css1.css" rel="stylesheet"> | ||
| <link href="project-name/css2.css" rel="stylesheet"> | ||
| <link href="project-name/css3.css" rel="stylesheet"> | ||
| </head> | ||
@@ -16,3 +16,5 @@ <body><span>Im being prepended</span> | ||
| </script> | ||
| <!-- viewBox attribute should not be lowercased --> | ||
| <svg viewBox=""></svg> | ||
| <div id="appended">Im being appended</div></body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <html version="1"> | ||
| <head> | ||
| <title></title> | ||
@@ -16,3 +16,5 @@ <link href="css1.css" rel="stylesheet"> | ||
| </script> | ||
| <!-- viewBox attribute should not be lowercased --> | ||
| <svg viewBox=""></svg> | ||
| </body> | ||
| </html> |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
20693
13.37%260
7.88%290
14.62%