9
9
use Phug \AbstractCompilerModule ;
10
10
use Phug \Compiler ;
11
11
use Phug \CompilerEvent ;
12
+ use Phug \Renderer ;
12
13
use Phug \Util \ModuleContainerInterface ;
13
14
14
15
class JsPhpizePhug extends AbstractCompilerModule
@@ -17,6 +18,14 @@ public function __construct(ModuleContainerInterface $container)
17
18
{
18
19
parent ::__construct ($ container );
19
20
21
+ if ($ container instanceof Renderer) {
22
+ $ container ->setOptionsRecursive ([
23
+ 'compiler_modules ' => [$ this ],
24
+ ]);
25
+
26
+ return ;
27
+ }
28
+
20
29
/* @var Compiler $compiler */
21
30
$ compiler = $ container ;
22
31
@@ -86,19 +95,19 @@ public function compile(JsPhpize $jsPhpize, $code, $fileName)
86
95
public function getEventListeners ()
87
96
{
88
97
return [
89
- CompilerEvent::COMPILE => function (Compiler \Event \CompileEvent $ e ) {
90
- $ e ->getTarget ()->setOption ('jsphpize_engine ' , new JsPhpize ($ this ->getOptions ()));
98
+ CompilerEvent::COMPILE => function (Compiler \Event \CompileEvent $ event ) {
99
+ $ event ->getTarget ()->setOption ('jsphpize_engine ' , new JsPhpize ($ this ->getOptions ()));
91
100
},
92
101
93
- CompilerEvent::OUTPUT => function (Compiler \Event \OutputEvent $ e ) {
94
- $ compiler = $ e ->getTarget ();
102
+ CompilerEvent::OUTPUT => function (Compiler \Event \OutputEvent $ event ) {
103
+ $ compiler = $ event ->getTarget ();
95
104
96
105
/** @var JsPhpize $jsPhpize */
97
106
$ jsPhpize = $ compiler ->getOption ('jsphpize_engine ' );
98
107
$ output = preg_replace (
99
108
'/\{\s*\?><\?(?:php)?\s*\}/ ' ,
100
109
'{} ' ,
101
- $ e ->getOutput ()
110
+ $ event ->getOutput ()
102
111
);
103
112
$ output = preg_replace (
104
113
'/\}\s*\?><\?(?:php)?\s*( ' .
@@ -113,7 +122,7 @@ public function getEventListeners()
113
122
$ output = $ compiler ->getFormatter ()->handleCode ($ dependencies ) . $ output ;
114
123
}
115
124
116
- $ e ->setOutput ($ output );
125
+ $ event ->setOutput ($ output );
117
126
118
127
$ jsPhpize ->flushDependencies ();
119
128
$ compiler ->unsetOption ('jsphpize_engine ' );
0 commit comments