From ed03dd15a190a3c01f9fab7779e42a9253010292 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 29 Apr 2016 13:03:21 +0200 Subject: [PATCH] UIMacros: looking for layout template moved to UIMacros --- .../ApplicationLatte/TemplateFactory.php | 2 +- src/Bridges/ApplicationLatte/UIMacros.php | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 84184402e..b8f0ea9f9 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -61,7 +61,7 @@ public function createTemplate(UI\Control $control = NULL) array_unshift($latte->onCompile, function ($latte) use ($control, $template) { $latte->getParser()->shortNoEscape = TRUE; $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler())); - UIMacros::install($latte->getCompiler()); + UIMacros::install($latte->getCompiler(), $control instanceof UI\Presenter ? $control : NULL); if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) { Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); } diff --git a/src/Bridges/ApplicationLatte/UIMacros.php b/src/Bridges/ApplicationLatte/UIMacros.php index 3cb8a51dd..ba03eb45e 100644 --- a/src/Bridges/ApplicationLatte/UIMacros.php +++ b/src/Bridges/ApplicationLatte/UIMacros.php @@ -8,11 +8,12 @@ namespace Nette\Bridges\ApplicationLatte; use Nette; +use Nette\Application\UI\Presenter; +use Nette\Utils\Strings; use Latte; use Latte\MacroNode; use Latte\PhpWriter; use Latte\CompileException; -use Nette\Utils\Strings; /** @@ -24,10 +25,15 @@ */ class UIMacros extends Latte\Macros\MacroSet { + /** @var Presenter|NULL */ + private $presenter; - public static function install(Latte\Compiler $compiler) + + public static function install(Latte\Compiler $compiler, Presenter $presenter = NULL) { $me = new static($compiler); + $me->presenter = $presenter; + $me->addMacro('control', [$me, 'macroControl']); $me->addMacro('href', NULL, NULL, function (MacroNode $node, PhpWriter $writer) use ($me) { @@ -47,10 +53,11 @@ public static function install(Latte\Compiler $compiler) */ public function initialize() { - $this->getCompiler()->addMethod('getExtends', ' - return !$this->getParent() && $this->params["_control"] instanceof Nette\Application\UI\Presenter - ? $this->params["_control"]->findLayoutTemplateFile() : NULL; - '); + $layout = $this->presenter + ? '!$this->getParent() ? ' . var_export($this->presenter->findLayoutTemplateFile(), TRUE) . ' : NULL' + : '!$this->getParent() && $this->params["_control"] instanceof Nette\Application\UI\Presenter + ? $this->params["_control"]->findLayoutTemplateFile() : NULL'; + $this->getCompiler()->addMethod('getExtends', "return $layout;"); } @@ -126,7 +133,10 @@ public function macroExtends(MacroNode $node, PhpWriter $writer) if ($node->modifiers || $node->parentNode || $node->args !== 'auto') { return FALSE; } - $this->getCompiler()->addMethod('getExtends', 'return $this->params["_presenter"]->findLayoutTemplateFile();'); + $layout = $this->presenter + ? var_export($this->presenter->findLayoutTemplateFile(), TRUE) + : '$this->params["_presenter"]->findLayoutTemplateFile()'; + $this->getCompiler()->addMethod('getExtends', "return $layout;"); }