Skip to content

Commit

Permalink
Merge pull request #20 from sidwood/module-option
Browse files Browse the repository at this point in the history
Add module to available options
  • Loading branch information
ericclemmons committed Apr 24, 2013
2 parents baad256 + 5e89d26 commit 53d618b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ module.exports = function(grunt) {
},
src: ['test/fixtures/simple.html'],
dest: 'tmp/simple_prepend.js'
},
target: {
options: {
base: 'test/fixtures',
module: 'ImAModuleNotATarget'
},
src: ['test/fixtures/simple.html'],
dest: 'tmp/options_module.js'
}
}
});
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ which preloads `$templateCache` to prevent round-trips to the server.
```js
// grunt.js
grunt.initConfig({
ngtemplates: {
myapp: {
options: {
ngtemplates: {
build: {
options: {
base: 'src/views', // $templateCache ID will be relative to this folder
prepend: '/static/assets/' // (Optional) Prepend path to $templateCache ID
prepend: '/static/assets/', // (Optional) Prepend path to $templateCache ID
module: 'App' // (Optional) The module the templates will be added to, defaults to target if not present ('build' in this case)
},
src: [ 'src/views/**.html' ],
dest: 'dist/templates.js'
Expand All @@ -44,13 +45,10 @@ grunt.initConfig({
});
```

**You should name your sub-target (e.g. `myapp`) after the name of the module the templates will be added to**.


This will generate the following at `dist/templates.js`:

```js
angular.module('myapp').run(['$templateCache', function($templateCache) {
angular.module('App').run(['$templateCache', function($templateCache) {
...
}]);
```
Expand Down
2 changes: 1 addition & 1 deletion tasks/angular-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt) {
var compiler = require('./lib/compiler').init(grunt);

grunt.registerMultiTask('ngtemplates', 'Compile AngularJS templates', function() {
var id = this.target;
var id = this.options().module || this.target;
var files = grunt.file.expand(this.files[0].src);
var dest = path.normalize(this.files[0].dest);
var done = this.async();
Expand Down
10 changes: 10 additions & 0 deletions test/angular-templates_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ exports.ngtemplates = {

test.equal(expected, actual, 'should prepend $templateCache ID with /prepend/simple.html"');
test.done();
},

module: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/options_module.js');
var expected = grunt.file.read('test/expected/options_module.js');

test.equal(expected, actual, 'should set the angular module to the provided options value');
test.done();
}

};
8 changes: 8 additions & 0 deletions test/expected/options_module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
angular.module("ImAModuleNotATarget").run(["$templateCache", function($templateCache) {

$templateCache.put("simple.html",
"Howdy there! \\ Your name is \"{{ name }}\"." +
""
);

}]);

0 comments on commit 53d618b

Please sign in to comment.