Implementation + tests for the @root special variable like in handlebars-v2.0.0.js

fixed travis complaints
This commit is contained in:
Thomas Seven 2015-03-04 21:40:54 +01:00
parent 382938b82e
commit b65be0e1c5
2 changed files with 31 additions and 0 deletions

View File

@ -203,6 +203,10 @@ class Context
return '';
}
if (substr($variableName, 0, 6) == '@root.') {
$variableName = trim(substr($variableName, 6));
$level = count($this->stack)-1;
}
end($this->stack);
while ($level) {
prev($this->stack);

View File

@ -1226,6 +1226,33 @@ EOM;
$this->assertEquals($res, $results);
}
public function rootSpecialVariableProvider()
{
return array(
array('{{foo}} {{ @root.foo }}', array( 'foo' => 'bar' ), "bar bar"),
array('{{@root.foo}} {{#each arr}}{{ @root.foo }}{{/each}}', array( 'foo' => 'bar', 'arr' => array( '1' ) ), "bar bar"),
);
}
/**
* Test 'root' special variable
*
* @param string $template template text
* @param array $data context data
* @param string $results The Expected Results
*
* @dataProvider rootSpecialVariableProvider
*
* @return void
*/
public function testRootSpecialVariableHelpers($template, $data, $results)
{
$engine = new \Handlebars\Handlebars();
$res = $engine->render($template, $data);
$this->assertEquals($res, $results);
}
}
/**