mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Merge pull request #137 from stevejordan/if_unless_depth_correction
Updates if and unless helper behavior for handlebars 4
This commit is contained in:
commit
fe4e79ed83
@ -53,7 +53,6 @@ class IfHelper implements Helper
|
||||
$parsedArgs = $template->parseArguments($args);
|
||||
$tmp = $context->get($parsedArgs[0]);
|
||||
|
||||
$context->push($context->last());
|
||||
if ($tmp) {
|
||||
$template->setStopToken('else');
|
||||
$buffer = $template->render($context);
|
||||
@ -65,7 +64,6 @@ class IfHelper implements Helper
|
||||
$template->setStopToken(false);
|
||||
$buffer = $template->render($context);
|
||||
}
|
||||
$context->pop();
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ class UnlessHelper implements Helper
|
||||
$parsedArgs = $template->parseArguments($args);
|
||||
$tmp = $context->get($parsedArgs[0]);
|
||||
|
||||
$context->push($context->last());
|
||||
|
||||
if (!$tmp) {
|
||||
$template->setStopToken('else');
|
||||
$buffer = $template->render($context);
|
||||
@ -66,8 +64,6 @@ class UnlessHelper implements Helper
|
||||
$buffer = $template->render($context);
|
||||
}
|
||||
|
||||
$context->pop();
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
@ -1383,16 +1383,34 @@ EOM;
|
||||
$this->assertEquals('A-B', $engine->render('{{concat (concat a "-") b}}', array('a' => 'A', 'b' => 'B', 'A-' => '!')));
|
||||
}
|
||||
|
||||
public function ifUnlessDepthDoesntChangeProvider()
|
||||
{
|
||||
return [[
|
||||
'{{#with b}}{{#if this}}{{../a}}{{/if}}{{/with}}',
|
||||
['a' => 'good', 'b' => 'stump'],
|
||||
'good',
|
||||
], [
|
||||
'{{#with b}}{{#unless false}}{{../a}}{{/unless}}{{/with}}',
|
||||
['a' => 'good', 'b' => 'stump'],
|
||||
'good',
|
||||
], [
|
||||
'{{#with foo}}{{#if goodbye}}GOODBYE cruel {{../world}}!{{/if}}{{/with}}',
|
||||
['foo' => ['goodbye' => true], 'world' => 'world'],
|
||||
'GOODBYE cruel world!',
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if and unless adding an extra layer when accessing parent
|
||||
* Test if and unless do not add an extra layer when accessing parent
|
||||
*
|
||||
* @dataProvider ifUnlessDepthDoesntChangeProvider
|
||||
*/
|
||||
public function testIfUnlessExtraLayer()
|
||||
public function testIfUnlessDepthDoesntChange($template, $data, $expected)
|
||||
{
|
||||
$loader = new \Handlebars\Loader\StringLoader();
|
||||
$engine = new \Handlebars\Handlebars(array('loader' => $loader));
|
||||
|
||||
$this->assertEquals('good', $engine->render('{{#with b}}{{#if this}}{{../../a}}{{/if}}{{/with}}', array('a' => 'good', 'b' => 'stump')));
|
||||
$this->assertEquals('good', $engine->render('{{#with b}}{{#unless false}}{{../../a}}{{/unless}}{{/with}}', array('a' => 'good', 'b' => 'stump')));
|
||||
$this->assertEquals($expected, $engine->render($template, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user