Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

A fix for issue #40 #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tasks/hashresHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ exports.hashAndSub = function(grunt, options) {
grunt.file.expand(f.dest).forEach(function(f) {
var destContents = fs.readFileSync(f, encoding);
files.forEach(function(value) {
grunt.log.debug('Substituting ' + value[0] + ' by ' + value[1])
destContents = destContents.replace(new RegExp(utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), value[1]);
grunt.log.debug('Substituting ' + value[0] + ' by ' + value[1]);
destContents = destContents.replace(new RegExp("([\'\"\/])"+utils.preg_quote(value[0])+"(\\?[0-9a-z]+)?", "g"), "$1"+value[1]);

grunt.log.debug('Substituting ' + nameToNameSearch[value[0]] + ' by ' + value[1])
grunt.log.debug('Substituting ' + nameToNameSearch[value[0]] + ' by ' + value[1]);
destContents = destContents.replace(
new RegExp(nameToNameSearch[value[0]], "g"),
value[1]
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/partial/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<head><script type="text/javascript" src="myscripts.js"></script><script type="text/javascript" src="mobile-myscripts.js"></script></head>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/partial/mobile-myscripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
3 changes: 3 additions & 0 deletions test/fixtures/partial/myscripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
// Nothing to do
})
19 changes: 18 additions & 1 deletion test/hashresHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ vows.describe('hashresHelper').addBatch({
assert(html.indexOf('scripts/5a7a5b61-myscripts2.js') !== -1);
assert(html.indexOf('styles/3b97b071-mystyles1.css') !== -1);
assert(html.indexOf('styles/3b97b071-mystyles2.css') !== -1);
}
},
'for partial sample': function(grunt) {
helper.hashAndSub(
grunt, {
files: [{
src : ['./temp/helper/partial/myscripts.js'],
dest : './temp/helper/partial/index.html',
}],
fileNameFormat: '${hash}.${name}.cache.${ext}',
encoding : 'utf8',
renameFiles : true
});
assert(fs.existsSync('./temp/helper/partial/5a7a5b61.myscripts.cache.js'));

var html = fs.readFileSync('./temp/helper/partial/index.html', 'utf8');
assert(html.indexOf('5a7a5b61.myscripts.cache.js') !== -1);
assert(html.indexOf('mobile-5a7a5b61.myscripts.cache.js') === -1);
},
}
}).export(module);