Skip to content

Commit

Permalink
UIMacros: Latte 2.4 generates short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 21, 2015
1 parent 9a793cb commit 6074ad2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nette/di": "~2.3",
"nette/forms": "~2.2",
"nette/robot-loader": "~2.2",
"latte/latte": "~2.3"
"latte/latte": "~2.4"
},
"conflict": {
"nette/nette": "<2.2"
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationLatte/UIMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
$method = Strings::match($method, '#^\w*\z#') ? "render$method" : "{\"render$method\"}";
$param = $writer->formatArray();
if (!Strings::contains($node->args, '=>')) {
$param = substr($param, 6, -1); // removes array()
$param = substr($param, $param[0] === '[' ? 1 : 6, -1); // removes array() or []
}
return ($name[0] === '$' ? "if (is_object($name)) \$_l->tmp = $name; else " : '')
. '$_l->tmp = $_control->getComponent(' . $name . '); '
Expand Down
4 changes: 2 additions & 2 deletions tests/Application.Latte/UIMacros.control.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Assert::match( '<?php if (is_object($form)) %a% else %a% $_control->getComponent
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType() ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->{"render$type"}() ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType(\'param\') ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType(array(\'param\' => 123)) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType(array(\'param\' => 123)) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode );
Assert::match( '<?php %a% $_control->getComponent("form"); %a%->render(); echo $template->striptags(%a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode );
6 changes: 3 additions & 3 deletions tests/Application.Latte/UIMacros.link.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ Assert::same( '<?php echo $_control->link("$p:$a") ?>', $compiler->expandMacro(
Assert::same( '<?php echo $_control->link("p:a") ?>', $compiler->expandMacro('link', '"p:a"', '')->openingCode );
Assert::same( '<?php echo $_control->link(\'p:a\') ?>', $compiler->expandMacro('link', "'p:a'", '')->openingCode );

Assert::same( '<?php echo $_control->link("p", array(\'param\')) ?>', $compiler->expandMacro('link', 'p param', '')->openingCode );
Assert::same( '<?php echo $_control->link("p", array(\'param\' => 123)) ?>', $compiler->expandMacro('link', 'p param => 123', '')->openingCode );
Assert::same( '<?php echo $_control->link("p", array(\'param\' => 123)) ?>', $compiler->expandMacro('link', 'p, param => 123', '')->openingCode );
Assert::same( '<?php echo $_control->link("p", [\'param\']) ?>', $compiler->expandMacro('link', 'p param', '')->openingCode );
Assert::same( '<?php echo $_control->link("p", [\'param\' => 123]) ?>', $compiler->expandMacro('link', 'p param => 123', '')->openingCode );
Assert::same( '<?php echo $_control->link("p", [\'param\' => 123]) ?>', $compiler->expandMacro('link', 'p, param => 123', '')->openingCode );

0 comments on commit 6074ad2

Please sign in to comment.