Skip to content

Commit 30d2ad4

Browse files
committed
tests: Latte generates pretty code
1 parent 6075edf commit 30d2ad4

File tree

4 files changed

+247
-117
lines changed

4 files changed

+247
-117
lines changed

tests/Forms.Latte/expected/FormMacros.button.phtml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ class Template%a% extends Latte\Template
66

77
function render()
88
{
9-
%A%?>
10-
<form<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], array (
11-
), FALSE) ?>>
12-
<button<?php $_input = $_form["send"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
9+
%A%<form<?php
10+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], array (
11+
), FALSE) ?>>
12+
<button<?php
13+
$_input = $_form["send"];
14+
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>>
1315
description of button
1416
</button>
1517

16-
<button<?php $_input = $_form["send"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>></button>
18+
<button<?php
19+
$_input = $_form["send"];
20+
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>></button>
1721

18-
<button<?php $_input = $_form["send"]; echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>
19-
><?php echo htmlspecialchars($_input->caption) ?></button>
22+
<button<?php
23+
$_input = $_form["send"];
24+
echo $_input->{method_exists($_input, 'getControlPart')?'getControlPart':'getControl'}()->attributes() ?>><?php
25+
echo htmlspecialchars($_input->caption) ?></button>
2026
<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd($_form, FALSE) ?></form>
2127
<?php
2228
}

tests/Forms.Latte/expected/FormMacros.formContainer.phtml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,80 @@ class Template%a% extends Latte\Template
66

77
function render()
88
{
9-
%A%
10-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], []) ?>
9+
extract($this->params);
10+
// prolog Latte\Macros\CoreMacros
11+
if ($this->initialize($_b, $_l, $_g)) return;
12+
13+
// main template
14+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $_control["myForm"], []) ?>
1115

1216
<table>
1317
<tr>
14-
<th><?php if ($_label = $_form["input1"]->getLabel()) echo $_label ?></th>
18+
<th><?php if ($_label = $_form["input1"]->getLabel()) echo $_label ?></th>
1519
<td><?php echo $_form["input1"]->getControl() ?></td>
1620
</tr>
17-
<?php $_formStack[] = $_form; $formContainer = $_form = $_form["cont1"] ?>
21+
<?php
22+
$_formStack[] = $_form;
23+
$formContainer = $_form = $_form["cont1"] ?>
1824
<tr>
19-
<th><?php if ($_label = $_form["input2"]->getLabel()) echo $_label ?></th>
25+
<th><?php if ($_label = $_form["input2"]->getLabel()) echo $_label ?></th>
2026
<td><?php echo $_form["input2"]->getControl() ?></td>
2127
</tr>
2228
<tr>
23-
<th><?php if ($_label = $_form["input3"]->getLabel()) echo $_label ?></th>
29+
<th><?php if ($_label = $_form["input3"]->getLabel()) echo $_label ?></th>
2430
<td><?php echo $_form["input3"]->getControl() ?></td>
2531
</tr>
2632
<tr>
2733
<th>Checkboxes</th>
2834
<td>
29-
<?php $_formStack[] = $_form; $formContainer = $_form = $_form["cont2"] ?> <ol>
30-
<?php $%a% foreach ($formContainer->controls AS $name => $field) { ?>
31-
<li><?php $_input = is_object($field) ? $field : $_form[$field]; echo $_input->getControl() ?></li>
32-
<?php $iterations++; } ?> </ol>
35+
<?php
36+
$_formStack[] = $_form;
37+
$formContainer = $_form = $_form["cont2"] ?> <ol>
38+
<?php
39+
$iterations = 0;
40+
if (isset($this->params['name'])) trigger_error('Variable $name overwritten in foreach.');
41+
if (isset($this->params['field'])) trigger_error('Variable $field overwritten in foreach.');
42+
foreach ($formContainer->controls AS $name => $field) {
43+
?> <li><?php
44+
$_input = is_object($field) ? $field : $_form[$field];
45+
echo $_input->getControl() ?></li>
46+
<?php
47+
$iterations++;
48+
}
49+
?> </ol>
3350
<?php $formContainer = $_form = array_pop($_formStack) ?>
3451
</td>
3552
</tr>
3653
<tr>
37-
<th><?php if ($_label = $_form["input7"]->getLabel()) echo $_label ?></th>
54+
<th><?php if ($_label = $_form["input7"]->getLabel()) echo $_label ?></th>
3855
<td><?php echo $_form["input7"]->getControl() ?></td>
3956
</tr>
40-
<?php $formContainer = $_form = array_pop($_formStack) ;$_formStack[] = $_form; $formContainer = $_form = $_form["items"] ?>
57+
<?php
58+
$formContainer = $_form = array_pop($_formStack);
59+
$_formStack[] = $_form;
60+
$formContainer = $_form = $_form["items"] ?>
4161
<tr>
4262
<th>Items</th>
4363
<td>
44-
<?php $items = array(1, 2, 3) ;%a% foreach ($items as $item) { if (!isset($formContainer[$item])) continue ;$_formStack[] = $_form; $formContainer = $_form = is_object($item) ? $item : $_form[$item] ?>
45-
<?php echo $_form["input"]->getControl() ?>
64+
<?php
65+
$items = array(1, 2, 3);
66+
$iterations = 0;
67+
if (isset($this->params['item'])) trigger_error('Variable $item overwritten in foreach.');
68+
foreach ($items as $item) {
69+
if (!isset($formContainer[$item])) continue;
70+
$_formStack[] = $_form;
71+
$formContainer = $_form = is_object($item) ? $item : $_form[$item] ?> <?php echo $_form["input"]->getControl() ?>
4672

47-
<?php $formContainer = $_form = array_pop($_formStack) ;$iterations++; } ?>
73+
<?php
74+
$formContainer = $_form = array_pop($_formStack);
75+
$iterations++;
76+
}
77+
?>
4878
</td>
4979
</tr>
5080
<?php $formContainer = $_form = array_pop($_formStack) ?>
5181
<tr>
52-
<th><?php if ($_label = $_form["input8"]->getLabel()) echo $_label ?></th>
82+
<th><?php if ($_label = $_form["input8"]->getLabel()) echo $_label ?></th>
5383
<td><?php echo $_form["input8"]->getControl() ?></td>
5484
</tr>
5585
</table>

0 commit comments

Comments
 (0)