more cleanup

v1.18.x
psychobunny 11 years ago
parent e4f136c208
commit dbb75f181d

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

Loading…
Cancel
Save