Skip to content

Commit

Permalink
UIMacros: {ifCurrent} calls isLinkCurrent() method
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 25, 2015
1 parent 878d3dc commit 6144b26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Bridges/ApplicationLatte/UIMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ public function macroLink(MacroNode $node, PhpWriter $writer)
*/
public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
{
return $writer->write(($node->args ? 'try { $_presenter->link(%node.word, %node.array?); } catch (Nette\Application\UI\InvalidLinkException $e) {}' : '')
. '; if ($_presenter->getLastCreatedRequestFlag("current")) {');
return $writer->write($node->args
? 'if ($_presenter->isLinkCurrent(%node.word, %node.array?)) {'
: 'if ($_presenter->getLastCreatedRequestFlag("current")) {'
);
}


Expand Down
4 changes: 4 additions & 0 deletions tests/Application.Latte/UIMacros.isLinkCurrent.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ Assert::matchFile(__DIR__ . '/expected/UIMacros.isLinkCurrent.phtml', $latte->co
<a href="{link default}" n:class="$presenter->isLinkCurrent() ? current">href before n:class</a>
<a n:class="$presenter->isLinkCurrent() ? current" href="{link default}">href after n:class</a>
{ifCurrent}empty{/ifCurrent}
{ifCurrent default}default{/ifCurrent}
'));
6 changes: 6 additions & 0 deletions tests/Application.Latte/expected/UIMacros.isLinkCurrent.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
<a href="%A%"%A%>href before n:class</a>

<a href="%A%"%A%>href after n:class</a>

<?php if ($_presenter->getLastCreatedRequestFlag("current")) { ?>empty<?php } ?>


<?php if ($_presenter->isLinkCurrent("default")) { ?>default<?php } ?>

<?php
%A%

0 comments on commit 6144b26

Please sign in to comment.