diff --git a/public/src/templates.js b/public/src/templates.js index 1441c5a059..30ab7380cf 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -165,7 +165,7 @@ do { parsedBlock = parse(block, array[key][iterator], bind, namespace, {iterator: iterator, total: numblocks}) + ((iterator < numblocks) ? '\r\n':''); - result += (!bind) ? parsedBlock : '' + parsedBlock + ''; + result += (!bind) ? parsedBlock : setBindContainer(parsedBlock, bind + namespace + iterator); result = parseFunctions(block, result, { data: array[key][iterator], iterator: iterator, @@ -180,6 +180,10 @@ return template.replace(regex, result); } + function setBindContainer(block, namespace) { + return namespace ? '' + block + '' : block; + } + function parseValue(template, key, value, blockInfo) { value = typeof value === 'string' ? value.replace(/^\s+|\s+$/g, '') : value; @@ -199,14 +203,11 @@ function setupBindings(parameters) { var obj = parameters.obj, key = parameters.key, - namespace = parameters.namespace, - blockInfo = parameters.blockInfo, bind = parameters.bind, - template = parameters.template, value = obj[key]; - obj.__namespace = namespace; - obj.__iterator = blockInfo ? blockInfo.iterator : false; + obj.__namespace = parameters.namespace; + obj.__iterator = parameters.blockInfo ? parameters.blockInfo.iterator : false; Object.defineProperty(obj, key, { get: function() { @@ -243,10 +244,6 @@ } function parse(template, obj, bind, namespace, blockInfo) { - if (!obj || obj.length === 0) { - template = ''; - } - namespace = namespace || ''; originalObj = originalObj || obj; @@ -270,8 +267,7 @@ key: key, namespace: namespace, blockInfo: blockInfo, - bind: bind, - template: template + bind: bind }); } } @@ -283,13 +279,11 @@ namespace = ''; } else { // clean up all undefined conditionals - template = template.replace(/\s*\s*/gi, 'ENDIF -->\r\n') + template = setBindContainer(template.replace(/\s*\s*/gi, 'ENDIF -->\r\n') .replace(/\s*/gi, '') - .replace(/\s*\s*/gi, ''); + .replace(/\s*\s*/gi, ''), bind); - if (bind) { - template = '' + template + ''; - } + template = setBindContainer(template, bind); } return template;