Support parent tags and block args as direct children of blocks and sections.

Fixes #294

Drive-by: rename blocks context variable to something more descriptive.
This commit is contained in:
Justin Hileman
2016-05-18 22:45:46 -07:00
parent 21d553fc02
commit 051f857197
+8 -5
View File
@@ -191,7 +191,7 @@ class Mustache_Compiler
{ {
$this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context); $this->lambdaHelper = new Mustache_LambdaHelper($this->mustache, $context);
$buffer = \'\'; $buffer = \'\';
$newContext = array(); $blocksContext = array();
%s %s
return $buffer; return $buffer;
@@ -207,7 +207,7 @@ class Mustache_Compiler
public function renderInternal(Mustache_Context $context, $indent = \'\') public function renderInternal(Mustache_Context $context, $indent = \'\')
{ {
$buffer = \'\'; $buffer = \'\';
$newContext = array(); $blocksContext = array();
%s %s
return $buffer; return $buffer;
@@ -264,7 +264,7 @@ class Mustache_Compiler
return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level)); return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level));
} }
const BLOCK_ARG = '$newContext[%s] = array($this, \'block%s\');'; const BLOCK_ARG = '$blocksContext[%s] = array($this, \'block%s\');';
/** /**
* Generate Mustache Template inheritance block argument PHP source. * Generate Mustache Template inheritance block argument PHP source.
@@ -291,7 +291,8 @@ class Mustache_Compiler
const BLOCK_FUNCTION = ' const BLOCK_FUNCTION = '
public function block%s($context) public function block%s($context)
{ {
$indent = $buffer = \'\';%s $indent = $buffer = \'\';
$blocksContext = array();%s
return $buffer; return $buffer;
} }
@@ -326,6 +327,8 @@ class Mustache_Compiler
private function section%s(Mustache_Context $context, $indent, $value) private function section%s(Mustache_Context $context, $indent, $value)
{ {
$buffer = \'\'; $buffer = \'\';
$blocksContext = array();
if (%s) { if (%s) {
$source = %s; $source = %s;
$result = call_user_func($value, $source, %s); $result = call_user_func($value, $source, %s);
@@ -457,7 +460,7 @@ class Mustache_Compiler
%s %s
if ($parent = $this->mustache->loadPartial(%s)) { if ($parent = $this->mustache->loadPartial(%s)) {
$context->pushBlockContext($newContext); $context->pushBlockContext($blocksContext);
$buffer .= $parent->renderInternal($context, $indent); $buffer .= $parent->renderInternal($context, $indent);
$context->popBlockContext(); $context->popBlockContext();
} }