From 6074ad25663a19bea53e880411447738b364ea54 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 21 May 2015 15:02:10 +0200 Subject: [PATCH] UIMacros: Latte 2.4 generates short array syntax --- composer.json | 2 +- src/Bridges/ApplicationLatte/UIMacros.php | 2 +- tests/Application.Latte/UIMacros.control.phpt | 4 ++-- tests/Application.Latte/UIMacros.link.phpt | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index b59770eaf..19adbe76c 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index 86c98d284..bbc4a55b2 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -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 . '); ' diff --git a/tests/Application.Latte/UIMacros.control.phpt b/tests/Application.Latte/UIMacros.control.phpt index 3ac9cde37..b4036d1c6 100644 --- a/tests/Application.Latte/UIMacros.control.phpt +++ b/tests/Application.Latte/UIMacros.control.phpt @@ -21,6 +21,6 @@ Assert::match( 'getComponent Assert::match( 'getComponent("form"); %a%->renderType() ?>', $compiler->expandMacro('control', 'form:type', '')->openingCode ); Assert::match( 'getComponent("form"); %a%->{"render$type"}() ?>', $compiler->expandMacro('control', 'form:$type', '')->openingCode ); Assert::match( 'getComponent("form"); %a%->renderType(\'param\') ?>', $compiler->expandMacro('control', 'form:type param', '')->openingCode ); -Assert::match( 'getComponent("form"); %a%->renderType(array(\'param\' => 123)) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode ); -Assert::match( 'getComponent("form"); %a%->renderType(array(\'param\' => 123)) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode ); +Assert::match( 'getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type param => 123', '')->openingCode ); +Assert::match( 'getComponent("form"); %a%->renderType([\'param\' => 123]) ?>', $compiler->expandMacro('control', 'form:type, param => 123', '')->openingCode ); Assert::match( 'getComponent("form"); %a%->render(); echo $template->striptags(%a%) ?>', $compiler->expandMacro('control', 'form', 'striptags')->openingCode ); diff --git a/tests/Application.Latte/UIMacros.link.phpt b/tests/Application.Latte/UIMacros.link.phpt index 2a1d7cd77..2749e3fa6 100644 --- a/tests/Application.Latte/UIMacros.link.phpt +++ b/tests/Application.Latte/UIMacros.link.phpt @@ -25,6 +25,6 @@ Assert::same( 'link("$p:$a") ?>', $compiler->expandMacro( Assert::same( 'link("p:a") ?>', $compiler->expandMacro('link', '"p:a"', '')->openingCode ); Assert::same( 'link(\'p:a\') ?>', $compiler->expandMacro('link', "'p:a'", '')->openingCode ); -Assert::same( 'link("p", array(\'param\')) ?>', $compiler->expandMacro('link', 'p param', '')->openingCode ); -Assert::same( 'link("p", array(\'param\' => 123)) ?>', $compiler->expandMacro('link', 'p param => 123', '')->openingCode ); -Assert::same( 'link("p", array(\'param\' => 123)) ?>', $compiler->expandMacro('link', 'p, param => 123', '')->openingCode ); +Assert::same( 'link("p", [\'param\']) ?>', $compiler->expandMacro('link', 'p param', '')->openingCode ); +Assert::same( 'link("p", [\'param\' => 123]) ?>', $compiler->expandMacro('link', 'p param => 123', '')->openingCode ); +Assert::same( 'link("p", [\'param\' => 123]) ?>', $compiler->expandMacro('link', 'p, param => 123', '')->openingCode );