From 61478caa3d3169abf0022c6f431c2afeafb7fc49 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 8 Apr 2014 15:51:15 -0400 Subject: [PATCH] imported latest templates.js --- public/src/templates.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index eacef3aa3f..29c0d2787d 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -17,7 +17,6 @@ obj = registerGlobals(obj || {}); bind = bind ? Math.random() : false; - template = template.toString() || ''; if (bind) { obj.__template = template; @@ -76,7 +75,7 @@ } function makeRegex(block) { - return new RegExp("[\\s\\S]*?", 'g'); + return new RegExp("[\\s\\S]*", 'g'); } function makeConditionalRegex(block) { @@ -98,29 +97,34 @@ } function checkConditional(template, key, value) { - var conditional = makeConditionalRegex(key), - matches = template.match(conditional); + var matches = template.match(makeConditionalRegex(key)); if (matches !== null) { for (var i = 0, ii = matches.length; i < ii; i++) { - var conditionalBlock = matches[i].split(/\s*\s*/), - statement = makeStatementRegex(key); + var statement = makeStatementRegex(key), + nestedConditionals = matches[i].match(/\s\s/), + match = matches[i].replace(statement, '').replace(//, ''), + conditionalBlock = match.split(/\s*\s*/); if (conditionalBlock[1]) { // there is an else statement if (!value) { - template = template.replace(matches[i], conditionalBlock[1].replace(statement, '').replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); + template = template.replace(matches[i], conditionalBlock[1].replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); } else { - template = template.replace(matches[i], conditionalBlock[0].replace(statement, '').replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); + template = template.replace(matches[i], conditionalBlock[0].replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); } } else { // regular if statement if (!value) { template = template.replace(matches[i], ''); } else { - template = template.replace(matches[i], matches[i].replace(statement, '').replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); + template = template.replace(matches[i], match.replace(/(^[\r\n\t]*)|([\r\n\t]*$)/gi, '')); } } + + if (nestedConditionals) { + template = template.replace('', nestedConditionals[0]); + } } }