grunt-angular-templates
Advanced tools
Comparing version 0.3.8 to 0.3.9
@@ -73,10 +73,41 @@ /* | ||
}, | ||
target: { | ||
moduleString: { | ||
options: { | ||
base: 'test/fixtures', | ||
module: 'ImAModuleNotATarget' | ||
module: 'ImNotATarget' | ||
}, | ||
src: ['test/fixtures/simple.html'], | ||
dest: 'tmp/options_module.js' | ||
dest: 'tmp/module_option_string.js' | ||
}, | ||
moduleObject: { | ||
options: { | ||
base: 'test/fixtures', | ||
module: { | ||
name: 'ImNotATarget', | ||
define: true | ||
} | ||
}, | ||
src: ['test/fixtures/simple.html'], | ||
dest: 'tmp/module_option_object.js' | ||
}, | ||
moduleObjectName: { | ||
options: { | ||
base: 'test/fixtures', | ||
module: { | ||
name: 'ImNotATarget' | ||
} | ||
}, | ||
src: ['test/fixtures/simple.html'], | ||
dest: 'tmp/module_option_object_name.js' | ||
}, | ||
moduleObjectDefine: { | ||
options: { | ||
base: 'test/fixtures', | ||
module: { | ||
define: true | ||
} | ||
}, | ||
src: ['test/fixtures/simple.html'], | ||
dest: 'tmp/module_option_object_define.js' | ||
}, | ||
concatSimple: { | ||
@@ -102,3 +133,3 @@ options: { | ||
src: 'test/fixtures/simple.html', | ||
dest: 'tmp/options_noConflict_fixture.js' | ||
dest: 'tmp/noConflict_option_fixture.js' | ||
}, | ||
@@ -105,0 +136,0 @@ } |
{ | ||
"name": "grunt-angular-templates", | ||
"description": "Grunt build task to concatenate & register your AngularJS templates in the $templateCache", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"homepage": "https://github.com/ericclemmons/grunt-angular-templates", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -40,3 +40,8 @@ # grunt-angular-templates [![Build Status](https://travis-ci.org/ericclemmons/grunt-angular-templates.png?branch=master)](https://travis-ci.org/ericclemmons/grunt-angular-templates) | ||
module: 'App' // (Optional) The module the templates will be added to | ||
// Defaults to target name (e.g. `build`) | ||
// Defaults to grunt target name (e.g. `myapp`) | ||
// ...or... | ||
module: { | ||
name: 'App', // (Optional) Explicitly define module name | ||
define: true // (Optional) Define new module (Default: false) | ||
}, | ||
concat: 'dist/js/app.js' // (Optional) Append to existing `concat` target | ||
@@ -137,4 +142,37 @@ noConflict: 'otherAngular' // (Optional) Name of angular.noConflict() app uses | ||
### Defining an Angular Module | ||
It's possible to define a new angular module in the generated JS file. | ||
```js | ||
ngtemplates: { | ||
myapp: { | ||
options: { | ||
module: { | ||
name: 'templates', | ||
define: true | ||
} | ||
}, | ||
src: 'src/views/**.html', | ||
dest: 'dist/templates.js' | ||
} | ||
} | ||
``` | ||
This will generate the following at `dist/templates.js`: | ||
```js | ||
angular.module('templates', []).run(['$templateCache', function($templateCache) { | ||
... | ||
}]); | ||
``` | ||
If you want the templates to append to a *pre-existing* module, simply leave off the `define` option by default. | ||
## Changelog | ||
### v0.3.9 | ||
- Allow the creation of a new module via `module.define`, thanks to @sidwood ([#28](https://github.com/ericclemmons/grunt-angular-templates/pull/28)) | ||
### v0.3.8 | ||
@@ -141,0 +179,0 @@ |
@@ -19,3 +19,3 @@ /* | ||
grunt.registerMultiTask('ngtemplates', 'Compile AngularJS templates', function() { | ||
var id = this.options().module || this.target; | ||
var id = this.target; | ||
var noConflict = this.options().noConflict || 'angular'; | ||
@@ -26,4 +26,17 @@ var files = grunt.file.expand(this.files[0].src); | ||
var options = this.options(); | ||
var define = false; | ||
compiler.compile(id, noConflict, options, files, function(err, compiled) { | ||
if (options.module) { | ||
if (typeof options.module === 'string') { | ||
id = options.module; | ||
} else if (options.module.hasOwnProperty('name') && typeof options.module.name === 'string') { | ||
id = options.module.name; | ||
} | ||
if (options.module.hasOwnProperty('define') && options.module.define === true ) { | ||
define = true; | ||
} | ||
} | ||
compiler.compile(id, noConflict, define, options, files, function(err, compiled) { | ||
if (err) { | ||
@@ -30,0 +43,0 @@ done(false); |
@@ -26,5 +26,11 @@ /* | ||
var compile = function(id, noConflict, options, files, callback) { | ||
var template = '<%= noConflict %>.module("<%= id %>").run(["$templateCache", function($templateCache) {\n<%= content %>\n}]);\n'; | ||
var compile = function(id, noConflict, define, options, files, callback) { | ||
var template = '<%= noConflict %>.module("<%= id %>"'; | ||
if (define) { | ||
template += ', []'; | ||
} | ||
template += ').run(["$templateCache", function($templateCache) {\n<%= content %>\n}]);\n'; | ||
concat(options, files, function(err, concated) { | ||
@@ -31,0 +37,0 @@ var compiled = process(template, id, concated.join(''), noConflict); |
@@ -38,17 +38,47 @@ 'use strict'; | ||
module: function(test) { | ||
moduleString: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/options_module.js'); | ||
var expected = grunt.file.read('test/expected/options_module.js'); | ||
var actual = grunt.file.read('tmp/module_option_string.js'); | ||
var expected = grunt.file.read('test/expected/module_option_string.js'); | ||
test.equal(expected, actual, 'should set the angular module to the provided options value'); | ||
test.equal(expected, actual, 'set angular module name to the one provided'); | ||
test.done(); | ||
}, | ||
moduleObject: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/module_option_object.js'); | ||
var expected = grunt.file.read('test/expected/module_option_object.js'); | ||
test.equal(expected, actual, ' define new angular module with provided name'); | ||
test.done(); | ||
}, | ||
moduleObjectName: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/module_option_object_name.js'); | ||
var expected = grunt.file.read('test/expected/module_option_string.js'); | ||
test.equal(expected, actual, ' set angular module name to the one provided'); | ||
test.done(); | ||
}, | ||
moduleObjectDefine: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/module_option_object_define.js'); | ||
var expected = grunt.file.read('test/expected/module_option_object_define.js'); | ||
test.equal(expected, actual, ' define new angular module with grunt target name'); | ||
test.done(); | ||
}, | ||
noConflict: function(test) { | ||
test.expect(1); | ||
var actual = grunt.file.read('tmp/options_noConflict_fixture.js'); | ||
var expected = grunt.file.read('test/expected/options_noConflict.js'); | ||
var actual = grunt.file.read('tmp/noConflict_option_fixture.js'); | ||
var expected = grunt.file.read('test/expected/noConflict_option.js'); | ||
@@ -55,0 +85,0 @@ test.equal(expected, actual, 'should reference angular by the noConflict options value'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23400
21
376
259