Merge branch 'master' of github.com:XaminProject/handlebars.php

Conflicts:
	src/Handlebars/Template.php
This commit is contained in:
fzerorubigd 2012-11-29 12:24:45 +03:30
commit c735de8e5b

View File

@ -45,7 +45,6 @@ class Handlebars_Template
*/
private $_stack = array();
private $_stopToken = false;
/**
* Handlebars template constructor
*
@ -58,7 +57,7 @@ class Handlebars_Template
$this->handlebars = $engine;
$this->tree = $tree;
$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)
{
$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()
{
return $this->_stopToken;
$topStack = end($this->_stack);
return $topStack[2];
}
/**
* Render top tree
@ -126,37 +128,33 @@ class Handlebars_Template
if (!$context instanceof Handlebars_Context) {
$context = new Handlebars_Context($context);
}
$topTree = end($this->_stack); //This method never pop a value from stack
list($index ,$tree) = $topTree;
$topTree = end($this->_stack); //This method (render) never pop a value from stack
list($index ,$tree, $stop) = $topTree;
$buffer = '';
while (array_key_exists($index, $tree)) {
$current = $tree[$index];
$index++;
//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::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;
}
switch ($current[Handlebars_Tokenizer::TYPE]) {
case Handlebars_Tokenizer::T_SECTION :
$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);
array_pop($this->_stack);
break;
case Handlebars_Tokenizer::T_INVERTED :
$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);
array_pop($this->_stack);
break;
break;
case Handlebars_Tokenizer::T_COMMENT :
$buffer .= '';
break;
@ -178,6 +176,13 @@ class Handlebars_Template
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;
}
@ -194,23 +199,25 @@ class Handlebars_Template
$context = new Handlebars_Context($context);
}
$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)) {
$current = $tree[$index];
$index++;
//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::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;
}
}
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 '';
}
@ -290,7 +297,7 @@ class Handlebars_Template
return '';
}
}
/**
* Process partial section
*