From ccd71d7ae67833e6d4b1f372d0b3c33c17d14ee7 Mon Sep 17 00:00:00 2001 From: Kai Groner Date: Tue, 7 May 2013 22:10:30 -0400 Subject: [PATCH] Preserve line endings in templates. --- tasks/lib/compiler.js | 4 ++-- test/expected/multiple.js | 26 ++++++++++++-------------- test/expected/options_module.js | 3 +-- test/expected/simple.js | 3 +-- test/expected/simple_prepend.js | 3 +-- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/tasks/lib/compiler.js b/tasks/lib/compiler.js index 619f40d..31bb97b 100644 --- a/tasks/lib/compiler.js +++ b/tasks/lib/compiler.js @@ -15,8 +15,8 @@ module.exports.init = function(grunt) { var concat = function(options, files, callback) { grunt.util.async.concatSeries(files, function(file, next) { var id = (options.prepend || '') + path.relative(options.base || '.', file).replace( /\\/g, '/'); - var template = '\n $templateCache.put("<%= id %>",\n "<%= content %>"\n );\n'; - var cleaned = grunt.file.read(file).replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\r?\n/g, '" +\n "'); + var template = '\n $templateCache.put("<%= id %>",\n <%= content %>\n );\n'; + var cleaned = grunt.file.read(file).split(/^/gm).map(function(line) { return JSON.stringify(line); }).join(' +\n '); var cached = process(template, id, cleaned); next(null, cached); diff --git a/test/expected/multiple.js b/test/expected/multiple.js index e665c43..6f1d8fe 100644 --- a/test/expected/multiple.js +++ b/test/expected/multiple.js @@ -1,23 +1,21 @@ angular.module("multiple").run(["$templateCache", function($templateCache) { $templateCache.put("multiple/one.html", - "

One

" + - "" + - "

I am one.

" + - "" + - "" + - "" + "

One

\n" + + "\n" + + "

I am one.

\n" + + "\n" + + "\n" ); $templateCache.put("multiple/two/two.html", - "

Two

" + - "" + - "

We are two.

" + - "" + "

Two

\n" + + "\n" + + "

We are two.

\n" ); }]); diff --git a/test/expected/options_module.js b/test/expected/options_module.js index 6659f41..78f6995 100644 --- a/test/expected/options_module.js +++ b/test/expected/options_module.js @@ -1,8 +1,7 @@ angular.module("ImAModuleNotATarget").run(["$templateCache", function($templateCache) { $templateCache.put("simple.html", - "Howdy there! \\ Your name is \"{{ name }}\"." + - "" + "Howdy there! \\ Your name is \"{{ name }}\".\n" ); }]); diff --git a/test/expected/simple.js b/test/expected/simple.js index 97997d7..6487862 100644 --- a/test/expected/simple.js +++ b/test/expected/simple.js @@ -1,8 +1,7 @@ angular.module("simple").run(["$templateCache", function($templateCache) { $templateCache.put("simple.html", - "Howdy there! \\ Your name is \"{{ name }}\"." + - "" + "Howdy there! \\ Your name is \"{{ name }}\".\n" ); }]); diff --git a/test/expected/simple_prepend.js b/test/expected/simple_prepend.js index 3e29ae7..a8e9858 100644 --- a/test/expected/simple_prepend.js +++ b/test/expected/simple_prepend.js @@ -1,8 +1,7 @@ angular.module("prepend").run(["$templateCache", function($templateCache) { $templateCache.put("/prepend/simple.html", - "Howdy there! \\ Your name is \"{{ name }}\"." + - "" + "Howdy there! \\ Your name is \"{{ name }}\".\n" ); }]);