cgross / grunt-dom-munger

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

Add a filter option to `read` operation #2

Open jamesspencer opened 11 years ago

jamesspencer commented 11 years ago

It would be very useful to filter the text retrieved during read operations by passing a function to be called each time text is extracted.

My use-case is such that I have to manipulate the urls retrieved when scanning the src attribute of some script tags before they are used in any subsequent tasks.

cgross commented 11 years ago

Hmm. You could always use callback for that. Not sure it would be much simpler if done as part of read. You can write to a task config by doing something like:

grunt.config(['dom_munger','data','stuff'],[1,2,3]);
jamesspencer commented 11 years ago

I'm currently using the callback option to perform this task but the code I've written is almost exactly the same as the read operation with the only difference being a modification of the attribute I've read. I reckon that the ability to mutate the data gathered by read would be useful in enough cases to warrant adding an option for it.

I've added a pull request to show the relatively minimal impact this should have.