diff --git a/grunt.js b/grunt.js index 4131896..1584ac0 100644 --- a/grunt.js +++ b/grunt.js @@ -39,11 +39,18 @@ module.exports = function(grunt) { globals: {} }, ngtemplates: { + multiple: { + options: { + base: 'test/fixtures' + }, + src: ['test/fixtures/multiple/**/*.html'], + dest: 'tmp/multiple.js' + }, simple: { options: { base: 'test/fixtures' }, - src: ['test/fixtures/**/simple.html'], + src: ['test/fixtures/simple.html'], dest: 'tmp/simple.js' } } diff --git a/tasks/lib/compiler.js b/tasks/lib/compiler.js index ae97248..a3852d7 100644 --- a/tasks/lib/compiler.js +++ b/tasks/lib/compiler.js @@ -15,24 +15,24 @@ module.exports.init = function(grunt) { var concat = function(base, files, callback) { grunt.utils.async.concatSeries(files, function(file, next) { var id = path.relative(base, file); - var template = '\n $templateCache.put("<%= id %>", "<%= content %>"\n );\n'; + var template = '\n $templateCache.put("<%= id %>",\n "<%= content %>"\n );\n'; var cleaned = grunt.file.read(file).replace(/"/g, '\\"').replace(/\r?\n/g, '" +\n "'); var cached = grunt.template.process(template, { id: id, content: cleaned }); - next(cached); + next(null, cached); }, callback); }; var compile = function(id, base, files, callback) { var template = 'angular.module("<%= id %>", []).run(["$templateCache", function($templateCache) {\n<%= content %>\n}]);\n'; - concat(base, files, function(concated) { + concat(base, files, function(err, concated) { var compiled = grunt.template.process(template, { id: id, - content: concated + content: concated.join('') }); callback(false, compiled); diff --git a/test/angular-templates_test.js b/test/angular-templates_test.js index b3fb7bb..a8b5578 100644 --- a/test/angular-templates_test.js +++ b/test/angular-templates_test.js @@ -8,11 +8,21 @@ exports.ngtemplates = { simple: function(test) { test.expect(1); - var actual = grunt.file.read('tmp/simple.js'); + var actual = grunt.file.read('tmp/simple.js'); var expected = grunt.file.read('test/expected/simple.js'); test.equal(expected, actual, 'should compile template as module `simple.templates`'); test.done(); + }, + + multiple: function(test) { + test.expect(1); + + var actual = grunt.file.read('tmp/multiple.js'); + var expected = grunt.file.read('test/expected/multiple.js'); + + test.equal(expected, actual, 'should compile multiple templates together as `multiple.templates`'); + test.done(); } }; diff --git a/test/expected/multiple.js b/test/expected/multiple.js new file mode 100644 index 0000000..699b9c3 --- /dev/null +++ b/test/expected/multiple.js @@ -0,0 +1,17 @@ +angular.module("multiple.templates", []).run(["$templateCache", function($templateCache) { + + $templateCache.put("multiple/one.html", + "
I am one.
" + + "" + ); + + $templateCache.put("multiple/two/two.html", + "We are two.
" + + "" + ); + +}]); diff --git a/test/expected/simple.js b/test/expected/simple.js index bab4e2e..a46042a 100644 --- a/test/expected/simple.js +++ b/test/expected/simple.js @@ -1,6 +1,7 @@ angular.module("simple.templates", []).run(["$templateCache", function($templateCache) { - $templateCache.put("simple.html", "Howdy there! Your name is \"{{ name }}\"." + + $templateCache.put("simple.html", + "Howdy there! Your name is \"{{ name }}\"." + "" ); diff --git a/test/fixtures/multiple/one.html b/test/fixtures/multiple/one.html new file mode 100644 index 0000000..3095f94 --- /dev/null +++ b/test/fixtures/multiple/one.html @@ -0,0 +1,3 @@ +I am one.
diff --git a/test/fixtures/multiple/two/two.html b/test/fixtures/multiple/two/two.html new file mode 100644 index 0000000..1844c79 --- /dev/null +++ b/test/fixtures/multiple/two/two.html @@ -0,0 +1,3 @@ +We are two.