11
11
12
12
use Latte ;
13
13
use Nette ;
14
+ use Nette \Bridges \ApplicationLatte ;
15
+ use Tracy ;
14
16
15
17
16
18
/**
@@ -31,6 +33,9 @@ public function __construct(string $tempDir, bool $debugMode = false)
31
33
$ this ->debugMode = $ debugMode ;
32
34
33
35
$ this ->config = new class {
36
+ /** @var ?bool */
37
+ public $ debugger = null ;
38
+
34
39
/** @var bool */
35
40
public $ xhtml = false ;
36
41
@@ -56,7 +61,7 @@ public function loadConfiguration()
56
61
$ builder = $ this ->getContainerBuilder ();
57
62
58
63
$ latteFactory = $ builder ->addFactoryDefinition ($ this ->prefix ('latteFactory ' ))
59
- ->setImplement (Nette \ Bridges \ ApplicationLatte \LatteFactory::class)
64
+ ->setImplement (ApplicationLatte \LatteFactory::class)
60
65
->getResultDefinition ()
61
66
->setFactory (Latte \Engine::class)
62
67
->addSetup ('setTempDirectory ' , [$ this ->tempDir ])
@@ -70,7 +75,7 @@ public function loadConfiguration()
70
75
71
76
$ builder ->addDefinition ($ this ->prefix ('templateFactory ' ))
72
77
->setType (Nette \Application \UI \TemplateFactory::class)
73
- ->setFactory (Nette \ Bridges \ ApplicationLatte \TemplateFactory::class)
78
+ ->setFactory (ApplicationLatte \TemplateFactory::class)
74
79
->setArguments (['templateClass ' => $ config ->templateClass ]);
75
80
76
81
foreach ($ config ->macros as $ macro ) {
@@ -84,6 +89,31 @@ public function loadConfiguration()
84
89
}
85
90
86
91
92
+ public function beforeCompile ()
93
+ {
94
+ $ builder = $ this ->getContainerBuilder ();
95
+
96
+ if (
97
+ $ this ->debugMode
98
+ && ($ this ->config ->debugger ?? $ builder ->getByType (\Tracy \Bar::class))
99
+ && class_exists (Latte \Bridges \Tracy \LattePanel::class)
100
+ ) {
101
+ $ factory = $ builder ->getDefinition ($ this ->prefix ('templateFactory ' ));
102
+ $ factory ->addSetup ([self ::class, 'initLattePanel ' ], [$ factory ]);
103
+ }
104
+ }
105
+
106
+
107
+ public static function initLattePanel (ApplicationLatte \TemplateFactory $ factory , Tracy \Bar $ bar )
108
+ {
109
+ $ factory ->onCreate [] = function (ApplicationLatte \Template $ template ) use ($ bar ) {
110
+ if ($ template ->control instanceof Nette \Application \UI \Presenter) {
111
+ $ bar ->addPanel (new Latte \Bridges \Tracy \LattePanel ($ template ->getLatte ()));
112
+ }
113
+ };
114
+ }
115
+
116
+
87
117
public function addMacro (string $ macro ): void
88
118
{
89
119
$ builder = $ this ->getContainerBuilder ();
0 commit comments