// lib/handlebars/base.js var Handlebars = {}; Handlebars.VERSION = "1.0.beta.5"; Handlebars.helpers = {}; Handlebars.partials = {}; Handlebars.registerHelper = function(name, fn, inverse) { if(inverse) { fn.not = inverse; } this.helpers[name] = fn; }; Handlebars.registerPartial = function(name, str) { this.partials[name] = str; }; Handlebars.registerHelper('helperMissing', function(arg) { if(arguments.length === 2) { return undefined; } else { throw new Error("Could not find property '" + arg + "'"); } }); var toString = Object.prototype.toString, functionType = "[object Function]"; Handlebars.registerHelper('blockHelperMissing', function(context, options) { var inverse = options.inverse || function() {}, fn = options.fn; var ret = ""; var type = toString.call(context); if(type === functionType) { context = context.call(this); } if(context === true) { return fn(this); } else if(context === false || context == null) { return inverse(this); } else if(type === "[object Array]") { if(context.length > 0) { for(var i=0, j=context.length; i 0) { for(var i=0, j=context.length; i": ">", '"': """, "'": "'", "`": "`" }; var badChars = /&(?!\w+;)|[<>"'`]/g; var possible = /[&<>"'`]/; var escapeChar = function(chr) { return escape[chr] || "&"; }; Handlebars.Utils = { escapeExpression: function(string) { // don't escape SafeStrings, since they're already safe if (string instanceof Handlebars.SafeString) { return string.toString(); } else if (string == null || string === false) { return ""; } if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); }, isEmpty: function(value) { if (typeof value === "undefined") { return true; } else if (value === null) { return true; } else if (value === false) { return true; } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) { return true; } else { return false; } } }; })();; // lib/handlebars/runtime.js Handlebars.VM = { template: function(templateSpec) { // Just add water var container = { escapeExpression: Handlebars.Utils.escapeExpression, invokePartial: Handlebars.VM.invokePartial, programs: [], program: function(i, fn, data) { var programWrapper = this.programs[i]; if(data) { return Handlebars.VM.program(fn, data); } else if(programWrapper) { return programWrapper; } else { programWrapper = this.programs[i] = Handlebars.VM.program(fn); return programWrapper; } }, programWithDepth: Handlebars.VM.programWithDepth, noop: Handlebars.VM.noop }; return function(context, options) { options = options || {}; return templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data); }; }, programWithDepth: function(fn, data, $depth) { var args = Array.prototype.slice.call(arguments, 2); return function(context, options) { options = options || {}; return fn.apply(this, [context, options.data || data].concat(args)); }; }, program: function(fn, data) { return function(context, options) { options = options || {}; return fn(context, options.data || data); }; }, noop: function() { return ""; }, invokePartial: function(partial, name, context, helpers, partials, data) { options = { helpers: helpers, partials: partials, data: data }; if(partial === undefined) { throw new Handlebars.Exception("The partial " + name + " could not be found"); } else if(partial instanceof Function) { return partial(context, options); } else if (!Handlebars.compile) { throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode"); } else { partials[name] = Handlebars.compile(partial); return partials[name](context, options); } } }; Handlebars.template = Handlebars.VM.template; ;