Skip to content

Commit a4fc407

Browse files
committed
tests: Latte generates pretty code
1 parent 83f19ce commit a4fc407

File tree

6 files changed

+122
-84
lines changed

6 files changed

+122
-84
lines changed

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ class Template%a% extends Latte\Template
1212
function render()
1313
{
1414
%A%
15-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
16-
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
15+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
16+
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
1717

18-
// main template
19-
if ($this->tryRenderParent(get_defined_vars())) return ?>
20-
<div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($this->blockQueue['_outer1']), $this->params) ?>
21-
</div>
18+
// main template
19+
if ($this->tryRenderParent(get_defined_vars())) return;
20+
?><div id="<?php echo $_control->getSnippetId('outer1') ?>"><?php call_user_func(reset($this->blockQueue['_outer1']), $this->params) ?></div>
21+
22+
<div id="<?php echo $_control->getSnippetId('outer2') ?>"><?php call_user_func(reset($this->blockQueue['_outer2']), $this->params) ?></div><?php
2223

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

2726

@@ -34,30 +33,42 @@ if ($this->tryRenderParent(get_defined_vars())) return ?>
3433
function blockOuter1($_args)
3534
{
3635
extract($_args);
37-
$_control->redrawControl('outer1', FALSE);
36+
$_control->redrawControl('outer1', FALSE);
3837

39-
%a% foreach (array(1,2,3) as $id) { ?>
40-
<div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
38+
$iterations = 0;
39+
%a%
40+
foreach (array(1,2,3) as $id) {
41+
?> <div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
4142
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
4243

4344
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?> </div>
44-
<?php $iterations++; } ?>
45-
<?php if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
45+
<?php
46+
$iterations++;
47+
}
48+
?> <?php
49+
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
50+
4651
}
4752

4853

4954
function blockOuter2($_args)
5055
{
5156
extract($_args);
52-
$_control->redrawControl('outer2', FALSE);
57+
$_control->redrawControl('outer2', FALSE);
5358

54-
%a% foreach (array(1,2,3) as $id) { ?>
55-
<div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
59+
$iterations = 0;
60+
%a%
61+
foreach (array(1,2,3) as $id) {
62+
?> <div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
5663
<?php ob_start() ?> #<?php echo LFilters::escapeHtmlText($id) ?>
5764

5865
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?> </div>
59-
<?php $iterations++; } ?>
60-
<?php if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
66+
<?php
67+
$iterations++;
68+
}
69+
?> <?php
70+
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
71+
6172
}
6273

6374
}

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class Template%a% extends Latte\Template
1111
function render()
1212
{
1313
%A%
14-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
15-
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
14+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
15+
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
16+
17+
// main template
18+
if ($this->tryRenderParent(get_defined_vars())) return;
19+
?><div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?></div><?php
1620

17-
// main template
18-
if ($this->tryRenderParent(get_defined_vars())) return ?>
19-
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
20-
</div><?php
2121
}
2222

2323

@@ -30,18 +30,23 @@ if ($this->tryRenderParent(get_defined_vars())) return ?>
3030
function blockOuter($_args)
3131
{
3232
extract($_args);
33-
$_control->redrawControl('outer', FALSE);
33+
$_control->redrawControl('outer', FALSE);
3434

35-
%a% foreach (array(1,2,3) as $id) { ?>
36-
<div id="<?php echo $this->local->dynSnippetId = $_control->getSnippetId("inner-$id") ?>
37-
"><?php ob_start() ?>
35+
$iterations = 0;
36+
%a%
37+
foreach (array(1,2,3) as $id) {
38+
?> <div id="<?php echo $this->local->dynSnippetId = $_control->getSnippetId("inner-$id") ?>"><?php ob_start() ?>
3839

3940
#<?php echo LFilters::escapeHtmlText($id) ?>
4041

4142
<?php $this->local->dynSnippets[$this->local->dynSnippetId] = ob_get_flush() ?>
4243
</div>
43-
<?php $iterations++; } ?>
44-
<?php if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
44+
<?php
45+
$iterations++;
46+
}
47+
?> <?php
48+
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
49+
4550
}
4651

4752
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
<a href="%A%"%A%>href after n:class</a>
88

9-
<?php if ($_presenter->getLastCreatedRequestFlag("current")) { ?>empty<?php } ?>
10-
9+
<?php
10+
if ($_presenter->getLastCreatedRequestFlag("current")) {
11+
?>empty<?php
12+
}
13+
?>
1114

