Skip to content

Commit 55210af

Browse files
committed
Latte bridge: compatibility with Latte master
1 parent 9bb9cec commit 55210af

File tree

7 files changed

+65
-37
lines changed

7 files changed

+65
-37
lines changed

src/Bridges/ApplicationLatte/UIMacros.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function install(Latte\Compiler $compiler)
4848
public function initialize()
4949
{
5050
$this->getCompiler()->addMethod('getParentName', '
51-
return !$this->getReferrerTemplate() && $this->params["_control"] instanceof Nette\Application\UI\Presenter
51+
return !$this->getReferringTemplate() && $this->params["_control"] instanceof Nette\Application\UI\Presenter
5252
? $this->params["_control"]->findLayoutTemplateFile() : NULL;
5353
');
5454
}

src/Bridges/ApplicationLatte/UIRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function initialize(Latte\Template $template, $blockQueue)
3333
$params = $template->getParameters();
3434
if (!$template->getParentName() && !empty($params['_control']->snippetMode)) {
3535
$tmp = $template;
36-
while (in_array($tmp->getReferenceType(), ['extends', 'include', NULL], TRUE) && ($tmp = $tmp->getReferrerTemplate()));
36+
while (in_array($tmp->getReferenceType(), ['extends', 'include', NULL], TRUE) && ($tmp = $tmp->getReferringTemplate()));
3737
if (!$tmp) {
3838
self::renderSnippets($params['_control'], $blockQueue, $params);
3939
return TRUE;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_outer1' => ['blockOuter1', 'html'],
8-
'_outer2' => ['blockOuter2', 'html'],
7+
'_outer1' => 'blockOuter1',
8+
'_outer2' => 'blockOuter2',
9+
];
10+
11+
public $blockTypes = [
12+
'_outer1' => 'html',
13+
'_outer2' => 'html',
914
];
1015

1116

@@ -17,7 +22,6 @@ class Template%a% extends Latte\Template
1722
$template = $this->params["template"];
1823

1924
// main template
20-
if ($this->tryRenderParent(get_defined_vars())) return;
2125
?><div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($this->blockQueue['_outer1']), $this->params) ?></div>
2226

2327
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($this->blockQueue['_outer2']), $this->params) ?></div><?php

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_outer' => ['blockOuter', 'html'],
7+
'_outer' => 'blockOuter',
8+
];
9+
10+
public $blockTypes = [
11+
'_outer' => 'html',
812
];
913

1014

@@ -16,7 +20,6 @@ class Template%a% extends Latte\Template
1620
$template = $this->params["template"];
1721

1822
// main template
19-
if ($this->tryRenderParent(get_defined_vars())) return;
2023
?><div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?></div><?php
2124

2225
}
@@ -40,9 +43,7 @@ class Template%a% extends Latte\Template
4043

4144
#<?php echo LFilters::escapeHtmlText($id) ?>
4245

43-
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?>
44-
</div>
45-
<?php
46+
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?></div><?php
4647
$iterations++;
4748
}
4849
?> <?php

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_outer' => ['blockOuter', 'html'],
8-
'_inner' => ['blockInner', 'html'],
9-
'_gallery' => ['blockGallery', 'html'],
7+
'_outer' => 'blockOuter',
8+
'_inner' => 'blockInner',
9+
'_gallery' => 'blockGallery',
10+
];
11+
12+
public $blockTypes = [
13+
'_outer' => 'html',
14+
'_inner' => 'html',
15+
'_gallery' => 'html',
1016
];
1117

1218

@@ -19,9 +25,7 @@ class Template%a% extends Latte\Template
1925

2026
// main template
2127
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
22-
<?php
23-
if ($this->tryRenderParent(get_defined_vars())) return;
24-
call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
28+
<?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
2529
</div>
2630

2731
<div class="test"<?php echo ' id="' . $_control->getSnippetId('inner') . '"' ?>>

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_' => ['block_%h%', 'html'],
8-
'_outer' => ['blockOuter', 'html'],
9-
'_inner' => ['blockInner', 'html'],
10-
'_title' => ['blockTitle', 'html'],
11-
'_title2' => ['blockTitle2', 'html'],
7+
'_' => 'block_b14a7',
8+
'_outer' => 'blockOuter',
9+
'_inner' => 'blockInner',
10+
'_title' => 'blockTitle',
11+
'_title2' => 'blockTitle2',
12+
];
13+
14+
public $blockTypes = [
15+
'_' => 'html',
16+
'_outer' => 'html',
17+
'_inner' => 'html',
18+
'_title' => 'html',
19+
'_title2' => 'html',
1220
];
1321

1422

@@ -20,7 +28,6 @@ class Template%a% extends Latte\Template
2028
$template = $this->params["template"];
2129

2230
// main template
23-
if ($this->tryRenderParent(get_defined_vars())) return;
2431
?><div id="<?php echo $_control->getSnippetId('') ?>"><?php call_user_func(reset($this->blockQueue['_']), $this->params) ?></div>
2532

2633

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

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_snippet' => ['blockSnippet', 'html'],
8-
'block1' => ['blockBlock1', 'html'],
9-
'_outer' => ['blockOuter', 'html'],
10-
'block2' => ['blockBlock2', 'html'],
7+
'block1' => 'blockBlock1',
8+
'_snippet' => 'blockSnippet',
9+
'_outer' => 'blockOuter',
10+
'block2' => 'blockBlock2',
11+
];
12+
13+
public $blockTypes = [
14+
'block1' => 'html',
15+
'_snippet' => 'html',
16+
'_outer' => 'html',
17+
'block2' => 'html',
1118
];
1219

1320

1421
function render()
1522
{
1623
%A%
1724
// main template
18-
if ($this->tryRenderParent(get_defined_vars())) return;
19-
call_user_func(reset($this->blockQueue['_snippet']), $this->params);
25+
call_user_func(reset($this->blockQueue['block1']), get_defined_vars());
2026
?>
2127

2228

@@ -25,21 +31,23 @@ class Template%a% extends Latte\Template
2531
}
2632

2733

28-
function blockSnippet($_args)
34+
function blockBlock1($_args)
2935
{
3036
extract($_args);
31-
$_control->redrawControl('snippet', FALSE);
32-
37+
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
38+
<?php call_user_func(reset($this->blockQueue['_snippet']), $this->params) ?>
39+
</div>
40+
<?php
3341

3442
}
3543

3644

37-
function blockBlock1($_args)
45+
function blockSnippet($_args)
3846
{
3947
extract($_args);
40-
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
41-
static
42-
</div>
48+
$_control->redrawControl('snippet', FALSE);
49+
50+
?> static
4351
<?php
4452
}
4553

@@ -51,6 +59,9 @@ class Template%a% extends Latte\Template
5159

5260
?>
5361
begin
62+
<?php
63+
call_user_func(reset($this->blockQueue['block2']), get_defined_vars());
64+
?>
5465
end
5566
<?php
5667
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
@@ -62,9 +73,10 @@ end
6273
{
6374
extract($_args);
6475
?><div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
65-
dynamic
66-
</div>
76+
<?php ob_start() ?> dynamic
77+
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?></div>
6778
<?php
79+
6880
}
6981

7082
}

0 commit comments

Comments
 (0)