mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-02 10:16:41 +03:00
Merge branch 'master' of github.com:XaminProject/handlebars.php
Conflicts: src/Handlebars/Template.php
This commit is contained in:
commit
c735de8e5b
@ -45,7 +45,6 @@ class Handlebars_Template
|
|||||||
*/
|
*/
|
||||||
private $_stack = array();
|
private $_stack = array();
|
||||||
|
|
||||||
private $_stopToken = false;
|
|
||||||
/**
|
/**
|
||||||
* Handlebars template constructor
|
* Handlebars template constructor
|
||||||
*
|
*
|
||||||
@ -58,7 +57,7 @@ class Handlebars_Template
|
|||||||
$this->handlebars = $engine;
|
$this->handlebars = $engine;
|
||||||
$this->tree = $tree;
|
$this->tree = $tree;
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
array_push($this->_stack, array (0, $this->getTree()));
|
array_push($this->_stack, array (0, $this->getTree(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +100,9 @@ class Handlebars_Template
|
|||||||
|
|
||||||
public function setStopToken($token)
|
public function setStopToken($token)
|
||||||
{
|
{
|
||||||
$this->_stopToken = $token;
|
$topStack = array_pop($this->_stack);
|
||||||
|
$topStack[2] = $token;
|
||||||
|
array_push($this->_stack, $topStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +113,8 @@ class Handlebars_Template
|
|||||||
|
|
||||||
public function getStopToken()
|
public function getStopToken()
|
||||||
{
|
{
|
||||||
return $this->_stopToken;
|
$topStack = end($this->_stack);
|
||||||
|
return $topStack[2];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Render top tree
|
* Render top tree
|
||||||
@ -126,37 +128,33 @@ class Handlebars_Template
|
|||||||
if (!$context instanceof Handlebars_Context) {
|
if (!$context instanceof Handlebars_Context) {
|
||||||
$context = new Handlebars_Context($context);
|
$context = new Handlebars_Context($context);
|
||||||
}
|
}
|
||||||
$topTree = end($this->_stack); //This method never pop a value from stack
|
$topTree = end($this->_stack); //This method (render) never pop a value from stack
|
||||||
list($index ,$tree) = $topTree;
|
list($index ,$tree, $stop) = $topTree;
|
||||||
|
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
while (array_key_exists($index, $tree)) {
|
while (array_key_exists($index, $tree)) {
|
||||||
$current = $tree[$index];
|
$current = $tree[$index];
|
||||||
$index++;
|
$index++;
|
||||||
//if the section is exactly like waitFor
|
//if the section is exactly like waitFor
|
||||||
if (is_string($this->_stopToken)
|
if (is_string($stop)
|
||||||
&& $current[Handlebars_Tokenizer::TYPE] == Handlebars_Tokenizer::T_ESCAPED
|
&& $current[Handlebars_Tokenizer::TYPE] == Handlebars_Tokenizer::T_ESCAPED
|
||||||
&& $current[Handlebars_Tokenizer::NAME] === $this->_stopToken
|
&& $current[Handlebars_Tokenizer::NAME] === $stop
|
||||||
) {
|
) {
|
||||||
//Ok break here, the helper should be aware of this.
|
|
||||||
$newStack = array_pop($this->_stack);
|
|
||||||
$newStack[0] = $index;
|
|
||||||
array_push($this->_stack, $newStack);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch ($current[Handlebars_Tokenizer::TYPE]) {
|
switch ($current[Handlebars_Tokenizer::TYPE]) {
|
||||||
case Handlebars_Tokenizer::T_SECTION :
|
case Handlebars_Tokenizer::T_SECTION :
|
||||||
$newStack = isset($current[Handlebars_Tokenizer::NODES]) ? $current[Handlebars_Tokenizer::NODES] : array();
|
$newStack = isset($current[Handlebars_Tokenizer::NODES]) ? $current[Handlebars_Tokenizer::NODES] : array();
|
||||||
array_push($this->_stack, array(0, $newStack));
|
array_push($this->_stack, array(0, $newStack, false));
|
||||||
$buffer .= $this->_section($context, $current);
|
$buffer .= $this->_section($context, $current);
|
||||||
array_pop($this->_stack);
|
array_pop($this->_stack);
|
||||||
break;
|
break;
|
||||||
case Handlebars_Tokenizer::T_INVERTED :
|
case Handlebars_Tokenizer::T_INVERTED :
|
||||||
$newStack = isset($current[Handlebars_Tokenizer::NODES]) ? $current[Handlebars_Tokenizer::NODES] : array();
|
$newStack = isset($current[Handlebars_Tokenizer::NODES]) ? $current[Handlebars_Tokenizer::NODES] : array();
|
||||||
array_push($this->_stack, array(0, $newStack));
|
array_push($this->_stack, array(0, $newStack, false));
|
||||||
$buffer .= $this->_inverted($context, $current);
|
$buffer .= $this->_inverted($context, $current);
|
||||||
array_pop($this->_stack);
|
array_pop($this->_stack);
|
||||||
break;
|
break;
|
||||||
case Handlebars_Tokenizer::T_COMMENT :
|
case Handlebars_Tokenizer::T_COMMENT :
|
||||||
$buffer .= '';
|
$buffer .= '';
|
||||||
break;
|
break;
|
||||||
@ -178,6 +176,13 @@ class Handlebars_Template
|
|||||||
throw new RuntimeException('Invalid node type : ' . json_encode($current));
|
throw new RuntimeException('Invalid node type : ' . json_encode($current));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($stop) {
|
||||||
|
//Ok break here, the helper should be aware of this.
|
||||||
|
$newStack = array_pop($this->_stack);
|
||||||
|
$newStack[0] = $index;
|
||||||
|
$newStack[2] = false; //No stop token from now on
|
||||||
|
array_push($this->_stack, $newStack);
|
||||||
|
}
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,23 +199,25 @@ class Handlebars_Template
|
|||||||
$context = new Handlebars_Context($context);
|
$context = new Handlebars_Context($context);
|
||||||
}
|
}
|
||||||
$topTree = end($this->_stack); //This method never pop a value from stack
|
$topTree = end($this->_stack); //This method never pop a value from stack
|
||||||
list($index ,$tree) = $topTree;
|
list($index ,$tree, $stop) = $topTree;
|
||||||
|
|
||||||
while (array_key_exists($index, $tree)) {
|
while (array_key_exists($index, $tree)) {
|
||||||
$current = $tree[$index];
|
$current = $tree[$index];
|
||||||
$index++;
|
$index++;
|
||||||
//if the section is exactly like waitFor
|
//if the section is exactly like waitFor
|
||||||
if (is_string($this->_stopToken)
|
if (is_string($stop)
|
||||||
&& $current[Handlebars_Tokenizer::TYPE] == Handlebars_Tokenizer::T_ESCAPED
|
&& $current[Handlebars_Tokenizer::TYPE] == Handlebars_Tokenizer::T_ESCAPED
|
||||||
&& $current[Handlebars_Tokenizer::NAME] === $this->_stopToken
|
&& $current[Handlebars_Tokenizer::NAME] === $stop
|
||||||
) {
|
) {
|
||||||
//Ok break here, the helper should be aware of this.
|
|
||||||
$newStack = array_pop($this->_stack);
|
|
||||||
$newStack[0] = $index;
|
|
||||||
array_push($this->_stack, $newStack);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($stop) {
|
||||||
|
//Ok break here, the helper should be aware of this.
|
||||||
|
$newStack = array_pop($this->_stack);
|
||||||
|
$newStack[0] = $index;
|
||||||
|
$newStack[2] = false;
|
||||||
|
array_push($this->_stack, $newStack);
|
||||||
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +297,7 @@ class Handlebars_Template
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process partial section
|
* Process partial section
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user