Skip to content

Commit 6092150

Browse files
committed
UIMacros: {control} must be used in HTML text [Closes nette/latte#232]
1 parent d529fc9 commit 6092150

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public function macroControl(MacroNode $node, PhpWriter $writer)
8383
{
8484
if ($node->modifiers) {
8585
trigger_error('Modifiers are deprecated in ' . $node->getNotation(), E_USER_DEPRECATED);
86+
} elseif ($node->context !== [Latte\Compiler::CONTENT_HTML, Latte\Compiler::CONTEXT_HTML_TEXT]) {
87+
trigger_error('Tag {control} must be used in HTML text.', E_USER_WARNING);
8688
}
89+
8790
$words = $node->tokenizer->fetchWords();
8891
if (!$words) {
8992
throw new CompileException('Missing control name in {control}');
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Test: {control ...}
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\Bridges\ApplicationLatte\UIMacros;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
$latte = new Latte\Engine;
17+
$latte->setLoader(new Latte\Loaders\StringLoader);
18+
UIMacros::install($latte->getCompiler());
19+
$latte->addProvider('uiControl', new class {
20+
public function __call($name, $args)
21+
{
22+
return new self;
23+
}
24+
});
25+
26+
Assert::error(function () use ($latte) {
27+
$latte->renderToString('<div {control x}');
28+
}, E_USER_WARNING, 'Tag {control} must be used in HTML text.');
29+
30+
Assert::error(function () use ($latte) {
31+
$latte->renderToString('<div title="{control x}"');
32+
}, E_USER_WARNING, 'Tag {control} must be used in HTML text.');
33+
34+
Assert::error(function () use ($latte) {
35+
$latte->renderToString('<style> {control x} </style>');
36+
}, E_USER_WARNING, 'Tag {control} must be used in HTML text.');

0 commit comments

Comments
 (0)