Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module to available options #20

Merged
merged 1 commit into from
Apr 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whitespace nazi in me wants to align the // part, but I can't argue with progress!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you mean. I'm a right margin nut so the whole line was making me hyperventilate.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we should work together :)

I ended up splitting it up into 2 lines for v0.3.2, so we both win!

},
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 }}\"." +
""
);

}]);