fixed three bugs in templates: 1) if you're sending in null as a value it should now correctly replace that field as ''. 2) you don't need to put objects last in data anymore (stupid bug) 3) you can now send multiple objects to be parsed in templates properly; Also added deprecation message to server side templates

v1.18.x
psychobunny 12 years ago
parent 8e48990a48
commit 3fa0f7c8b5

@ -113,8 +113,8 @@ var templates = {};
for (var d in data) {
if (data.hasOwnProperty(d)) {
if (data[d] instanceof String || data[d] === null) {
continue;
if (data[d] === null) {
template = replace(namespace + d, '', template);
} else if (data[d].constructor == Array) {
namespace += d;
@ -127,9 +127,9 @@ var templates = {};
do {
result += parse(data[d][i], namespace + '.', block);
} while (i++ < numblocks);
namespace = namespace.replace(d, '');
template = setBlock(regex, result, template);
} else if (data[d] instanceof Object) {
namespace += d + '.';
@ -142,7 +142,7 @@ var templates = {};
} else {
template = replace(namespace + d, data[d], template);
}
}
}
}
if (namespace) {

@ -17,6 +17,7 @@ var fs = require('fs');
};
}
template.prototype.file = file;
template.prototype.parse = parse;
template.prototype.html = String(html);
@ -65,6 +66,7 @@ var fs = require('fs');
var template = this.html, regex, block;
return (function parse(data, namespace, template) {
console.log(this.file + ' is being called on server side. Templates will be deprecated soon');
if (Object.keys(data).length == 0) {
regex = makeRegex('[^]*');
template = template.replace(regex, '');

Loading…
Cancel
Save