Skip to content

Commit 52e55ad

Browse files
authored
test to compare final results
added back in the old method and evaluate the template string using both approaches, log out to console any different results found
1 parent e96981a commit 52e55ad

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/extensions.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,37 @@ if (!String.prototype.resolve)
9898
}
9999
return _templateCache[template];
100100
};
101+
102+
// ONLY FOR TESTING
103+
String.prototype.resolve_old = function (substitutes, prefixes)
104+
{
105+
var result = this;
106+
107+
$.each(substitutes, function (key, value)
108+
{
109+
if (value != null && typeof value !== "function")
110+
{
111+
if (typeof value === "object")
112+
{
113+
var keys = (prefixes) ? $.extend([], prefixes) : [];
114+
keys.push(key);
115+
result = result.resolve_old(value, keys) + "";
116+
}
117+
else
118+
{
119+
if (formatter && formatter[key] && typeof formatter[key] === "function")
120+
{
121+
value = formatter[key](value);
122+
}
123+
key = (prefixes) ? prefixes.join(".") + "." + key : key;
124+
var pattern = new RegExp("\\{\\{" + key + "\\}\\}", "gm");
125+
result = result.replace(pattern, (value.replace) ? value.replace(/\$/gi, "$") : value);
126+
}
127+
}
128+
});
129+
130+
return result;
131+
};
101132

102133
String.prototype.resolve = function (substitutes, prefixes)
103134
{
@@ -135,6 +166,13 @@ if (!String.prototype.resolve)
135166
result += str[i]; // plain old html
136167
}
137168
}
169+
// ONLY FOR TESTING, remove for release or testing performance of individal approaches
170+
var result_old = this.resolve_old(substitutes, prefixes);
171+
if (result !== result_old){
172+
console.warn("Different templating result");
173+
console.log("new: ", result);
174+
console.log("old: ", result_old);
175+
}
138176
return result;
139177
};
140178
}

0 commit comments

Comments
 (0)