diff --git a/.gitignore b/.gitignore index bd07880..b785247 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/node_modules -/npm-debug.log -/tmp +node_modules +npm-debug.log +tmp diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..6b4c1a9 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,14 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "sub": true, + "undef": true, + "boss": true, + "eqnull": true, + "node": true, + "es5": true +} diff --git a/README.md b/README.md index b5658c4..6717f67 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,13 @@ grunt.loadNpmTasks('grunt-angular-templates'); This plugin provides the grunt task `ngtemplates`, which will allow you to compile your HTML templates into a single JS file, which preloads `$templateCache` to prevent round-trips to the server. -### Update Grunt: +### Update Grunt ```js // grunt.js grunt.initConfig({ ngtemplates: { - app: { + myapp: { options: { base: 'src/views' }, src: [ 'src/views/**.html' ], dest: 'dist/templates.js' @@ -41,19 +41,46 @@ grunt.initConfig({ }); ``` -### Add template module to your app +**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 -// js/app.js -angular.module('app', [ - 'app.templates' // Generated by ngtemplates:app +angular.module('myapp').run(['$templateCache', function($templateCache) { ... -]); +}]); +``` + +### Include Compiled Templates + +This can either be done via HTML: + +```html + +``` + +or via your Gruntfile: + +```js +concat: { + myapp: { + src: [ + 'src/js/**/*.js', // MyApp module first + '<%= ngtemplates.myapp.dest %>' // Generated templates + ], + dest: 'dist/js/app.js' + } +} ``` ## Changelog +### v0.3.0 + +- **BC break** - Templates are added to an existing module (e.g. `myapp`) rather than being their own `myapp.templates` module to be manually included, thanks to @geddesign. ([#10](https://github.com/ericclemmons/grunt-angular-templates/issues/10)) + ### v0.2.2 - Fixes diff --git a/package.json b/package.json index ca925d4..357251d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-angular-templates", "description": "Grunt build task to concatenate & register your AngularJS templates in the $templateCache", - "version": "0.2.2", + "version": "0.3.0", "homepage": "https://github.com/ericclemmons/grunt-angular-templates", "author": { "name": "Eric Clemmons", @@ -22,16 +22,15 @@ ], "main": "Gruntfile.js", "engines": { - "node": "0.8.x", - "npm": "1.1.x" + "node": ">= 0.8.0" }, "scripts": { "test": "./node_modules/.bin/grunt" }, "devDependencies": { - "grunt": "0.4.0rc7", - "grunt-contrib-jshint": "~0.1.0", - "grunt-contrib-nodeunit": "~0.1.1", + "grunt": "~0.4.0", + "grunt-contrib-jshint": "~0.1.1", + "grunt-contrib-nodeunit": "~0.1.2", "grunt-cli": "~0.1.6" }, "keywords": [ diff --git a/tasks/angular-templates.js b/tasks/angular-templates.js index 301832d..7d2b3a8 100644 --- a/tasks/angular-templates.js +++ b/tasks/angular-templates.js @@ -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 + '.templates'; + var id = this.target; var base = grunt.file.expand(this.options().base || '.')[0]; var files = grunt.file.expand(this.files[0].src); var dest = path.normalize(this.files[0].dest); diff --git a/tasks/lib/compiler.js b/tasks/lib/compiler.js index 6c8f4ff..9e8aaf6 100644 --- a/tasks/lib/compiler.js +++ b/tasks/lib/compiler.js @@ -30,7 +30,7 @@ module.exports.init = function(grunt) { }; var compile = function(id, base, files, callback) { - var template = 'angular.module("<%= id %>", []).run(["$templateCache", function($templateCache) {\n<%= content %>\n}]);\n'; + var template = 'angular.module("<%= id %>").run(["$templateCache", function($templateCache) {\n<%= content %>\n}]);\n'; concat(base, files, function(err, concated) { var options = { diff --git a/test/expected/multiple.js b/test/expected/multiple.js index 699b9c3..6a7aff2 100644 --- a/test/expected/multiple.js +++ b/test/expected/multiple.js @@ -1,4 +1,4 @@ -angular.module("multiple.templates", []).run(["$templateCache", function($templateCache) { +angular.module("multiple").run(["$templateCache", function($templateCache) { $templateCache.put("multiple/one.html", "