12-
<?php if ($_presenter->isLinkCurrent("default")) { ?>default<?php } ?>
1315

1416
<?php
17+
if ($_presenter->isLinkCurrent("default")) {
18+
?>default<?php
19+
}
1520
%A%

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@ class Template%a% extends Latte\Template
1313
function render()
1414
{
1515
%A%
16-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
17-
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
16+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
17+
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
1818

19-
// main template
20-
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
21-
<?php if ($this->tryRenderParent(get_defined_vars())) return;call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
19+
// main template
20+
?> <div class="test"<?php echo ' id="' . $_control->getSnippetId('outer') . '"' ?>>
21+
<?php
22+
if ($this->tryRenderParent(get_defined_vars())) return;
23+
call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
2224
</div>
2325

2426
<div class="test"<?php echo ' id="' . $_control->getSnippetId('inner') . '"' ?>>
25-
<?php call_user_func(reset($this->blockQueue['_inner']), $this->params) ?> </div>
27+
<?php
28+
call_user_func(reset($this->blockQueue['_inner']), $this->params);
29+
?> </div>
2630

27-
<div class="<?php echo LFilters::escapeHtmlAttr('class') ?>"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>
28-
><?php call_user_func(reset($this->blockQueue['_gallery']), $this->params) ?>
31+
<div class="<?php echo LFilters::escapeHtmlAttr('class') ?>"<?php echo ' id="' . $_control->getSnippetId('gallery') . '"' ?>><?php
32+
call_user_func(reset($this->blockQueue['_gallery']), $this->params) ?>
2933
</div>
3034
<?php
35+
3136
}
3237

3338

@@ -40,25 +45,27 @@ if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueu
4045
function blockOuter($_args)
4146
{
4247
extract($_args);
43-
$_control->redrawControl('outer', FALSE)
44-
?> <p>Outer</p>
48+
$_control->redrawControl('outer', FALSE);
49+
50+
?> <p>Outer</p>
4551
<?php
4652
}
4753

4854

4955
function blockInner($_args)
5056
{
5157
extract($_args);
52-
$_control->redrawControl('inner', FALSE)
53-
?> <p>Inner</p>
58+
$_control->redrawControl('inner', FALSE);
59+
60+
?> <p>Inner</p>
5461
<?php
5562
}
5663

5764

5865
function blockGallery($_args)
5966
{
6067
extract($_args);
61-
$_control->redrawControl('gallery', FALSE);
68+
$_control->redrawControl('gallery', FALSE);
6269

6370

6471
}

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

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Template%a% extends Latte\Template
55
{
66
public $blocks = [
7-
'_' => ['block_b14a7', 'html'],
7+
'_' => ['block_%h%', 'html'],
88
'_outer' => ['blockOuter', 'html'],
99
'_inner' => ['blockInner', 'html'],
1010
'_title' => ['blockTitle', 'html'],
@@ -15,28 +15,30 @@ class Template%a% extends Latte\Template
1515
function render()
1616
{
1717
%A%
18-
// prolog Nette\Bridges\ApplicationLatte\UIMacros
19-
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
18+
// prolog Nette\Bridges\ApplicationLatte\UIMacros
19+
if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueue)) return;
2020

21-
// main template
22-
?>
21+
// main template
22+
?>
23+
24+
<?php
25+
if ($this->tryRenderParent(get_defined_vars())) return;
26+
?><div id="<?php echo $_control->getSnippetId('') ?>"><?php call_user_func(reset($this->blockQueue['_']), $this->params) ?></div>
2327

24-
<?php if ($this->tryRenderParent(get_defined_vars())) return ?>
25-
<div id="<?php echo $_control->getSnippetId('') ?>"><?php call_user_func(reset($this->blockQueue['_']), $this->params) ?>
26-
</div>
2728

29+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?></div>
2830

29-
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
30-
</div>
3131

32+
@<?php
33+
if (true) {
34+
?> Hello World @<?php
35+
}
36+
?>
3237

33-
@<?php if (true) { ?> Hello World @<?php } ?>
3438

39+
<h2 id="<?php echo $_control->getSnippetId('title') ?>"><?php call_user_func(reset($this->blockQueue['_title']), $this->params) ?></h2>
40+
<h2 id="<?php echo $_control->getSnippetId('title2') ?>"><?php call_user_func(reset($this->blockQueue['_title2']), $this->params) ?></h2><?php
3541

36-
<h2 id="<?php echo $_control->getSnippetId('title') ?>"><?php call_user_func(reset($this->blockQueue['_title']), $this->params) ?>
37-
</h2>
38-
<h2 id="<?php echo $_control->getSnippetId('title2') ?>"><?php call_user_func(reset($this->blockQueue['_title2']), $this->params) ?>
39-
</h2><?php
4042
}
4143

