cgross / grunt-dom-munger

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

Resolving relative paths #14

Closed michal-novacek closed 10 years ago

michal-novacek commented 10 years ago

Hello, this is more of a general grunt question, not an issue with your awesome module.

I want to check if files linked from src attributes of multiple html files exist. Since the src links have relative paths, I need to know which file I am processing.

I want to do (config):

dom_munger: { html: { options: { callback: function($) { $('*').each(function() { if (this.type === 'script' && this.attribs.src) { // check if linked files actually exist if (!grunt.file.read(CURRENT_FILEPATH + this.attribs.src)) { grunt.fail.fatal('you have linked a file which does not exist'); } } }); } } } }

Can you advise how to get the CURRENT_FILEPATH inside the callback function?

grunt.task.current.data.files[0].src does not work because I am passing a glob match pattern such as:
files: [{ expand: true, src: 'something/else/*/.html' }]

Cheers,

Mike

cgross commented 10 years ago

Hmm. There isn't a way the callback can figure out which file is being processed. It would require a change to the the task so that its passed as an extra argument to the callback fn.

I will look at it when I have some time. I'm sure it will be pretty simple. A pull request with the functionality would be great!

michal-novacek commented 10 years ago

Pull request at https://github.com/cgross/grunt-dom-munger/pull/15