Skip to content

Commit

Permalink
accepting conditional change
Browse files Browse the repository at this point in the history
  • Loading branch information
olado committed Dec 28, 2011
1 parent d8bc7f0 commit 7f35418
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions doT.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@
});
}

function ifdef(x) {
if (typeof x !== 'undefined' && x !== null)
return x;
else
return '';
}

doT.template = function(tmpl, c, def) {
c = c || doT.templateSettings;
var cstart = c.append ? "'+(" : "';out+=(", // optimal choice depends on platform/size of templates
Expand All @@ -69,8 +62,7 @@
((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, expression) {
var code = 'ifdef(' + expression + ')';
.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) {
Expand All @@ -80,7 +72,7 @@
return "'; } out += '";
})
.replace(c.conditionalStart, function(match, expression) {
var code = "; if (" + expression + ") {\n";
var code = "; if (" + expression + ") {\n";
return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='";
})
.replace(c.evaluate, function(match, code) {
Expand All @@ -93,11 +85,6 @@
.split("out+='';").join('')
.split("var out='';out+=").join('var out=');

if (!doT._ifdef)
doT._ifdef = ifdef.toString() + '; ';

str = doT._ifdef + str;

try {
return new Function(c.varname, str);
} catch (e) {
Expand Down

0 comments on commit 7f35418

Please sign in to comment.