Comparing version 0.1.5 to 0.1.6
33
doT.js
@@ -13,3 +13,3 @@ // doT.js | ||
(function() { | ||
var doT = { version : '0.1.5' }; | ||
var doT = { version : '0.1.6' }; | ||
@@ -27,3 +27,3 @@ if (typeof module !== 'undefined' && module.exports) { | ||
use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation | ||
define: /\{\{#\s*([\w$]+)\s*\:([\s\S]+?)#\}\}/g, //compile time defs | ||
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, //compile time defs | ||
varname: 'it', | ||
@@ -34,19 +34,28 @@ strip : true, | ||
function resolveDefs(define, use, str, defs) { | ||
return str.replace(define, function (match, code, value) { | ||
if (!(code in defs)) defs[code]=value; | ||
function resolveDefs(c, block, def) { | ||
return ((typeof block === 'string') ? block : block.toString()) | ||
.replace(c.define, function (match, code, assign, value) { | ||
if (code.indexOf('def.') === 0) { | ||
code = code.substring(4); | ||
} | ||
if (!(code in def)) { | ||
if (assign === ':') { | ||
def[code]= value; | ||
} else { | ||
eval("def[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; | ||
.replace(c.use, function(match, code) { | ||
var v = eval(code); | ||
return v ? resolveDefs(c, v, def) : v; | ||
}); | ||
} | ||
doT.template = function(tmpl, c, defs) { | ||
doT.template = function(tmpl, c, def) { | ||
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; | ||
var str = (c.use || c.define) ? resolveDefs(c, tmpl, def || {}) : tmpl; | ||
@@ -61,3 +70,3 @@ str = ("var out='" + | ||
.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; | ||
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; | ||
}) | ||
@@ -64,0 +73,0 @@ .replace(c.evaluate, function(match, code) { |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"main": "doT", | ||
@@ -13,0 +13,0 @@ "homepage": "http://github.com/olado/doT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6879
102