Skip to content

Commit

Permalink
Merge pull request #42 from Hobart2967/master
Browse files Browse the repository at this point in the history
Adding prefix option
  • Loading branch information
ptitgraig committed Apr 23, 2016
2 parents d83811a + f214a5a commit bb34cd3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Gruntfile.js
Expand Up @@ -40,6 +40,14 @@ module.exports = function(grunt) {
'tmp/defaults.html': ['test/fixtures/*.js', 'test/fixtures/*.css', 'test/fixtures/component.html', '!test/fixtures/*.min.*']
}
},
prefix: {
options: {
prefix: 'abc'
},
files: {
'tmp/prefix.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 @@ -102,6 +102,12 @@ Default value: `<!-- endinjector -->`
Set the end tag that the injector is looking for. `{{ext}}` is replaced with file extension name, e.g. "css", "js" or "html".
The extension for files collected from from Bower components is prepended with option `bowerPrefix` if given.

#### options.prefix
Type: `String`
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.bowerPrefix
Type: `String`
Default value: `NULL`
Expand Down
3 changes: 2 additions & 1 deletion tasks/injector.js
Expand Up @@ -24,6 +24,7 @@ module.exports = function(grunt) {
template: null,
bowerPrefix: null,
relative: false,
prefix: '',
addRootSlash: (function (that) {
var addRootSlash = true;
if (that.data.options) {
Expand Down Expand Up @@ -152,7 +153,7 @@ module.exports = function(grunt) {
} else {
file = removeRootSlash(file);
}
obj.file = file;
obj.file = options.prefix + file;
});

// Read template:
Expand Down
23 changes: 23 additions & 0 deletions test/expected/prefix.html
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>grunt-injector</title>
<!-- injector:html -->
<link rel="import" href="abc/test/fixtures/component.html">
<!-- endinjector -->
<!-- injector:css -->
<link rel="stylesheet" href="abc/test/fixtures/style.css">
<!-- endinjector -->
<!-- injector:bower:css -->
<!-- endinjector -->
</head>
<body>

<!-- injector:bower:js -->
<!-- endinjector -->
<!-- injector:js -->
<script src="abc/test/fixtures/script.js"></script>
<script src="abc/test/fixtures/script2.js"></script>
<!-- endinjector -->
</body>
</html>
9 changes: 9 additions & 0 deletions test/injector_test.js
Expand Up @@ -36,6 +36,15 @@ exports.injector = {

test.done();
},
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();
},
templateString: function(test) {
test.expect(1);

Expand Down

0 comments on commit bb34cd3

Please sign in to comment.