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

This commit is contained in:
psychobunny
2013-05-14 17:36:12 +00:00
parent 8e48990a48
commit 3fa0f7c8b5
2 changed files with 7 additions and 5 deletions

View File

@@ -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;
@@ -128,8 +128,8 @@ var templates = {};
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 + '.';

View File

@@ -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, '');