Skip to content

Commit 933a7c4

Browse files
committed
UIMacros: own handler for {extends}
1 parent 7fcb78e commit 933a7c4

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ public static function install(Latte\Compiler $compiler)
3636
$me->addMacro('plink', [$me, 'macroLink']);
3737
$me->addMacro('link', [$me, 'macroLink']);
3838
$me->addMacro('ifCurrent', [$me, 'macroIfCurrent'], '}'); // deprecated; use n:class="$presenter->linkCurrent ? ..."
39+
$me->addMacro('extends', [$me, 'macroExtends']);
40+
$me->addMacro('layout', [$me, 'macroExtends']);
41+
}
42+
43+
44+
/**
45+
* Initializes before template parsing.
46+
* @return void
47+
*/
48+
public function initialize()
49+
{
50+
$this->getCompiler()->addMethod('getExtends', '
51+
if (empty($this->params["_g"]->extended)) {
52+
$this->params["_g"]->extended = __CLASS__;
53+
}
54+
return $this->params["_g"]->extended === __CLASS__ && isset($this->params["_control"]) && $this->params["_control"] instanceof Nette\Application\UI\Presenter
55+
? $this->params["_control"]->findLayoutTemplateFile() : NULL;
56+
');
3957
}
4058

4159

@@ -103,6 +121,18 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
103121
}
104122

105123

124+
/**
125+
* {extends auto}
126+
*/
127+
public function macroExtends(MacroNode $node, PhpWriter $writer)
128+
{
129+
if ($node->modifiers || $node->parentNode || $node->args !== 'auto') {
130+
return FALSE;
131+
}
132+
$this->getCompiler()->addMethod('getExtends', 'return $this->params["_presenter"]->findLayoutTemplateFile();');
133+
}
134+
135+
106136
/** @deprecated */
107137
public static function renderSnippets(Nette\Application\UI\Control $control, \stdClass $local, array $params)
108138
{

tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.alt.phtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return
2525
}
2626

2727

28+
function getExtends()
29+
{
30+
if (%A%
31+
}
32+
33+
2834
function blockOuter1($_b, $_args)
2935
{
3036
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
@@ -54,9 +60,4 @@ $_control->redrawControl('outer2', FALSE);
5460
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
5561
}
5662

57-
58-
function getExtends()
59-
{
60-
}
61-
6263
}

tests/Bridges.Latte/expected/UIMacros.dynamicsnippets.phtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ if (Latte\Macros\BlockMacrosRuntime::progress($this, get_defined_vars())) return
2121
}
2222

2323

24+
function getExtends()
25+
{
26+
if (%A%
27+
}
28+
29+
2430
function blockOuter($_b, $_args)
2531
{
2632
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
@@ -38,9 +44,4 @@ $_control->redrawControl('outer', FALSE);
3844
<?php if (isset($_l->dynSnippets)) return $_l->dynSnippets;
3945
}
4046

41-
42-
function getExtends()
43-
{
44-
}
45-
4647
}

tests/Bridges.Latte/expected/UIMacros.snippet.alt.phtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $_b)) return;
3131
}
3232

3333

34+
function getExtends()
35+
{
36+
if (%A%
37+
}
38+
39+
3440
function blockOuter($_b, $_args)
3541
{
3642
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
@@ -57,9 +63,4 @@ $_control->redrawControl('gallery', FALSE);
5763

5864
}
5965

60-
61-
function getExtends()
62-
{
63-
}
64-
6566
}

tests/Bridges.Latte/expected/UIMacros.snippet.phtml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $_b)) return;
4040
}
4141

4242

43-
function block_%h%($_b, $_args)
43+
function getExtends()
44+
{
45+
if (%A%
46+
}
47+
48+
49+
function block_b14a7($_b, $_args)
4450
{
4551
unset($_args["this"]); foreach ($_args as $__k => $__v) $$__k = $__v;
4652
$_control->redrawControl('', FALSE);
@@ -83,9 +89,4 @@ $_control->redrawControl('title2', FALSE)
8389
?>Title 2<?php
8490
}
8591

86-
87-
function getExtends()
88-
{
89-
}
90-
9192
}

0 commit comments

Comments
 (0)