@@ -24,24 +24,38 @@ public function __construct(BladeCompiler $bladeCompiler, array $globalArgs = []
2424 $ this ->bladeDirectives ();
2525 }
2626
27+ /**
28+ * Compile the content and styles of an ODT template
29+ * @return array{content: string, styles: string}
30+ */
2731 public function compile (OdtFile $ template , array $ args = [], array $ options = []): array
2832 {
2933 return [
30- 'content ' => $ this ->compileXML ($ template ->content (), $ template , $ args , $ options ),
31- 'styles ' => $ this ->compileXML ($ template ->styles (), $ template , $ args , $ options ),
34+ 'content ' => $ this ->compileTemplate ($ template ->content (), $ template , $ args , $ options ),
35+ 'styles ' => $ this ->compileTemplate ($ template ->styles (), $ template , $ args , $ options ),
3236 ];
3337 }
3438
35- private function compileXML (string $ xml , OdtFile $ template , array $ args = [], array $ options = []): string
39+ /**
40+ * @param array{content: string, styles: string} $compiled
41+ */
42+ public function render (array $ compiled , array $ args = []): array
43+ {
44+ return [
45+ 'content ' => $ this ->renderTemplate ($ compiled ['content ' ], $ args ),
46+ 'styles ' => $ this ->renderTemplate ($ compiled ['styles ' ], $ args ),
47+ ];
48+ }
49+
50+ private function compileTemplate (string $ xml , OdtFile $ template , array $ args = [], array $ options = []): string
3651 {
3752 if ($ options ['cleanVars ' ] ?? false ) {
3853 $ xml = (new VariableCleaner ())->compile ($ xml );
3954 }
4055 $ xml = $ this ->precompile ($ xml , $ template , $ args );
4156 $ xml = $ this ->bladeCompile ($ xml );
4257
43- $ xml = $ this ->render ($ xml , $ args );
44- return $ this ->postRender ($ xml );
58+ return $ xml ;
4559 }
4660
4761 private function precompile (string $ value , OdtFile $ template , array $ args ): string
@@ -66,7 +80,7 @@ private function bladeCompile(string $value): string
6680 return $ compiled ;
6781 }
6882
69- private function render (string $ renderableContent , $ args ): string
83+ private function renderTemplate (string $ renderableContent , $ args ): string
7084 {
7185 $ args = $ args
7286 + [
@@ -85,11 +99,13 @@ private function render(string $renderableContent, $args): string
8599 try {
86100 eval ('?> ' . $ renderableContent );
87101 } catch (\Exception $ e ) {
88- ob_get_clean ();
102+ ob_end_clean ();
89103 throw $ e ;
90104 }
91105
92- return ob_get_clean ();
106+ $ output = ob_get_clean ();
107+
108+ return $ this ->postRender ($ output );
93109 }
94110
95111 /**
0 commit comments