Skip to content

Commit

Permalink
added support for multiple destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolmeister committed Jul 5, 2013
1 parent 8038fcf commit 557e04f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function(grunt) {
appRoot: 'test/'
},
files: {
'test/fixtures/file.html': 'test/fixtures/*.js'
'test/fixtures/**/*.html': 'test/fixtures/*.js'
}
}
},
Expand Down
29 changes: 13 additions & 16 deletions tasks/scriptlinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,20 @@ module.exports = function(grunt) {
}).join('');


if (!grunt.file.exists(f.dest)) {
grunt.log.warn('Destination file "' + f.dest + '" not found.');
} else {
page = grunt.file.read(f.dest);
grunt.file.expand({}, f.dest).forEach(function(page){

start = page.indexOf(options.startTag);

start = page.indexOf(options.startTag);
end = page.indexOf(options.endTag);

if (start === -1 || end === -1 || start >= end) {
grunt.log.warn('Destination file\'s "' + f.dest + '" start and/or end tag is not correctly setup.');
} else {
newPage = page.substr(0, start + options.startTag.length) + scripts + page.substr(end);
// Insert the scripts
grunt.file.write(f.dest, newPage);
grunt.log.writeln('File "' + f.dest + '" updated.');
}
}
end = page.indexOf(options.endTag);
if (start === -1 || end === -1 || start >= end) {
grunt.log.warn('Destination file\'s "' + f.dest + '" start and/or end tag is not correctly setup.');
} else {
newPage = page.substr(0, start + options.startTag.length) + scripts + page.substr(end);
// Insert the scripts
grunt.file.write(f.dest, newPage);
grunt.log.writeln('File "' + f.dest + '" updated.');
}
});
});
});

Expand Down

0 comments on commit 557e04f

Please sign in to comment.