1111
1212use Latte ;
1313use Nette ;
14+ use Nette \Bridges \ApplicationLatte ;
15+ use Tracy ;
1416
1517
1618/**
@@ -31,6 +33,9 @@ public function __construct(string $tempDir, bool $debugMode = false)
3133 $ this ->debugMode = $ debugMode ;
3234
3335 $ this ->config = new class {
36+ /** @var ?bool */
37+ public $ debugger = null ;
38+
3439 /** @var bool */
3540 public $ xhtml = false ;
3641
@@ -56,7 +61,7 @@ public function loadConfiguration()
5661 $ builder = $ this ->getContainerBuilder ();
5762
5863 $ latteFactory = $ builder ->addFactoryDefinition ($ this ->prefix ('latteFactory ' ))
59- ->setImplement (Nette \ Bridges \ ApplicationLatte \LatteFactory::class)
64+ ->setImplement (ApplicationLatte \LatteFactory::class)
6065 ->getResultDefinition ()
6166 ->setFactory (Latte \Engine::class)
6267 ->addSetup ('setTempDirectory ' , [$ this ->tempDir ])
@@ -70,7 +75,7 @@ public function loadConfiguration()
7075
7176 $ builder ->addDefinition ($ this ->prefix ('templateFactory ' ))
7277 ->setType (Nette \Application \UI \TemplateFactory::class)
73- ->setFactory (Nette \ Bridges \ ApplicationLatte \TemplateFactory::class)
78+ ->setFactory (ApplicationLatte \TemplateFactory::class)
7479 ->setArguments (['templateClass ' => $ config ->templateClass ]);
7580
7681 foreach ($ config ->macros as $ macro ) {
@@ -84,6 +89,31 @@ public function loadConfiguration()
8489 }
8590
8691
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+
87117 public function addMacro (string $ macro ): void
88118 {
89119 $ builder = $ this ->getContainerBuilder ();
0 commit comments