From f2089b5f19d8e2fc864ba59406252aeb3840447d Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 5 Mar 2013 15:14:05 -0600 Subject: [PATCH 1/4] Update to Grunt 0.4.0 --- .gitignore | 6 +++--- .jshintrc | 14 ++++++++++++++ package.json | 9 ++++----- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .jshintrc 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/package.json b/package.json index ca925d4..8d55d76 100644 --- a/package.json +++ b/package.json @@ -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": [ From a0de04c1170eaa12ed2896fb3f5d022dfd06794b Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 5 Mar 2013 15:25:19 -0600 Subject: [PATCH 2/4] Compiled templates add to existing module rather than create new template-specific module --- tasks/angular-templates.js | 2 +- tasks/lib/compiler.js | 2 +- test/expected/multiple.js | 2 +- test/expected/simple.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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", "

One

" + diff --git a/test/expected/simple.js b/test/expected/simple.js index 92a0576..97997d7 100644 --- a/test/expected/simple.js +++ b/test/expected/simple.js @@ -1,4 +1,4 @@ -angular.module("simple.templates", []).run(["$templateCache", function($templateCache) { +angular.module("simple").run(["$templateCache", function($templateCache) { $templateCache.put("simple.html", "Howdy there! \\ Your name is \"{{ name }}\"." + From 06d0bbb5eaa68b59fa098db266746f1b35590c96 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 5 Mar 2013 15:26:55 -0600 Subject: [PATCH 3/4] Update README with new module examples --- README.md | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b5658c4..b851b76 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,14 +41,37 @@ 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' + } +} ``` From 140b4d18f1a0676f57a978099b23ce0036b85798 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Tue, 5 Mar 2013 15:28:51 -0600 Subject: [PATCH 4/4] Bump to v0.3.0 --- README.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b851b76..6717f67 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,10 @@ concat: { ## 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 8d55d76..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",