13
13
use Nette ;
14
14
use Nette \Bridges \ApplicationLatte ;
15
15
use Nette \Schema \Expect ;
16
+ use Tracy ;
16
17
17
18
18
19
/**
@@ -37,6 +38,7 @@ public function __construct(string $tempDir, bool $debugMode = false)
37
38
public function getConfigSchema (): Nette \Schema \Schema
38
39
{
39
40
return Expect::structure ([
41
+ 'debugger ' => Expect::anyOf (true , false , 'all ' ),
40
42
'xhtml ' => Expect::bool (false ),
41
43
'macros ' => Expect::arrayOf ('string ' ),
42
44
'templateClass ' => Expect::string (),
@@ -83,6 +85,34 @@ public function loadConfiguration()
83
85
}
84
86
85
87
88
+ public function beforeCompile ()
89
+ {
90
+ $ builder = $ this ->getContainerBuilder ();
91
+
92
+ if (
93
+ $ this ->debugMode
94
+ && ($ this ->config ->debugger ?? $ builder ->getByType (Tracy \Bar::class))
95
+ && class_exists (Latte \Bridges \Tracy \LattePanel::class)
96
+ ) {
97
+ $ factory = $ builder ->getDefinition ($ this ->prefix ('templateFactory ' ));
98
+ $ factory ->addSetup ([self ::class, 'initLattePanel ' ], [$ factory , 'all ' => $ this ->config ->debugger === 'all ' ]);
99
+ }
100
+ }
101
+
102
+
103
+ public static function initLattePanel (ApplicationLatte \TemplateFactory $ factory , Tracy \Bar $ bar , bool $ all = false )
104
+ {
105
+ $ factory ->onCreate [] = function (ApplicationLatte \Template $ template ) use ($ bar , $ all ) {
106
+ if ($ all || $ template ->control instanceof Nette \Application \UI \Presenter) {
107
+ $ bar ->addPanel (new Latte \Bridges \Tracy \LattePanel (
108
+ $ template ->getLatte (),
109
+ $ all ? (new \ReflectionObject ($ template ->control ))->getShortName () : null
110
+ ));
111
+ }
112
+ };
113
+ }
114
+
115
+
86
116
public function addMacro (string $ macro ): void
87
117
{
88
118
$ builder = $ this ->getContainerBuilder ();
0 commit comments