Luismahou/grunt-hashres — pull request #39 by ebello (2014-05-12 18:43:58+00:00)
Title: Take file path into account when substituting

I have a use case similar to the test, in that I have two files of the same name in different directories that both need to be substituted in my file. In the current version of hashres it only takes the filename into account when substituting, so in the destination file both instances would be replaced with the same hash.

The easiest way I found to take path into account is to find the common path that all files in the src have and remove that when considering the substitution. The test file illustrates this. The files to be hashed are:

```
./temp/helper/subfolders-same-filename/scripts/myscripts1.js
./temp/helper/subfolders-same-filename/scripts/sub/myscripts1.js
./temp/helper/subfolders-same-filename/styles/mystyles1.css
./temp/helper/subfolders-same-filename/styles/sub/mystyles1.css
```

In the destination file though, the files are referenced relatively:
```
scripts/myscripts1.js
scripts/sub/myscripts1.js
styles/mystyles1.css
styles/sub/mystyles1.css
```

So, it would not suffice to simply substitute by file path + file name. This code introduces a `findCommonPath` method that will end up removing `./temp/helper/subfolders-same-filename/` above in order to substitute as expected.

This is a breaking change, however, as the following src list may break for substitutions, depending on how the destination file is referencing the source files:
```javascript
// this may not work as expected
files: [{
src : grunt.file.expand([
'./temp/helper/subfolders-same-filename/scripts/**/*.js',
'./another-location/helper/subfolders-same-filename/styles/**/*.css']),
dest: './temp/helper/subfolders-same-filename/index.html'
}],
```

Although, my guess is that in practice this functionality change wouldn't affect most implementations. An alternative is to perhaps add a flag in options to take path substitutions into account.