Skip to content

Commit

Permalink
Merge pull request #50 from rogozhka/develop
Browse files Browse the repository at this point in the history
Add 'postfix' option
  • Loading branch information
ptitgraig committed Oct 7, 2016
2 parents a0afd26 + 787aed5 commit 7764246
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Gruntfile.js
Expand Up @@ -48,6 +48,14 @@ module.exports = function(grunt) {
'tmp/prefix.html': ['test/fixtures/*.js', 'test/fixtures/*.css', 'test/fixtures/component.html', '!test/fixtures/*.min.*']
}
},
postfix: {
options: {
postfix: '?offset1234567'
},
files: {
'tmp/postfix.html': ['test/fixtures/*.js', 'test/fixtures/*.css', 'test/fixtures/component.html', '!test/fixtures/*.min.*']
}
},
templateString: {
options: {
template: null,
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -112,6 +112,12 @@ Default value: `''`

Set the prefix to append to the beginning of each injected file. Useful to change the directory name in combination with ignorePath.

#### options.postfix
Type: `String`
Default value: `''`

Set the postfix to append to the end of each injected file. Useful to reset cached resources like "/path/to/script.js?offset01".

#### options.bowerPrefix
Type: `String`
Default value: `NULL`
Expand Down
14 changes: 9 additions & 5 deletions tasks/injector.js
Expand Up @@ -25,6 +25,7 @@ module.exports = function(grunt) {
bowerPrefix: null,
relative: false,
prefix: '',
postfix: '',
addRootSlash: (function (that) {
var addRootSlash = true;
if (that.data.options) {
Expand All @@ -35,14 +36,17 @@ module.exports = function(grunt) {
starttag: '<!-- injector:{{ext}} -->',
endtag: '<!-- endinjector -->',
lineEnding: null,
transform: function (filepath) {
var e = ext(filepath);
transform: function (filePath) {

var e = ext(filePath);
var pathToInject = filePath + options.postfix;

if (e === 'css') {
return '<link rel="stylesheet" href="' + filepath + '">';
return '<link rel="stylesheet" href="' + pathToInject + '">';
} else if (e === 'js') {
return '<script src="' + filepath + '"></script>';
return '<script src="' + pathToInject + '"></script>';
} else if (e === 'html') {
return '<link rel="import" href="' + filepath + '">';
return '<link rel="import" href="' + pathToInject + '">';
}
}
});
Expand Down
23 changes: 23 additions & 0 deletions test/expected/postfix.html
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>grunt-injector</title>
<!-- injector:html -->
<link rel="import" href="/test/fixtures/component.html?offset1234567">
<!-- endinjector -->
<!-- injector:css -->
<link rel="stylesheet" href="/test/fixtures/style.css?offset1234567">
<!-- endinjector -->
<!-- injector:bower:css -->
<!-- endinjector -->
</head>
<body>

<!-- injector:bower:js -->
<!-- endinjector -->
<!-- injector:js -->
<script src="/test/fixtures/script.js?offset1234567"></script>
<script src="/test/fixtures/script2.js?offset1234567"></script>
<!-- endinjector -->
</body>
</html>
15 changes: 12 additions & 3 deletions test/injector_test.js
Expand Up @@ -38,11 +38,20 @@ exports.injector = {
},
prefix: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/prefix.html');
var expected = grunt.file.read('test/expected/prefix.html');
test.equal(actual, expected, 'should inject stylesheets, scripts and html components into desired file having a prefix added.');


test.done();
},
postfix: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/postfix.html');
var expected = grunt.file.read('test/expected/postfix.html');
test.equal(actual, expected, 'should inject stylesheets, scripts and html components into desired file having a prefix added.');

test.done();
},
templateString: function(test) {
Expand Down Expand Up @@ -168,7 +177,7 @@ exports.injector = {
var actual = grunt.file.read('tmp/bowerWithOverrides.html');
var expected = grunt.file.read('test/expected/bowerWithOverrides.html');
test.equal(actual, expected,'should inject dependencies installed with bower, and it should take the bower `overrides` declaration into account.');

test.done();
},
custom: function(test) {
Expand Down

0 comments on commit 7764246

Please sign in to comment.