mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-04-15 10:57:24 +03:00
Implementation + tests for the @root special variable like in handlebars-v2.0.0.js
fixed travis complaints
This commit is contained in:
parent
382938b82e
commit
b65be0e1c5
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user