summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-09-02 18:19:18 -0500
committerkpdecker <kpdecker@gmail.com>2013-09-02 18:19:18 -0500
commitcb0c45b29fa9df0b912d843e3a695293f1d10cad (patch)
treecf50b624e59f3beee7d9e7c89be67d3dae7c6b8b /lib/handlebars/runtime.js
parent192887cedce6e6155bb1a079ab2802ff28fbd2bf (diff)
parent0fe78f379ab85e586381e167aecd7d5527984697 (diff)
downloadhandlebars.js-cb0c45b29fa9df0b912d843e3a695293f1d10cad.zip
handlebars.js-cb0c45b29fa9df0b912d843e3a695293f1d10cad.tar.gz
handlebars.js-cb0c45b29fa9df0b912d843e3a695293f1d10cad.tar.bz2
Merge branch 'master' into es6-modules
Conflicts: Gruntfile.js Rakefile dist/handlebars.js dist/handlebars.runtime.js lib/handlebars.js lib/handlebars/base.js lib/handlebars/runtime.js lib/handlebars/utils.js package.json
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js57
1 files changed, 38 insertions, 19 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 74361e8..eeef182 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -1,11 +1,31 @@
import { escapeExpression, extend, Exception } from "./utils";
import { COMPILER_REVISION, REVISION_CHANGES } from "./base";
+function checkRevision(compilerInfo) {
+ var compilerRevision = compilerInfo && compilerInfo[0] || 1,
+ currentRevision = Handlebars.COMPILER_REVISION;
+
+ if (compilerRevision !== currentRevision) {
+ if (compilerRevision < currentRevision) {
+ var runtimeVersions = Handlebars.REVISION_CHANGES[currentRevision],
+ compilerVersions = Handlebars.REVISION_CHANGES[compilerRevision];
+ throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
+ "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
+ } else {
+ // Use the embedded version info since the runtime doesn't know about this revision yet
+ throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
+ "Please update your runtime to a newer version ("+compilerInfo[1]+").";
+ }
+ }
+}
+
// TODO: Remove this line and break up compilePartial
export function template(templateSpec, Hbars, compile) {
if (compile) {
var 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; }
@@ -42,7 +62,7 @@ export function template(templateSpec, Hbars, compile) {
merge: function(param, common) {
var ret = param || common;
- if (param && common) {
+ if (param && common && (param !== common)) {
ret = {};
extend(ret, common);
extend(ret, param);
@@ -56,24 +76,23 @@ export function template(templateSpec, Hbars, compile) {
return function(context, options) {
options = options || {};
+ var namespace = options.partial ? options : Handlebars,
+ helpers,
+ partials;
- var result = templateSpec.call(container, Hbars, context, options.helpers, options.partials, options.data);
-
- var compilerInfo = container.compilerInfo || [],
- compilerRevision = compilerInfo[0] || 1,
- currentRevision = COMPILER_REVISION;
-
- if (compilerRevision !== currentRevision) {
- if (compilerRevision < currentRevision) {
- var runtimeVersions = REVISION_CHANGES[currentRevision],
- compilerVersions = REVISION_CHANGES[compilerRevision];
- throw "Template was precompiled with an older version of Handlebars than the current runtime. "+
- "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").";
- } else {
- // Use the embedded version info since the runtime doesn't know about this revision yet
- throw "Template was precompiled with a newer version of Handlebars than the current runtime. "+
- "Please update your runtime to a newer version ("+compilerInfo[1]+").";
- }
+ if (!options.partial) {
+ helpers = options.helpers;
+ partials = options.partials;
+ }
+ var result = templateSpec.call(
+ container,
+ namespace, context,
+ helpers,
+ partials,
+ options.data);
+
+ if (!options.partial) {
+ checkRevision(container.compilerInfo);
}
return result;
@@ -105,7 +124,7 @@ export function program(i, fn, data) {
}
export function invokePartial(partial, name, context, helpers, partials, data) {
- var options = { helpers: helpers, partials: partials, data: data };
+ var options = { partial: true, helpers: helpers, partials: partials, data: data };
if(partial === undefined) {
throw new Exception("The partial " + name + " could not be found");