Skip to content

Commit

Permalink
LatteExtension: initializes Latte Panel, added option 'debugger'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 16, 2021
1 parent 4a2d940 commit 65c419a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Nette;
use Nette\Bridges\ApplicationLatte;
use Nette\Schema\Expect;
use Tracy;


/**
Expand All @@ -37,6 +38,7 @@ public function __construct(string $tempDir, bool $debugMode = false)
public function getConfigSchema(): Nette\Schema\Schema
{
return Expect::structure([
'debugger' => Expect::anyOf(true, false, 'all'),
'xhtml' => Expect::bool(false),
'macros' => Expect::arrayOf('string'),
'templateClass' => Expect::string(),
Expand Down Expand Up @@ -83,6 +85,34 @@ public function loadConfiguration()
}


public function beforeCompile()
{
$builder = $this->getContainerBuilder();

if (
$this->debugMode
&& ($this->config->debugger ?? $builder->getByType(Tracy\Bar::class))
&& class_exists(Latte\Bridges\Tracy\LattePanel::class)
) {
$factory = $builder->getDefinition($this->prefix('templateFactory'));
$factory->addSetup([self::class, 'initLattePanel'], [$factory, 'all' => $this->config->debugger === 'all']);
}
}


public static function initLattePanel(ApplicationLatte\TemplateFactory $factory, Tracy\Bar $bar, bool $all = false)
{
$factory->onCreate[] = function (ApplicationLatte\Template $template) use ($bar, $all) {
if ($all || $template->control instanceof Nette\Application\UI\Presenter) {
$bar->addPanel(new Latte\Bridges\Tracy\LattePanel(
$template->getLatte(),
$all ? (new \ReflectionObject($template->control))->getShortName() : null
));
}
};
}


public function addMacro(string $macro): void
{
$builder = $this->getContainerBuilder();
Expand Down

0 comments on commit 65c419a

Please sign in to comment.