piskel/js/utils/Template.js
Julian Descottes ca427e0853 Dev environment : closure compiler + jshint update
Fixed error raised by closure compiler
Added es3 option to jshint (detect trailing commas)
Added curly option to jshint (missing curly braces for if/for blocks)
Removed trailing whitespaces (not enforced through jshint though)
2013-09-28 23:52:51 +02:00

30 lines
775 B
JavaScript

(function () {
var ns = $.namespace("pskl");
ns.utils.Template = {
get : function (templateId) {
var template = document.getElementById(templateId);
if (template) {
return template.innerHTML;
} else {
console.error("Could not find template for id :", templateId);
}
},
createFromHTML : function (html) {
var dummyEl = document.createElement("div");
dummyEl.innerHTML = html;
return dummyEl.children[0];
},
replace : function (template, dict) {
for (var key in dict) {
if (dict.hasOwnProperty(key)) {
var value = dict[key];
template = template.replace(new RegExp('\\{\\{'+key+'\\}\\}', 'g'), value);
}
}
return template;
}
};
})();