Skip to content

Commit 53d618b

Browse files
committed
Merge pull request #20 from sidwood/module-option
Add module to available options
2 parents baad256 + 5e89d26 commit 53d618b

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

Gruntfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ module.exports = function(grunt) {
5858
},
5959
src: ['test/fixtures/simple.html'],
6060
dest: 'tmp/simple_prepend.js'
61+
},
62+
target: {
63+
options: {
64+
base: 'test/fixtures',
65+
module: 'ImAModuleNotATarget'
66+
},
67+
src: ['test/fixtures/simple.html'],
68+
dest: 'tmp/options_module.js'
6169
}
6270
}
6371
});

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ which preloads `$templateCache` to prevent round-trips to the server.
3131
```js
3232
// grunt.js
3333
grunt.initConfig({
34-
ngtemplates: {
35-
myapp: {
36-
options: {
34+
ngtemplates: {
35+
build: {
36+
options: {
3737
base: 'src/views', // $templateCache ID will be relative to this folder
38-
prepend: '/static/assets/' // (Optional) Prepend path to $templateCache ID
38+
prepend: '/static/assets/', // (Optional) Prepend path to $templateCache ID
39+
module: 'App' // (Optional) The module the templates will be added to, defaults to target if not present ('build' in this case)
3940
},
4041
src: [ 'src/views/**.html' ],
4142
dest: 'dist/templates.js'
@@ -44,13 +45,10 @@ grunt.initConfig({
4445
});
4546
```
4647

47-
**You should name your sub-target (e.g. `myapp`) after the name of the module the templates will be added to**.
48-
49-
5048
This will generate the following at `dist/templates.js`:
5149

5250
```js
53-
angular.module('myapp').run(['$templateCache', function($templateCache) {
51+
angular.module('App').run(['$templateCache', function($templateCache) {
5452
...
5553
}]);
5654
```

tasks/angular-templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function(grunt) {
1515
var compiler = require('./lib/compiler').init(grunt);
1616

1717
grunt.registerMultiTask('ngtemplates', 'Compile AngularJS templates', function() {
18-
var id = this.target;
18+
var id = this.options().module || this.target;
1919
var files = grunt.file.expand(this.files[0].src);
2020
var dest = path.normalize(this.files[0].dest);
2121
var done = this.async();

test/angular-templates_test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ exports.ngtemplates = {
3333

3434
test.equal(expected, actual, 'should prepend $templateCache ID with /prepend/simple.html"');
3535
test.done();
36+
},
37+
38+
module: function(test) {
39+
test.expect(1);
40+
41+
var actual = grunt.file.read('tmp/options_module.js');
42+
var expected = grunt.file.read('test/expected/options_module.js');
43+
44+
test.equal(expected, actual, 'should set the angular module to the provided options value');
45+
test.done();
3646
}
3747

3848
};

test/expected/options_module.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
angular.module("ImAModuleNotATarget").run(["$templateCache", function($templateCache) {
2+
3+
$templateCache.put("simple.html",
4+
"Howdy there! \\ Your name is \"{{ name }}\"." +
5+
""
6+
);
7+
8+
}]);

0 commit comments

Comments
 (0)