include("lib.prototype"); include("lib.underscore"); var Templates = { PRECOMPILED: $H(), load: function(name, callback) { new Ajax.Request("templates/" + name + ".template.html", { asynchronous: false, onSuccess: function(response) { Templates.PRECOMPILED[name] = _.template(response.responseText); callback && callback.defer(); }, onException: function(response, e) { console.log(response); console.log(e); } }); return function() { if (!Templates.PRECOMPILED[name]) { console.error("Template not loaded yet!"); return ""; } return Templates.PRECOMPILED[name].apply(Templates.PRECOMPILED[name], arguments); } }, toDOM: function(string) { var div = new Element('div'); div.update(string); return div.firstChild; } };