cgross / grunt-dom-munger

Grunt task to read and manipulate HTML with CSS selectors.
MIT License
93 stars 40 forks source link

Added support for arrays of configurations in each option #16

Closed ProLoser closed 10 years ago

ProLoser commented 10 years ago

Now the following format is also supported:

options: {
        read: [{selector:'link',attribute:'href',writeto:'myCssRefs',isPath:true}],
        remove: ['#removeMe'],
        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>'}],
        text: [{selector:'title',text:'My App'}]
}

I'm aware remove doesn't really need to be an array, but I figured devs are probably going to complain about it eventually (instead of using commas) so I added support for it too. I did not add array support to callback though.

This allows you to do things like reading multiple chunks to multiple data stores, as well as performing all other options in different ways without having to fire multiple task targets.

cgross commented 10 years ago

Ah! Excellent idea. It will help keep the config less verbose.

Could you just add some docs and add a test for changes? For a test, you can simply create a new target in the Gruntfile.js that used the array format and add another method in the test class to ensure the changes were as expected.

ProLoser commented 10 years ago

@cgross tests added

cgross commented 10 years ago

Thanks for the PR. Its an addition that seems obvious in retrospect!