Use getNamespaceDeclaration to declare namespace and JSON.stringify to escape template names
This commit is contained in:
parent
2d5a2f20b7
commit
421d3a5b89
11
tasks/jst.js
11
tasks/jst.js
@ -11,8 +11,7 @@ module.exports = function(grunt) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("underscore");
|
var _ = require("underscore");
|
||||||
|
var helpers = require('grunt-contrib-lib').init(grunt);
|
||||||
var escapeQuote = function(name) { return name.replace("'","\\'"); };
|
|
||||||
|
|
||||||
// filename conversion for templates
|
// filename conversion for templates
|
||||||
var defaultProcessName = function(name) { return name; };
|
var defaultProcessName = function(name) { return name; };
|
||||||
@ -32,7 +31,7 @@ module.exports = function(grunt) {
|
|||||||
|
|
||||||
var compiled, srcFiles, src, filename;
|
var compiled, srcFiles, src, filename;
|
||||||
var output = [];
|
var output = [];
|
||||||
var namespace = "this['" + options.namespace + "']";
|
var nsInfo = helpers.getNamespaceDeclaration(options.namespace);
|
||||||
|
|
||||||
this.files.forEach(function(files) {
|
this.files.forEach(function(files) {
|
||||||
srcFiles = grunt.file.expandFiles(files.src);
|
srcFiles = grunt.file.expandFiles(files.src);
|
||||||
@ -46,12 +45,12 @@ module.exports = function(grunt) {
|
|||||||
grunt.fail.warn("JST failed to compile.");
|
grunt.fail.warn("JST failed to compile.");
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = escapeQuote(processName(file));
|
filename = processName(file);
|
||||||
output.push(namespace+"['"+filename+"'] = "+compiled+";");
|
output.push(nsInfo.namespace+"["+JSON.stringify(filename)+"] = "+compiled+";");
|
||||||
});
|
});
|
||||||
|
|
||||||
if(output.length > 0) {
|
if(output.length > 0) {
|
||||||
output.unshift(namespace + " = " + namespace + " || {};");
|
output.unshift(nsInfo.declaration);
|
||||||
grunt.file.write(files.dest, output.join("\n\n"));
|
grunt.file.write(files.dest, output.join("\n\n"));
|
||||||
grunt.log.writeln("File '" + files.dest + "' created.");
|
grunt.log.writeln("File '" + files.dest + "' created.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user