Skip to content

Commit

Permalink
Use env.VM to lookup runtime methods
Browse files Browse the repository at this point in the history
Allows for overrides by 3rd parties

Fixes #679
  • Loading branch information
kpdecker committed Dec 24, 2013
1 parent 956ac95 commit abe9c82
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@ export function template(templateSpec, 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 != null) { 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 != null) { return result; }
} else {
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
};
}
}
};

// Just add water
var container = {
Expand All @@ -71,8 +66,8 @@ export function template(templateSpec, env) {
}
return ret;
},
programWithDepth: programWithDepth,
noop: noop,
programWithDepth: env.VM.programWithDepth,
noop: env.VM.noop,
compilerInfo: null
};

Expand Down

0 comments on commit abe9c82

Please sign in to comment.