Comparing version 0.1.3 to 0.1.4
37
doT.js
@@ -5,5 +5,6 @@ // doT.js | ||
// | ||
// doT is a blend of templating functions from jQote2.js | ||
// doT is a custom blend of templating functions from jQote2.js | ||
// (jQuery plugin) by aefxx (http://aefxx.com/jquery-plugins/jqote2/) | ||
// and underscore.js (http://documentcloud.github.com/underscore/) | ||
// plus extensions. | ||
// | ||
@@ -13,3 +14,3 @@ // Licensed under the MIT license. | ||
(function() { | ||
var doT = { version : '0.1.3' }; | ||
var doT = { version : '0.1.4' }; | ||
@@ -23,18 +24,28 @@ if (typeof module !== 'undefined' && module.exports) { | ||
doT.templateSettings = { | ||
evaluate : /\{\{([\s\S]+?)\}\}/g, | ||
interpolate : /\{\{=([\s\S]+?)\}\}/g, | ||
encode : /\{\{!([\s\S]+?)\}\}/g, | ||
defines: /\{\{#([\s\S]+?)\}\}/g, | ||
varname : 'it', | ||
evaluate: /\{\{([\s\S]+?)\}\}/g, | ||
interpolate: /\{\{=([\s\S]+?)\}\}/g, | ||
encode: /\{\{!([\s\S]+?)\}\}/g, | ||
use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation | ||
define: /\{\{#\s*([\w$]+)\s*\:([\s\S]+?)#\}\}/g, //compile time defs | ||
varname: 'it', | ||
strip : true | ||
}; | ||
function resolveDefs(define, use, str, defs) { | ||
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; | ||
}); | ||
} | ||
doT.template = function(tmpl, c, defs) { | ||
c = c || doT.templateSettings; | ||
var str = ("var out='" + | ||
((c.strip) ? tmpl.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*|[\r\n\t]|(\/\*[\s\S]*?\*\/)/g, ''): | ||
tmpl) | ||
.replace(c.defines, function(match, code) { | ||
return eval(code.replace(/[\r\t\n]/g, ' ')); | ||
}) | ||
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, '\\\\') | ||
@@ -41,0 +52,0 @@ .replace(/'/g, "\\'") |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "doT", | ||
@@ -13,0 +13,0 @@ "homepage": "http://github.com/olado/doT", |
Sorry, the diff of this file is not supported yet
6697
90
38