From 91c1035ea60c575537d77840cc9fc9bb99b69c8c Mon Sep 17 00:00:00 2001 From: Floyd May Date: Tue, 27 Dec 2016 10:28:43 -0600 Subject: [PATCH] add logic to strip UTF8 BOM --- example/files/file3.html | 1 + src/index.js | 1 + test/html2js.spec.js | 27 ++++++++++++++++--- test/output/html-model.js | 6 +++++ test/output/html-template.js | 6 +++++ test/output/{model.js => jade-model.js} | 4 +-- test/output/{template.js => jade-template.js} | 4 +-- 7 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 example/files/file3.html create mode 100644 test/output/html-model.js create mode 100644 test/output/html-template.js rename test/output/{model.js => jade-model.js} (100%) rename test/output/{template.js => jade-template.js} (100%) diff --git a/example/files/file3.html b/example/files/file3.html new file mode 100644 index 0000000..1cbf913 --- /dev/null +++ b/example/files/file3.html @@ -0,0 +1 @@ +

Example HTML Template

diff --git a/src/index.js b/src/index.js index 34cc2f7..3dc925c 100644 --- a/src/index.js +++ b/src/index.js @@ -35,6 +35,7 @@ module.exports = function (opts, callback) { removeComments: true }); + html = html.replace(/^\ufeff/, ''); html = html.replace(/\\/g, '\\\\'); html = html.replace(/'/g, '\\\''); html = html.replace(/\r?\n/g, '\\n\' +\n \''); diff --git a/test/html2js.spec.js b/test/html2js.spec.js index 5670003..33535a6 100644 --- a/test/html2js.spec.js +++ b/test/html2js.spec.js @@ -6,10 +6,11 @@ var fs = require('fs'); var html2js = require('../src/index.js'); var path = require('path'); -var model = fs.readFileSync(path.join(__dirname, 'output/model.js')) +var jadeModel = fs.readFileSync(path.join(__dirname, 'output/jade-model.js')) +var htmlModel = fs.readFileSync(path.join(__dirname, 'output/html-model.js')) describe('html2js', function() { - it('should produce the expected js', function(done) { + it('should produce the expected js for jade templates', function(done) { var opts ={ isJade: true, extension: 'jade', @@ -19,11 +20,29 @@ describe('html2js', function() { basePath: 'example/files', minify: true, quotes: true, - output: path.join(__dirname, 'output/template.js') + output: path.join(__dirname, 'output/jade-template.js') } html2js(opts, function() { var output = fs.readFileSync(opts.output) - expect(output.toString() === model.toString()).to.be.true; + expect(output.toString()).to.equal(jadeModel.toString()); + done(); + }); + }); + + it('should produce the expected js for html templates', function(done) { + var opts ={ + extension: 'html', + tplPath: 'example/files/**/*.html', + moduleName: 'template.js', + filename: 'example/output/template.js', + basePath: 'example/files', + minify: true, + quotes: true, + output: path.join(__dirname, 'output/html-template.js') + } + html2js(opts, function() { + var output = fs.readFileSync(opts.output) + expect(output.toString()).to.equal(htmlModel.toString()); done(); }); }); diff --git a/test/output/html-model.js b/test/output/html-model.js new file mode 100644 index 0000000..5c295d3 --- /dev/null +++ b/test/output/html-model.js @@ -0,0 +1,6 @@ +angular.module('template.js', []) + .run(['$templateCache', function($templateCache) { + $templateCache.put('file3.html', + '

Example HTML Template

'); + + }]); diff --git a/test/output/html-template.js b/test/output/html-template.js new file mode 100644 index 0000000..5c295d3 --- /dev/null +++ b/test/output/html-template.js @@ -0,0 +1,6 @@ +angular.module('template.js', []) + .run(['$templateCache', function($templateCache) { + $templateCache.put('file3.html', + '

Example HTML Template

'); + + }]); diff --git a/test/output/model.js b/test/output/jade-model.js similarity index 100% rename from test/output/model.js rename to test/output/jade-model.js index 1af20ca..0c0687e 100644 --- a/test/output/model.js +++ b/test/output/jade-model.js @@ -4,9 +4,9 @@ angular.module('template.js', []) '

Hello World from file1!

'); $templateCache.put('file2.tpl.jade', '

Hello World from file2!

'); - $templateCache.put('subfolder/subfile1.tpl.jade', - '

Hello World from subfile1!

'); $templateCache.put('subfolder/subfile2.tpl.jade', '

Hello World from subfile2!

'); + $templateCache.put('subfolder/subfile1.tpl.jade', + '

Hello World from subfile1!

'); }]); diff --git a/test/output/template.js b/test/output/jade-template.js similarity index 100% rename from test/output/template.js rename to test/output/jade-template.js index 1af20ca..0c0687e 100644 --- a/test/output/template.js +++ b/test/output/jade-template.js @@ -4,9 +4,9 @@ angular.module('template.js', []) '

Hello World from file1!

'); $templateCache.put('file2.tpl.jade', '

Hello World from file2!

'); - $templateCache.put('subfolder/subfile1.tpl.jade', - '

Hello World from subfile1!

'); $templateCache.put('subfolder/subfile2.tpl.jade', '

Hello World from subfile2!

'); + $templateCache.put('subfolder/subfile1.tpl.jade', + '

Hello World from subfile1!

'); }]);