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 2, 2021
1 parent 8a61eb2 commit c1229f6
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]) {
$escapeMod = 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 .= $escapeMod ?? '';

$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 c1229f6

Please sign in to comment.