1 | <?php |
||
2 | /** |
||
3 | * Minify plugin for Craft CMS |
||
4 | * |
||
5 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
6 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
7 | * @license MIT License https://opensource.org/licenses/MIT |
||
8 | */ |
||
0 ignored issues
–
show
|
|||
9 | |||
10 | namespace nystudio107\minify\twigextensions; |
||
11 | |||
12 | use nystudio107\minify\Minify; |
||
13 | use Twig\Compiler; |
||
14 | use Twig\Node\Node; |
||
15 | |||
16 | /** |
||
17 | * Minify twig node parser |
||
18 | * |
||
19 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
20 | * @package Minify |
||
0 ignored issues
–
show
|
|||
21 | * @since 1.2.0 |
||
0 ignored issues
–
show
|
|||
22 | */ |
||
0 ignored issues
–
show
|
|||
23 | class MinifyNode extends Node |
||
24 | { |
||
25 | // Public Methods |
||
26 | // ========================================================================= |
||
27 | |||
28 | /** |
||
0 ignored issues
–
show
|
|||
29 | * @param Compiler $compiler |
||
0 ignored issues
–
show
|
|||
30 | */ |
||
0 ignored issues
–
show
|
|||
31 | public function compile(Compiler $compiler): void |
||
32 | { |
||
33 | $html = $this->getAttribute('html'); |
||
34 | $css = $this->getAttribute('css'); |
||
35 | $js = $this->getAttribute('js'); |
||
36 | |||
37 | $compiler |
||
38 | ->addDebugInfo($this); |
||
39 | |||
40 | $compiler |
||
41 | ->write("ob_start();\n") |
||
42 | ->subcompile($this->getNode('body')) |
||
43 | ->write("\$_compiledBody = ob_get_clean();\n"); |
||
44 | |||
45 | if ($html) { |
||
46 | $compiler |
||
47 | ->write("echo " . Minify::class . "::\$plugin->minify->htmlMin(\$_compiledBody);\n"); |
||
48 | } elseif ($css) { |
||
49 | $compiler |
||
50 | ->write("echo " . Minify::class . "::\$plugin->minify->cssMin(\$_compiledBody);\n"); |
||
51 | } elseif ($js) { |
||
52 | $compiler |
||
53 | ->write("echo " . Minify::class . "::\$plugin->minify->jsMin(\$_compiledBody);\n"); |
||
54 | } else { |
||
55 | $compiler |
||
56 | ->write("echo " . Minify::class . "::\$plugin->minify->minify(\$_compiledBody);\n"); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 |