diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-14 15:18:52 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-22 10:59:08 -0700 |
commit | 91ffd32cad32b2d1cd310ff94f65b28c428206ac (patch) | |
tree | 13cb346dfb0e6dc72dc6dddbcdf3ed8e61ebaeff /lib/handlebars/compiler/compiler.js | |
parent | 2571dd8e8e43fd320672763564b16a5b3ae33966 (diff) | |
download | handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.zip handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.tar.gz handlebars.js-91ffd32cad32b2d1cd310ff94f65b28c428206ac.tar.bz2 |
Implement partial blocks
This allows for failover for missing partials as well as limited templating ability through the `{{> @partial-block }}` partial special case.
Partial fix for #1018
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index ad6b861..a689e7d 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,3 +1,5 @@ +/* eslint-disable new-cap */ + import Exception from '../exception'; import {isArray, indexOf} from '../utils'; import AST from './ast'; @@ -157,6 +159,11 @@ Compiler.prototype = { PartialStatement: function(partial) { this.usePartial = true; + let program = partial.program; + if (program) { + program = this.compileProgram(partial.program); + } + let params = partial.params; if (params.length > 1) { throw new Exception('Unsupported number of partial arguments: ' + params.length, partial); @@ -170,7 +177,7 @@ Compiler.prototype = { this.accept(partial.name); } - this.setupFullMustacheParams(partial, undefined, undefined, true); + this.setupFullMustacheParams(partial, program, undefined, true); let indent = partial.indent || ''; if (this.options.preventIndent && indent) { @@ -181,9 +188,12 @@ Compiler.prototype = { this.opcode('invokePartial', isDynamic, partialName, indent); this.opcode('append'); }, + PartialBlockStatement: function(partialBlock) { + this.PartialStatement(partialBlock); + }, MustacheStatement: function(mustache) { - this.SubExpression(mustache); // eslint-disable-line new-cap + this.SubExpression(mustache); if (mustache.escaped && !this.options.noEscape) { this.opcode('appendEscaped'); |