4244

@@ -49,7 +51,7 @@ if (Nette\Bridges\ApplicationLatte\UIRuntime::initialize($this, $this->blockQueu
4951
function block_%h%($_args)
5052
{
5153
extract($_args);
52-
$_control->redrawControl('', FALSE);
54+
$_control->redrawControl('', FALSE);
5355

5456

5557
}
@@ -58,35 +60,38 @@ $_control->redrawControl('', FALSE);
5860
function blockOuter($_args)
5961
{
6062
extract($_args);
61-
$_control->redrawControl('outer', FALSE)
62-
?> Outer
63-
<div id="<?php echo $_control->getSnippetId('inner') ?>"><?php call_user_func(reset($this->blockQueue['_inner']), $this->params) ?>
64-
</div> /Outer
63+
$_control->redrawControl('outer', FALSE);
64+
65+
?> Outer
66+
<div id="<?php echo $_control->getSnippetId('inner') ?>"><?php call_user_func(reset($this->blockQueue['_inner']), $this->params) ?></div> /Outer
6567
<?php
6668
}
6769

6870

6971
function blockInner($_args)
7072
{
7173
extract($_args);
72-
$_control->redrawControl('inner', FALSE)
73-
?>Inner<?php
74+
$_control->redrawControl('inner', FALSE);
75+
76+
?>Inner<?php
7477
}
7578

7679

7780
function blockTitle($_args)
7881
{
7982
extract($_args);
80-
$_control->redrawControl('title', FALSE)
81-
?>Title 1<?php
83+
$_control->redrawControl('title', FALSE);
84+
85+
?>Title 1<?php
8286
}
8387

8488

8589
function blockTitle2($_args)
8690
{
8791
extract($_args);
88-
$_control->redrawControl('title2', FALSE)
89-
?>Title 2<?php
92+
$_control->redrawControl('title2', FALSE);
93+
94+
?>Title 2<?php
9095
}
9196

9297
}

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ class Template%a% extends Latte\Template
1414
function render()
1515
{
1616
%A%
17-
// main template
18-
if ($this->tryRenderParent(get_defined_vars())) return;call_user_func(reset($this->blockQueue['_snippet']), $this->params) ?>
17+
// main template
18+
if ($this->tryRenderParent(get_defined_vars())) return;
19+
call_user_func(reset($this->blockQueue['_snippet']), $this->params);
20+
?>
1921

2022

21-
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?>
22-
</div><?php
23+
<div id="<?php echo $_control->getSnippetId('outer') ?>"><?php call_user_func(reset($this->blockQueue['_outer']), $this->params) ?></div><?php
24+
2325
}
2426

2527

2628
function blockSnippet($_args)
2729
{
2830
extract($_args);
29-
$_control->redrawControl('snippet', FALSE);
31+
$_control->redrawControl('snippet', FALSE);
3032

3133

3234
}
3335

3436

3537
function blockBlock1($_args)
3638
{
37-
extract($_args)
38-
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
39+
extract($_args);
40+
?><div<?php echo ' id="' . $_control->getSnippetId('snippet') . '"' ?>>
3941
static
4042
</div>
4143
<?php
@@ -45,17 +47,20 @@ $_control->redrawControl('snippet', FALSE);
4547
function blockOuter($_args)
4648
{
4749
extract($_args);
48-
$_control->redrawControl('outer', FALSE)
49-
?>begin
50+
$_control->redrawControl('outer', FALSE);
51+
52+
?>begin
5053
end
51-
<?php if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
54+
<?php
55+
if (isset($this->local->dynSnippets)) return $this->local->dynSnippets;
56+
5257
}
5358

5459

5560
function blockBlock2($_args)
5661
{
57-
extract($_args)
58-
?><div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
62+
extract($_args);
63+
?><div<?php echo ' id="' . ($this->local->dynSnippetId = $_control->getSnippetId("inner-$id")) . '"' ?>>
5964
dynamic
6065
</div>
6166
<?php

0 commit comments

Comments
 (0)