grunt-dom-munger
grunt-dom-munger copied to clipboard
Add a filter option to `read` operation
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.
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]);
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.