Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/files/file3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Example HTML Template</h1>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really show very well here, but this file has a UTF8 BOM.

1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 \'');
Expand Down
27 changes: 23 additions & 4 deletions test/html2js.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
});
});
Expand Down
6 changes: 6 additions & 0 deletions test/output/html-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular.module('template.js', [])
.run(['$templateCache', function($templateCache) {
$templateCache.put('file3.html',
'<h1>Example HTML Template</h1>');

}]);
6 changes: 6 additions & 0 deletions test/output/html-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular.module('template.js', [])
.run(['$templateCache', function($templateCache) {
$templateCache.put('file3.html',
'<h1>Example HTML Template</h1>');

}]);
4 changes: 2 additions & 2 deletions test/output/model.js → test/output/jade-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ angular.module('template.js', [])
'<div><h1>Hello World from file1!</h1></div>');
$templateCache.put('file2.tpl.jade',
'<div><h1>Hello World from file2!</h1></div>');
$templateCache.put('subfolder/subfile1.tpl.jade',
'<div><h1>Hello World from subfile1!</h1></div>');
$templateCache.put('subfolder/subfile2.tpl.jade',
'<div><h1>Hello World from subfile2!</h1></div>');
$templateCache.put('subfolder/subfile1.tpl.jade',
'<div><h1>Hello World from subfile1!</h1></div>');

}]);
4 changes: 2 additions & 2 deletions test/output/template.js → test/output/jade-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ angular.module('template.js', [])
'<div><h1>Hello World from file1!</h1></div>');
$templateCache.put('file2.tpl.jade',
'<div><h1>Hello World from file2!</h1></div>');
$templateCache.put('subfolder/subfile1.tpl.jade',
'<div><h1>Hello World from subfile1!</h1></div>');
$templateCache.put('subfolder/subfile2.tpl.jade',
'<div><h1>Hello World from subfile2!</h1></div>');
$templateCache.put('subfolder/subfile1.tpl.jade',
'<div><h1>Hello World from subfile1!</h1></div>');

}]);