Skip to content

Commit

Permalink
added conditional section syntax: {{? expr }} to open and {{?}} to close
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Côté-Roy committed Oct 20, 2011
1 parent 53e9572 commit c87a272
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doT.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g, //compile time evaluation
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g, //compile time defs
conditionalStart: /\{\{\?([\s\S]+?)\}\}/g,
conditionalEnd: /\{\{\?\}\}/g,
varname: 'it',
strip : true,
append: true
Expand Down Expand Up @@ -66,6 +68,13 @@
.replace(c.encode, function(match, code) {
return cstart + code.replace(/\\'/g, "'").replace(/\\\\/g, "\\").replace(/[\r\t\n]/g, ' ') + ").toString().replace(/&(?!\\w+;)/g, '&#38;').split('<').join('&#60;').split('>').join('&#62;').split('" + '"' + "').join('&#34;').split(" + '"' + "'" + '"' + ").join('&#39;').split('/').join('&#47;'" + cend;
})
.replace(c.conditionalEnd, function(match, expression) {
return "'; } out += '";
})
.replace(c.conditionalStart, function(match, expression) {
var code = "; if (" + expression + ") {\n";
return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='";
})
.replace(c.evaluate, function(match, code) {
return "';" + code.replace(/\\'/g, "'").replace(/\\\\/g,"\\").replace(/[\r\t\n]/g, ' ') + "out+='";
})
Expand Down

0 comments on commit c87a272

Please sign in to comment.