Skip to content

Commit

Permalink
macro n:attr expands array (#158)
Browse files Browse the repository at this point in the history
When the first and only argument to n:attr macro is an array, expand it.
  • Loading branch information
dakujem authored and dg committed May 17, 2017
1 parent 4d95f3a commit b6163f1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Latte/Macros/CoreMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function macroClass(MacroNode $node, PhpWriter $writer)
*/
public function macroAttr(MacroNode $node, PhpWriter $writer)
{
return $writer->write('echo LR\Filters::htmlAttributes(%node.array);');
return $writer->write('$_tmp = %node.array; echo LR\Filters::htmlAttributes(isset($_tmp[0]) && is_array($_tmp[0]) ? $_tmp[0] : $_tmp);');
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/macros.n-macros.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<p title="hello"> </p>


<p title="hello"> </p>

<b>item</b>
<b class="even">item</b>
Expand Down
8 changes: 6 additions & 2 deletions tests/Latte/expected/macros.n-macros.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ class Template%a% extends Latte\Runtime\Template
%A%

<p<?php
echo LR\Filters::htmlAttributes(['title' => 'hello', 'lang' => isset($lang) ? $lang : NULL]);
$_tmp = ['title' => 'hello', 'lang' => isset($lang) ? $lang : NULL];
echo LR\Filters::htmlAttributes(isset($_tmp[0]) && is_array($_tmp[0]) ? $_tmp[0] : $_tmp);
?>> </p>


<p<?php
$_tmp = [['title' => 'hello']];
echo LR\Filters::htmlAttributes(isset($_tmp[0]) && is_array($_tmp[0]) ? $_tmp[0] : $_tmp);
?>> </p>

<?php
$iterations = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/templates/macros.n-macros.latte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<p n:attr="title => hello, lang => isset($lang) ? $lang"> </p>


<p n:attr="[title => hello]"> </p>

{foreach [1,2,3] as $foo}
<b n:class="$iterator->even ? even">item</b>
Expand Down

0 comments on commit b6163f1

Please sign in to comment.