handlebars.runtime.js in handlebars-source-1.1.2 vs handlebars.runtime.js in handlebars-source-1.2.0

- old
+ new

@@ -1,8 +1,8 @@ /*! - handlebars v1.1.2 + handlebars v1.2.0 Copyright (C) 2011 by Yehuda Katz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,10 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @license */ +/* exported Handlebars */ var Handlebars = (function() { // handlebars/safe-string.js var __module3__ = (function() { "use strict"; var __exports__; @@ -44,10 +45,11 @@ // handlebars/utils.js var __module2__ = (function(__dependency1__) { "use strict"; var __exports__ = {}; + /*jshint -W004 */ var SafeString = __dependency1__; var escape = { "&": "&amp;", "<": "&lt;", @@ -64,11 +66,11 @@ return escape[chr] || "&amp;"; } function extend(obj, value) { for(var key in value) { - if(value.hasOwnProperty(key)) { + if(Object.prototype.hasOwnProperty.call(value, key)) { obj[key] = value[key]; } } } @@ -147,15 +149,14 @@ // handlebars/base.js var __module1__ = (function(__dependency1__, __dependency2__) { "use strict"; var __exports__ = {}; - /*globals Exception, Utils */ var Utils = __dependency1__; var Exception = __dependency2__; - var VERSION = "1.1.2"; + var VERSION = "1.2.0"; __exports__.VERSION = VERSION;var COMPILER_REVISION = 4; __exports__.COMPILER_REVISION = COMPILER_REVISION; var REVISION_CHANGES = { 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it 2: '== 1.0.0-rc.3', @@ -242,19 +243,23 @@ if(context && typeof context === 'object') { if (isArray(context)) { for(var j = context.length; i<j; i++) { if (data) { data.index = i; - data.first = (i === 0) + data.first = (i === 0); data.last = (i === (context.length-1)); } ret = ret + fn(context[i], { data: data }); } } else { for(var key in context) { if(context.hasOwnProperty(key)) { - if(data) { data.key = key; } + if(data) { + data.key = key; + data.index = i; + data.first = (i === 0); + } ret = ret + fn(context[key], {data: data}); i++; } } } @@ -330,11 +335,10 @@ // handlebars/runtime.js var __module5__ = (function(__dependency1__, __dependency2__, __dependency3__) { "use strict"; var __exports__ = {}; - /*global Utils */ var Utils = __dependency1__; var Exception = __dependency2__; var COMPILER_REVISION = __dependency3__.COMPILER_REVISION; var REVISION_CHANGES = __dependency3__.REVISION_CHANGES; @@ -354,36 +358,31 @@ "Please update your runtime to a newer version ("+compilerInfo[1]+")."); } } } - // TODO: Remove this line and break up compilePartial + __exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial function template(templateSpec, env) { if (!env) { throw new Error("No environment passed to template"); } - var invokePartialWrapper; - if (env.compile) { - invokePartialWrapper = function(partial, name, context, helpers, partials, data) { - // TODO : Check this for all inputs and the options handling (partial flag, etc). This feels - // like there should be a common exec path - var result = invokePartial.apply(this, arguments); - if (result) { return result; } + // Note: Using env.VM references rather than local var references throughout this section to allow + // for external users to override these as psuedo-supported APIs. + var invokePartialWrapper = function(partial, name, context, helpers, partials, data) { + var result = env.VM.invokePartial.apply(this, arguments); + if (result != null) { return result; } + if (env.compile) { var options = { helpers: helpers, partials: partials, data: data }; partials[name] = env.compile(partial, { data: data !== undefined }, env); return partials[name](context, options); - }; - } else { - invokePartialWrapper = function(partial, name /* , context, helpers, partials, data */) { - var result = invokePartial.apply(this, arguments); - if (result) { return result; } + } else { throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode"); - }; - } + } + }; // Just add water var container = { escapeExpression: Utils.escapeExpression, invokePartial: invokePartialWrapper, @@ -405,12 +404,12 @@ Utils.extend(ret, common); Utils.extend(ret, param); } return ret; }, - programWithDepth: programWithDepth, - noop: noop, + programWithDepth: env.VM.programWithDepth, + noop: env.VM.noop, compilerInfo: null }; return function(context, options) { options = options || {}; @@ -428,11 +427,11 @@ helpers, partials, options.data); if (!options.partial) { - checkRevision(container.compilerInfo); + env.VM.checkRevision(container.compilerInfo); } return result; }; } @@ -479,9 +478,10 @@ // handlebars.runtime.js var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) { "use strict"; var __exports__; + /*globals Handlebars: true */ var base = __dependency1__; // Each of these augment the Handlebars object. No need to setup here. // (This is done to easily share code between commonjs and browse envs) var SafeString = __dependency2__;