Comparing version 0.1.4 to 0.1.5
60
doT.js
@@ -13,3 +13,3 @@ // doT.js | ||
(function() { | ||
var doT = { version : '0.1.4' }; | ||
var doT = { version : '0.1.5' }; | ||
@@ -29,3 +29,4 @@ if (typeof module !== 'undefined' && module.exports) { | ||
varname: 'it', | ||
strip : true | ||
strip : true, | ||
append: true | ||
}; | ||
@@ -35,10 +36,10 @@ | ||
return str.replace(define, function (match, code, value) { | ||
if (!(code in defs)) defs[code]=value; | ||
return ''; | ||
}) | ||
.replace(use, function(match, code) { | ||
var value;// todo: detect circular use and convert into compiled functions | ||
with(defs) {try { value = eval(code);} catch(e) { value='';} } | ||
return value ? resolveDefs(define, use, value.toString(), defs) : value; | ||
}); | ||
if (!(code in defs)) defs[code]=value; | ||
return ''; | ||
}) | ||
.replace(use, function(match, code) { | ||
var value; // todo: detect circular use and convert into compiled functions | ||
with(defs) {try { value = eval(code);} catch(e) { value='';} } | ||
return value ? resolveDefs(define, use, value.toString(), defs) : value; | ||
}); | ||
} | ||
@@ -48,22 +49,25 @@ | ||
c = c || doT.templateSettings; | ||
var cstart = c.append ? "'+(" : "';out+=(", // optimal choice depends on platform/size of templates | ||
cend = c.append ? ")+'" : ");out+='"; | ||
var str = (c.use || c.define) ? resolveDefs(c.define, c.use, tmpl, defs || {}) : tmpl; | ||
str = ("var out='" + | ||
((c.strip) ? str.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*|[\r\n\t]|(\/\*[\s\S]*?\*\/)/g, ''): str) | ||
.replace(/\\/g, '\\\\') | ||
.replace(/'/g, "\\'") | ||
.replace(c.interpolate, function(match, code) { | ||
return "';out+=" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + ";out+='"; | ||
}) | ||
.replace(c.encode, function(match, code) { | ||
return "';out+=(" + code.replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/[\r\t\n]/g, ' ') + ").toString().replace(/&(?!\\w+;)/g, '&').split('<').join('<').split('>').join('>').split('" + '"' + "').join('"').split(" + '"' + "'" + '"' + ").join(''').split('/').join('/');out+='"; | ||
}) | ||
.replace(c.evaluate, function(match, code) { | ||
return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='"; | ||
}) | ||
+ "';return out;") | ||
.replace(/\n/g, '\\n') | ||
.replace(/\t/g, '\\t') | ||
.replace(/\r/g, '\\r') | ||
.split("out+='';").join('') | ||
.split('var out="";out+=').join('var out='); | ||
((c.strip) ? str.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*|[\r\n\t]|(\/\*[\s\S]*?\*\/)/g, ''): str) | ||
.replace(/\\/g, '\\\\') | ||
.replace(/'/g, "\\'") | ||
.replace(c.interpolate, function(match, code) { | ||
return cstart + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + cend; | ||
}) | ||
.replace(c.encode, function(match, code) { | ||
return cstart + code.replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/[\r\t\n]/g, ' ') + ").toString().replace(/&(?!\\w+;)/g, '&').split('<').join('<').split('>').join('>').split('" + '"' + "').join('"').split(" + '"' + "'" + '"' + ").join(''').split('/').join('/'" + cend; | ||
}) | ||
.replace(c.evaluate, function(match, code) { | ||
return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='"; | ||
}) | ||
+ "';return out;") | ||
.replace(/\n/g, '\\n') | ||
.replace(/\t/g, '\\t') | ||
.replace(/\r/g, '\\r') | ||
.split("out+='';").join('') | ||
.split("var out='';out+=").join('var out='); | ||
@@ -70,0 +74,0 @@ try { |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"main": "doT", | ||
@@ -13,0 +13,0 @@ "homepage": "http://github.com/olado/doT", |
6824
93