dwightjack / grunt-premailer

Grunt wrapper task for Premailer
MIT License
114 stars 16 forks source link

process individual files instead of concatenating #18

Closed amclin closed 10 years ago

amclin commented 10 years ago

Fix #16 and #17 by allowing grunt-premailer to operate on multiple files instead of concatenating files into one massive output.

dwightjack commented 10 years ago

Thanks for contributing.

Just one note: I've added some filtering and checking to ensure that src is just a single file before using .toString() on it, since using a notaion like:

files: {
    'dest.html': ['src1.html', 'src2.html']
}

would have resulted in a string like 'src1.html,src2.html'

amclin commented 10 years ago

by doing file.each() don't you gaurantee you're getting a single file back from the grunt files object to use in the loop?

dwightjack commented 10 years ago

As far as i know every element into the this.files array has a src array property with input files and a dest string property with output array. This way you can process multiple input files to a single one.

This should be the relevant line in Grunt source: https://github.com/gruntjs/grunt/blob/master/lib/grunt/file.js#L177

amclin commented 10 years ago

From my understanding, if you provide the following as a config object:

files : {
  'dest.html': ['src1.html','src2.html']
}

The resulting file object (once the config is processed as filters) looks like this:

files: [
  {
    src: 'src1.html',
    dest: 'dest.html'
  },
  {
    src: 'src2.html',
    dest: 'dest.html'
  }
]

As such, an extra check to make sure that the destination or source of a given file pairing is a single file isn't necessary.