Skip to content

Commit 5630891

Browse files
committed
UIMacros: own handler for {extends}
1 parent 67b8cf9 commit 5630891

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,10 +36,28 @@ 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']);
3941
$me->addMacro('includeblock', [$me, 'macroIncludeBlock']);
4042
}
4143

4244

45+
/**
46+
* Initializes before template parsing.
47+
* @return void
48+
*/
49+
public function initialize()
50+
{
51+
$this->getCompiler()->addMethod('getExtends', '
52+
if (empty($this->params["_g"]->extended)) {
53+
$this->params["_g"]->extended = __CLASS__;
54+
}
55+
return $this->params["_g"]->extended === __CLASS__ && isset($this->params["_control"]) && $this->params["_control"] instanceof Nette\Application\UI\Presenter
56+
? $this->params["_control"]->findLayoutTemplateFile() : NULL;
57+
');
58+
}
59+
60+
4361
/**
4462
* Finishes template parsing.
4563
* @return array(prolog, epilog)
@@ -104,6 +122,18 @@ public function macroIfCurrent(MacroNode $node, PhpWriter $writer)
104122
}
105123

106124

125+
/**
126+
* {extends auto}
127+
*/
128+
public function macroExtends(MacroNode $node, PhpWriter $writer)
129+
{
130+
if ($node->modifiers || $node->parentNode || $node->args !== 'auto') {
131+
return FALSE;
132+
}
133+
$this->getCompiler()->addMethod('getExtends', 'return $this->params["_presenter"]->findLayoutTemplateFile();');
134+
}
135+
136+
107137
/**
108138
* {includeblock "file"}
109139
*/

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 ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->exten
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 ($_l->extends) { ob_end_clean(); return $this->renderChildTemplate($_l->exten
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
@@ -32,6 +32,12 @@ call_user_func(reset($_b->blocks['_outer']), $_b, $this->params) ?>
3232
}
3333

3434

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

5965
}
6066

61-
62-
function getExtends()
63-
{
64-
}
65-
6667
}

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)