Permalink
Browse files

streamlined conditionals

  • Loading branch information...
1 parent e1a7b64 commit b47026710f88d3b043b4c3178aa4560968641350 @olado committed Apr 23, 2012
Showing with 15 additions and 23 deletions.
  1. +5 −9 benchmarks/templating/doT.js
  2. +5 −9 doT.js
  3. +5 −5 doT.min.js
@@ -25,9 +25,7 @@
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g,
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
- conditionalStart: /\{\{\?([\s\S]+?)\}\}/g,
- conditionalElse: /\{\{\?\?\s*([\s\S]*?)\s*\}\}/g,
- conditionalEnd: /\{\{\?\}\}/g,
+ conditional: /\{\{\?(\?)?\s*([\s\S]*?)\}\}/g,
varname: 'it',
strip : true,
append: true,
@@ -93,12 +91,10 @@
needhtmlencode = true;
return cse.startencode + unescape(code) + cse.end;
})
- .replace(c.conditionalEnd, "';}out+='")
- .replace(c.conditionalElse, function(m, code) {
- return (code) ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='";
- })
- .replace(c.conditionalStart, function(m, code) {
- return "';if(" + unescape(code) + "){out+='";
+ .replace(c.conditional, function(m, elsecase, code) {
+ return elsecase ?
+ (code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
+ (code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
})
.replace(c.evaluate, function(m, code) {
return "';" + unescape(code) + "out+='";
View
14 doT.js
@@ -25,9 +25,7 @@
encode: /\{\{!([\s\S]+?)\}\}/g,
use: /\{\{#([\s\S]+?)\}\}/g,
define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
- conditionalStart: /\{\{\?([\s\S]+?)\}\}/g,
- conditionalElse: /\{\{\?\?\s*([\s\S]*?)\s*\}\}/g,
- conditionalEnd: /\{\{\?\}\}/g,
+ conditional: /\{\{\?(\?)?\s*([\s\S]*?)\}\}/g,
varname: 'it',
strip : true,
append: true,
@@ -93,12 +91,10 @@
needhtmlencode = true;
return cse.startencode + unescape(code) + cse.end;
})
- .replace(c.conditionalEnd, "';}out+='")
- .replace(c.conditionalElse, function(m, code) {
- return (code) ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='";
- })
- .replace(c.conditionalStart, function(m, code) {
- return "';if(" + unescape(code) + "){out+='";
+ .replace(c.conditional, function(m, elsecase, code) {
+ return elsecase ?
+ (code ? "';}else if(" + unescape(code) + "){out+='" : "';}else{out+='") :
+ (code ? "';if(" + unescape(code) + "){out+='" : "';}out+='");
})
.replace(c.evaluate, function(m, code) {
return "';" + unescape(code) + "out+='";
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit b470267

Please sign in to comment.