Treat partial exec in a manner closer to helpers

This helps unify the code handling and will also be needed to support string/id tracking on partials.
This commit is contained in:
kpdecker
2014-11-27 09:11:03 -06:00
parent 1124908d2a
commit f990cf0064
4 changed files with 50 additions and 48 deletions
+13 -14
View File
@@ -35,36 +35,35 @@ export function template(templateSpec, env) {
// for external users to override these as psuedo-supported APIs.
env.VM.checkRevision(templateSpec.compiler);
var invokePartialWrapper = function(partial, indent, name, context, hash, helpers, partials, data, depths) {
if (hash) {
context = Utils.extend({}, context, hash);
var invokePartialWrapper = function(partial, context, options) {
if (options.hash) {
context = Utils.extend({}, context, options.hash);
}
if (!partial) {
partial = partials[name];
partial = options.partials[options.name];
}
var result = env.VM.invokePartial.call(this, partial, name, context, helpers, partials, data, depths);
var result = env.VM.invokePartial.call(this, partial, context, options);
if (result == null && env.compile) {
var options = { helpers: helpers, partials: partials, data: data, depths: depths };
partials[name] = env.compile(partial, templateSpec.compilerOptions, env);
result = partials[name](context, options);
options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
result = options.partials[options.name](context, options);
}
if (result != null) {
if (indent) {
if (options.indent) {
var lines = result.split('\n');
for (var i = 0, l = lines.length; i < l; i++) {
if (!lines[i] && i + 1 === l) {
break;
}
lines[i] = indent + lines[i];
lines[i] = options.indent + lines[i];
}
result = lines.join('\n');
}
return result;
} else {
throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
throw new Exception("The partial " + options.name + " could not be compiled when running in runtime-only mode");
}
};
@@ -172,11 +171,11 @@ export function program(container, i, fn, data, depths) {
return prog;
}
export function invokePartial(partial, name, context, helpers, partials, data, depths) {
var options = { partial: true, helpers: helpers, partials: partials, data: data, depths: depths };
export function invokePartial(partial, context, options) {
options.partial = true;
if(partial === undefined) {
throw new Exception("The partial " + name + " could not be found");
throw new Exception("The partial " + options.name + " could not be found");
} else if(partial instanceof Function) {
return partial(context, options);
}