Skip to content

Commit

Permalink
UIMacros: supports {control|noescape}
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 1, 2021
1 parent 3f474b4 commit 4f97f29
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -81,11 +81,13 @@ public function finalize()
*/
public function macroControl(MacroNode $node, PhpWriter $writer)
{
if ($node->context !== [Latte\Compiler::CONTENT_HTML, Latte\Compiler::CONTEXT_HTML_TEXT]) {
$tmp = Latte\Helpers::removeFilter($node->modifiers, 'noescape') ? '' : '|escape';
}
if ($node->modifiers) {
trigger_error('Modifiers are deprecated in ' . $node->getNotation(), E_USER_DEPRECATED);
} elseif ($node->context !== [Latte\Compiler::CONTENT_HTML, Latte\Compiler::CONTEXT_HTML_TEXT]) {
$node->modifiers .= '|escape';
}
$node->modifiers .= $tmp ?? '';

$words = $node->tokenizer->fetchWords();
if (!$words) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Bridges.Latte/UIMacros.control.3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Assert::exception(function () use ($latte) {
$latte->renderToString('<div {control x}');
}, Latte\RuntimeException::class, 'Filters: unable to convert content type HTML to HTMLTAG');

Assert::same(
'<div <>&amp;',
$latte->renderToString('<div {control x|noescape}'),
);

Assert::same(
'<div title="&lt;&gt;&amp;">',
$latte->renderToString('<div title="{control x}">')
Expand Down

0 comments on commit 4f97f29

Please sign in to comment.