Skip to content

Commit b09d4b5

Browse files
committed
feat: use jsesc instead of js-string-escape (breaking)
1 parent b748ca3 commit b09d4b5

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: node_js
22
node_js:
3-
- '0.10'
3+
- '4.2'

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ var gutil = require('gulp-util');
44
var concat = require('gulp-concat');
55
var header = require('gulp-header');
66
var footer = require('gulp-footer');
7-
var htmlJsStr = require('js-string-escape');
7+
var jsesc = require('jsesc');
88

99
/**
1010
* "constants"
1111
*/
1212

13-
var TEMPLATE_HEADER = 'angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {';
14-
var TEMPLATE_BODY = '$templateCache.put("<%= url %>","<%= contents %>");';
13+
var TEMPLATE_HEADER = 'angular.module(\'<%= module %>\'<%= standalone %>).run([\'$templateCache\', function($templateCache) {';
14+
var TEMPLATE_BODY = '$templateCache.put(\'<%= url %>\',\'<%= contents %>\');';
1515
var TEMPLATE_FOOTER = '}]);';
1616

1717
var DEFAULT_FILENAME = 'templates.js';
@@ -86,7 +86,7 @@ function templateCacheFiles(root, base, templateBody, transformUrl) {
8686

8787
file.contents = new Buffer(gutil.template(template, {
8888
url: url,
89-
contents: htmlJsStr(file.contents.toString('utf8')),
89+
contents: jsesc(file.contents.toString('utf8')),
9090
file: file
9191
}));
9292

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"repository": "miickel/gulp-angular-templatecache",
1010
"engines": {
11-
"node": ">=0.8.0"
11+
"node": ">=4.2.0"
1212
},
1313
"files": [
1414
"index.js"
@@ -34,7 +34,7 @@
3434
"gulp-footer": "1.0.5",
3535
"gulp-header": "1.8.2",
3636
"gulp-util": "3.0.7",
37-
"js-string-escape": "~1.0.0"
37+
"jsesc": "2.2.0"
3838
},
3939
"devDependencies": {
4040
"mocha": "latest"

test/test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('gulp-angular-templatecache', function () {
1212
stream.on('data', function (file) {
1313
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
1414
assert.equal(file.relative, 'templates.js');
15-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");\n$templateCache.put("/template-b.html","<h1 id=\\"template-b\\">I\\\'m template B!</h1>");}]);');
15+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');\n$templateCache.put(\'/template-b.html\',\'<h1 id="template-b">I\\\'m template B!</h1>\');}]);');
1616
cb();
1717
});
1818

@@ -40,7 +40,7 @@ describe('gulp-angular-templatecache', function () {
4040
stream.on('data', function (file) {
4141
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
4242
assert.equal(file.relative, 'templates.js');
43-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/views/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
43+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/views/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
4444
cb();
4545
});
4646

@@ -64,7 +64,7 @@ describe('gulp-angular-templatecache', function () {
6464
stream.on('data', function (file) {
6565
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
6666
assert.equal(file.relative, 'templates.js');
67-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/views/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
67+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/views/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
6868
cb();
6969
});
7070

@@ -85,7 +85,7 @@ describe('gulp-angular-templatecache', function () {
8585
stream.on('data', function (file) {
8686
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
8787
assert.equal(file.relative, 'templates.js');
88-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("./template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
88+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'./template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
8989
cb();
9090
});
9191

@@ -106,7 +106,7 @@ describe('gulp-angular-templatecache', function () {
106106
stream.on('data', function (file) {
107107
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
108108
assert.equal(file.relative, 'templates.js');
109-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("./template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
109+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'./template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
110110
cb();
111111
});
112112

@@ -127,7 +127,7 @@ describe('gulp-angular-templatecache', function () {
127127
stream.on('data', function (file) {
128128
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
129129
assert.equal(file.relative, 'templates.js');
130-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put(".root/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
130+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'.root/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
131131
cb();
132132
});
133133

@@ -147,15 +147,15 @@ describe('gulp-angular-templatecache', function () {
147147

148148
it('should change the URL to the output of the function', function (cb) {
149149
var stream = templateCache('templates.js', {
150-
transformUrl: function (url) {
150+
transformUrl: function(url) {
151151
return url.replace(/template/, 'tpl');
152152
}
153153
});
154154

155155
stream.on('data', function (file) {
156156
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
157157
assert.equal(file.relative, 'templates.js');
158-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/tpl-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
158+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/tpl-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
159159
cb();
160160
});
161161

@@ -171,15 +171,15 @@ describe('gulp-angular-templatecache', function () {
171171
it('should set the final url, after any root option has been applied', function (cb) {
172172
var stream = templateCache('templates.js', {
173173
root: './views',
174-
transformUrl: function (url) {
174+
transformUrl: function(url) {
175175
return '/completely/transformed/final';
176176
}
177177
});
178178

179179
stream.on('data', function (file) {
180180
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
181181
assert.equal(file.relative, 'templates.js');
182-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/completely/transformed/final","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
182+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/completely/transformed/final\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
183183
cb();
184184
});
185185

@@ -205,7 +205,7 @@ describe('gulp-angular-templatecache', function () {
205205
stream.on('data', function (file) {
206206
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
207207
assert.equal(file.relative, 'templates.js');
208-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
208+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
209209
cb();
210210
});
211211

@@ -251,7 +251,7 @@ describe('gulp-angular-templatecache', function () {
251251
stream.on('data', function (file) {
252252
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/foobar.js'));
253253
assert.equal(file.relative, 'foobar.js');
254-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/views/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
254+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/views/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
255255
cb();
256256
});
257257

@@ -279,7 +279,7 @@ describe('gulp-angular-templatecache', function () {
279279
stream.on('data', function (file) {
280280
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
281281
assert.equal(file.relative, 'templates.js');
282-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/views/test/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
282+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/views/test/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
283283
cb();
284284
});
285285

@@ -304,7 +304,7 @@ describe('gulp-angular-templatecache', function () {
304304
stream.on('data', function (file) {
305305
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
306306
assert.equal(file.relative, 'templates.js');
307-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/templates/all/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
307+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/templates/all/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
308308
cb();
309309
});
310310

@@ -331,7 +331,7 @@ describe('gulp-angular-templatecache', function () {
331331
stream.on('data', function (file) {
332332
assert.equal(file.path, path.normalize(__dirname + '/templates.js'));
333333
assert.equal(file.relative, 'templates.js');
334-
assert.equal(file.contents.toString('utf8'), '\'use strict\'; module.exports = angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
334+
assert.equal(file.contents.toString('utf8'), '\'use strict\'; module.exports = angular.module(\'templates\', []).run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
335335
cb();
336336
});
337337

@@ -352,7 +352,7 @@ describe('gulp-angular-templatecache', function () {
352352
stream.on('data', function (file) {
353353
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
354354
assert.equal(file.relative, 'templates.js');
355-
assert.equal(file.contents.toString('utf8'), 'define([\'angular\'], function(angular) { \'use strict\'; return angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);});');
355+
assert.equal(file.contents.toString('utf8'), 'define([\'angular\'], function(angular) { \'use strict\'; return angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);});');
356356
cb();
357357
});
358358

@@ -373,7 +373,7 @@ describe('gulp-angular-templatecache', function () {
373373
stream.on('data', function (file) {
374374
assert.equal(path.normalize(file.path), path.normalize(__dirname + '/templates.js'));
375375
assert.equal(file.relative, 'templates.js');
376-
assert.equal(file.contents.toString('utf8'), 'import angular from \'angular\'; export default angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put("/template-a.html","<h1 id=\\"template-a\\">I\\\'m template A!</h1>");}]);');
376+
assert.equal(file.contents.toString('utf8'), 'import angular from \'angular\'; export default angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'<h1 id="template-a">I\\\'m template A!</h1>\');}]);');
377377
cb();
378378
});
379379

@@ -399,7 +399,7 @@ describe('gulp-angular-templatecache', function () {
399399
stream.on('data', function (file) {
400400
assert.equal(file.path, path.normalize(__dirname + '/templates.js'));
401401
assert.equal(file.relative, 'templates.js');
402-
assert.equal(file.contents.toString('utf8'), 'var template = "$templateCache.put("/template-a.html","yoo");";');
402+
assert.equal(file.contents.toString('utf8'), 'var template = "$templateCache.put(\'/template-a.html\',\'yoo\');";');
403403
cb();
404404
});
405405

@@ -424,7 +424,7 @@ describe('gulp-angular-templatecache', function () {
424424
stream.on('data', function (file) {
425425
assert.equal(file.path, path.normalize(__dirname + '/templates.js'));
426426
assert.equal(file.relative, 'templates.js');
427-
assert.equal(file.contents.toString('utf8'), 'angular.module("templates").run(["$templateCache", function($templateCache) {$templateCache.put(\'/template-a.html\',\'yoo\');}]);');
427+
assert.equal(file.contents.toString('utf8'), 'angular.module(\'templates\').run([\'$templateCache\', function($templateCache) {$templateCache.put(\'/template-a.html\',\'yoo\');}]);');
428428
cb();
429429
});
430430

0 commit comments

Comments
 (0)