grunt-dom-munger icon indicating copy to clipboard operation
grunt-dom-munger copied to clipboard

Add a filter option to `read` operation

Open jamesspencer opened this issue 11 years ago • 2 comments

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.

jamesspencer avatar May 08 '13 19:05 jamesspencer

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]);

cgross avatar May 08 '13 19:05 cgross

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.

jamesspencer avatar May 09 '13 09:05 jamesspencer