/*! ICanHandlebarz.js version 0.1 -- by @ehntoo, based on ICanHaz.js by @HenrikJoreteg More info at: http://github.com/ehntoo/ICanHandlebarz.js */ (function ($) { /*! ICanHandlebarz.js -- by @ehntoo, based on ICanHaz.js by @HenrikJoreteg */ /*global jQuery */ function ICanHandlebarz() { var self = this; self.VERSION = "0.1"; self.templates = {}; // public function for adding templates // We're enforcing uniqueness to avoid accidental template overwrites. // If you want a different template, it should have a different name. self.addTemplate = function (name, templateString) { if (self[name]) throw "Invalid name: " + name + "."; if (self.templates[name]) throw "Template \" + name + \" exists"; self.templates[name] = Handlebars.compile(templateString); self[name] = function (data, title, raw) { data = data || {}; var result = self.templates[name](data); return raw? result: $(result); }; }; // public function for adding partials self.addPartial = function (name, templateString) { if (Handlebars.partials[name]) throw "Partial \" + name + \" exists"; Handlebars.registerPartial(name, templateString); }; self.addHelper = function (name, func, args) { if (Handlebars.helpers[name]) throw "Helper \" + name + \" exists"; if (typeof func === 'function') { Handlebars.registerHelper(name, func); } else { Handlebars.registerHelper(name, new Function(args, func)); } } // grabs templates from the DOM and caches them. // Loop through and add templates. // Whitespace at beginning and end of all templates inside