Some more refactoring of template function.

master
Artem Sapegin 2012-11-21 00:29:32 +04:00
parent 8b0b320103
commit f2a3c7aebd
1 changed files with 4 additions and 4 deletions

View File

@ -511,10 +511,10 @@ function makeUrl(url, context) {
}
function template(tmpl, context, filter) {
for (var key in context) if (context.hasOwnProperty(key)) {
tmpl = tmpl.replace(new RegExp('{' + key + '}', 'g'), filter ? filter(context[key]) : context[key]);
}
return tmpl;
return tmpl.replace(/\{([^\}]+)\}/g, function(m, key) {
// If key don't exists in the context we should keep template tag as is
return key in context ? (filter ? filter(context[key]) : context[key]) : m;
});
}
function getElementClassNames(elem, mod) {