1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SixtyEightPublishers\WebpackEncoreBundle\Latte; |
6
|
|
|
|
7
|
|
|
use Latte; |
8
|
|
|
|
9
|
|
|
final class WebpackEncoreMacros extends Latte\Macros\MacroSet |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param string $jsAssetsMacroName |
13
|
|
|
* @param string $cssAssetsMacroName |
14
|
|
|
* @param \Latte\Compiler $compiler |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
1 |
|
public static function install(string $jsAssetsMacroName, string $cssAssetsMacroName, Latte\Compiler $compiler): void |
19
|
|
|
{ |
20
|
1 |
|
$me = new static($compiler); |
21
|
|
|
|
22
|
1 |
|
$me->addMacro($jsAssetsMacroName, [$me, 'macroJsAssets']); |
23
|
1 |
|
$me->addMacro($cssAssetsMacroName, [$me, 'macroCssAssets']); |
24
|
1 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Latte\MacroNode $node |
28
|
|
|
* @param \Latte\PhpWriter $writer |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
* @throws \Latte\CompileException |
32
|
|
|
*/ |
33
|
1 |
|
public function macroJsAssets(Latte\MacroNode $node, Latte\PhpWriter $writer): string |
34
|
|
|
{ |
35
|
1 |
|
$this->removeEscapeModifier($node); |
36
|
|
|
|
37
|
|
|
return $writer |
38
|
1 |
|
->using($node) |
39
|
1 |
|
->write('echo %modify($this->global->webpackEncoreTagRenderer->renderJsTags(%node.args))'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param \Latte\MacroNode $node |
44
|
|
|
* @param \Latte\PhpWriter $writer |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
* @throws \Latte\CompileException |
48
|
|
|
*/ |
49
|
1 |
|
public function macroCssAssets(Latte\MacroNode $node, Latte\PhpWriter $writer): string |
50
|
|
|
{ |
51
|
1 |
|
$this->removeEscapeModifier($node); |
52
|
|
|
|
53
|
|
|
return $writer |
54
|
1 |
|
->using($node) |
55
|
1 |
|
->write('echo %modify($this->global->webpackEncoreTagRenderer->renderCssTags(%node.args))'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param \Latte\MacroNode $node |
60
|
|
|
*/ |
61
|
1 |
|
private function removeEscapeModifier(Latte\MacroNode $node): void |
62
|
|
|
{ |
63
|
|
|
/** @noinspection PhpInternalEntityUsedInspection */ |
64
|
1 |
|
Latte\Helpers::removeFilter($node->modifiers, 'escape'); |
65
|
1 |
|
} |
66
|
|
|
} |
67
|
|
|
|