importing latest templates.js @Schamper

v1.18.x
psychobunny 11 years ago
parent 1f7fd51b40
commit 678f0f436e

@ -1,4 +1,5 @@
"use strict"; 'use strict';
/*global require, module*/
(function(module) { (function(module) {
var templates = { var templates = {
@ -53,7 +54,7 @@
}; };
templates.getBlock = function(template, block) { templates.getBlock = function(template, block) {
return template.replace(new RegExp("[\\s\\S]*(<!--[\\s]*BEGIN " + block + "[\\s]*-->[\r\n]*[\\s\\S]*?[\r\n]*<!--[\\s]*END " + block + "[\\s]*-->)[\\s\\S]*", 'g'), '$1'); return template.replace(new RegExp('[\\s\\S]*(<!--[\\s]*BEGIN ' + block + '[\\s]*-->[\r\n]*[\\s\\S]*?[\r\n]*<!--[\\s]*END ' + block + '[\\s]*-->)[\\s\\S]*', 'g'), '$1');
}; };
function express(filename, options, fn) { function express(filename, options, fn) {
@ -76,15 +77,19 @@
} }
function makeRegex(block) { function makeRegex(block) {
return new RegExp("<!--[\\s]*BEGIN " + block + "[\\s]*-->[\\s\\S]*?<!--[\\s]*END " + block + "[\\s]*-->", 'g'); return new RegExp('<!--[\\s]*BEGIN ' + block + '[\\s]*-->[\\s\\S]*?<!--[\\s]*END ' + block + '[\\s]*-->');
}
function makeBlockRegex(block) {
return new RegExp('([\\n]?<!--[\\s]*BEGIN ' + block + '[\\s]*-->[\\n]?)|([\\n]?<!--[\\s]*END ' + block + '[\\s]*-->[\\n]?)', 'g');
} }
function makeConditionalRegex(block) { function makeConditionalRegex(block) {
return new RegExp("<!--[\\s]*IF " + block + "[\\s]*-->([\\s\\S]*?)<!--[\\s]*ENDIF " + block + "[\\s]*-->", 'g'); return new RegExp('<!--[\\s]*IF ' + block + '[\\s]*-->([\\s\\S]*?)<!--[\\s]*ENDIF ' + block + '[\\s]*-->', 'g');
} }
function makeStatementRegex(key) { function makeStatementRegex(key) {
return new RegExp("([\\s]*<!--[\\s]*IF " + key + "[\\s]*-->)|(<!--[\\s]*ENDIF " + key + "[\\s]*-->[\\s]*)", 'gi'); return new RegExp('([\\s]*<!--[\\s]*IF ' + key + '[\\s]*-->)|(<!--[\\s]*ENDIF ' + key + '[\\s]*-->[\\s]*)', 'gi');
} }
function registerGlobals(obj) { function registerGlobals(obj) {
@ -168,18 +173,18 @@
template = checkConditional(template, namespace + 'length', array[key].length); template = checkConditional(template, namespace + 'length', array[key].length);
template = checkConditional(template, '!' + namespace + 'length', !array[key].length); template = checkConditional(template, '!' + namespace + 'length', !array[key].length);
var regex = makeRegex(key), var regex = makeRegex(key), block;
block = namespace.substring(0, namespace.length - 1).split('.').pop();
block = template.replace(new RegExp("[\\s\\S]*<!--[\\s]*BEGIN " + block + "[\\s]*-->[\r\n]*([\\s\\S]*?)[\r\n]*<!--[\\s]*END " + block + "[\\s]*-->[\\s\\S]*", 'g'), '$1'); if (!array[key].length) {
if (typeof block === "undefined" || !array[key].length) {
return template; return template;
} }
while (block = template.match(regex)) {
block = block[0].replace(makeBlockRegex(key), '');
var numblocks = array[key].length - 1, var numblocks = array[key].length - 1,
iterator = 0, iterator = 0,
result = "", result = '',
parsedBlock; parsedBlock;
do { do {
@ -202,7 +207,10 @@
} }
} while (iterator++ < numblocks); } while (iterator++ < numblocks);
return template.replace(regex, result); template = template.replace(regex, result);
}
return template;
} }
function setBindContainer(block, namespace) { function setBindContainer(block, namespace) {
@ -265,7 +273,6 @@
namespace = namespace || ''; namespace = namespace || '';
originalObj = originalObj || obj; originalObj = originalObj || obj;
template = checkConditionalHelper(template, obj); template = checkConditionalHelper(template, obj);
for (var key in obj) { for (var key in obj) {
@ -296,7 +303,7 @@
} }
if (namespace) { if (namespace) {
template = template.replace(new RegExp("{" + namespace + "\\.[\\s\\S]*?}", 'g'), ''); template = template.replace(new RegExp('{' + namespace + '\\.[\\s\\S]*?}', 'g'), '');
namespace = ''; namespace = '';
} else { } else {
// clean up all undefined conditionals // clean up all undefined conditionals

Loading…
Cancel
Save