Skip to content

Commit 3bbf691

Browse files
committed
compatible with Latte 3.1
1 parent 7da987c commit 3bbf691

File tree

8 files changed

+137
-160
lines changed

8 files changed

+137
-160
lines changed

src/Bridges/FormsLatte/Nodes/FieldNNameNode.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Latte\Compiler\Nodes\AuxiliaryNode;
1414
use Latte\Compiler\Nodes\Html\AttributeNode;
1515
use Latte\Compiler\Nodes\Html\ElementNode;
16+
use Latte\Compiler\Nodes\Html\ExpressionAttributeNode;
1617
use Latte\Compiler\Nodes\NopNode;
1718
use Latte\Compiler\Nodes\Php\ExpressionNode;
1819
use Latte\Compiler\Nodes\Php\Scalar\StringNode;
@@ -104,6 +105,8 @@ public static function findUsedAttributes(ElementNode $el): array
104105
foreach ($el->attributes?->children as $child) {
105106
if ($child instanceof AttributeNode && $child->name instanceof TextNode) {
106107
$res[] = $child->name->content;
108+
} elseif ($child instanceof ExpressionAttributeNode) {
109+
$res[] = $child->name;
107110
}
108111
}
109112

tests/Forms.Latte3/expected/forms.button.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?php
22
%A%
3-
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */;
3+
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* %a% */;
44
Nette\Bridges\FormsLatte\Runtime::initializeForm($form);
55
echo '<form';
6-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* line %d% */;
6+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* %a% */;
77
echo '>
88
<button';
9-
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* line %d% */;
9+
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* %a% */;
1010
echo '>
1111
description of button
1212
</button>
1313
1414
<button';
15-
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* line %d% */;
15+
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* %a% */;
1616
echo '></button>
1717
1818
<button';
19-
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* line %d% */;
19+
echo ($ʟ_elem = Nette\Bridges\FormsLatte\Runtime::item('send', $this->global)->getControlPart())->attributes() /* %a% */;
2020
echo '>';
21-
echo LR\%a%::escape%a%($ʟ_elem->value) /* line %d% */;
21+
echo LR\%a%::escape%a%($ʟ_elem->value) /* %a% */;
2222
echo '</button>
2323
';
24-
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */;
24+
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* %a% */;
2525
echo '</form>
2626
';
2727
array_pop($this->global->formsStack);
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
<?php
22
%A%
3-
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */;
3+
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* %a% */;
44
Nette\Bridges\FormsLatte\Runtime::initializeForm($form);
5-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */;
5+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* %a% */;
66
echo '
77
<table>
88
<tr>
99
<th>';
10-
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getLabel()) /* line %d% */;
10+
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getLabel()) /* %a% */;
1111
echo '</th>
1212
<td>';
13-
echo Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getControl() /* line %d% */;
13+
echo Nette\Bridges\FormsLatte\Runtime::item('input1', $this->global)->getControl() /* %a% */;
1414
echo '</td>
1515
</tr>
1616
';
17-
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont1', $this->global) /* line %d% */;
17+
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont1', $this->global) /* %a% */;
1818
echo ' <tr>
1919
<th>';
20-
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getLabel()) /* line %d% */;
20+
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getLabel()) /* %a% */;
2121
echo '</th>
2222
<td>';
23-
echo Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getControl() /* line %d% */;
23+
echo Nette\Bridges\FormsLatte\Runtime::item('input2', $this->global)->getControl() /* %a% */;
2424
echo '</td>
2525
</tr>
2626
<tr>
2727
<th>';
28-
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getLabel()) /* line %d% */;
28+
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getLabel()) /* %a% */;
2929
echo '</th>
3030
<td>';
31-
echo Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getControl() /* line %d% */;
31+
echo Nette\Bridges\FormsLatte\Runtime::item('input3', $this->global)->getControl() /* %a% */;
3232
echo '</td>
3333
</tr>
3434
<tr>
3535
<th>Checkboxes</th>
3636
<td>
3737
';
38-
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont2', $this->global) /* line %d% */;
38+
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('cont2', $this->global) /* %a% */;
3939
echo ' <ol>
4040
';
41-
foreach ($formContainer->controls as $name => $field) /* line %d% */ {
41+
foreach ($formContainer->controls as $name => $field) /* %a% */ {
4242
echo ' <li>';
43-
echo Nette\Bridges\FormsLatte\Runtime::item($field, $this->global)->getControl() /* line %d% */;
43+
echo Nette\Bridges\FormsLatte\Runtime::item($field, $this->global)->getControl() /* %a% */;
4444
echo '</li>
4545
';
4646

@@ -55,27 +55,27 @@
5555
</tr>
5656
<tr>
5757
<th>';
58-
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getLabel()) /* line %d% */;
58+
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getLabel()) /* %a% */;
5959
echo '</th>
6060
<td>';
61-
echo Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getControl() /* line %d% */;
61+
echo Nette\Bridges\FormsLatte\Runtime::item('input7', $this->global)->getControl() /* %a% */;
6262
echo '</td>
6363
</tr>
6464
';
6565
array_pop($this->global->formsStack);
6666
$formContainer = end($this->global->formsStack);
6767

68-
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('items', $this->global) /* line %d% */;
68+
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item('items', $this->global) /* %a% */;
6969
echo ' <tr>
7070
<th>Items</th>
7171
<td>
7272
';
73-
$items = [1, 2, 3] /* line %d% */;
74-
foreach ($items as $item) /* line %d% */ {
75-
if (!isset($formContainer[$item])) /* line %d% */ continue;
76-
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item($item, $this->global) /* line %d% */;
73+
$items = [1, 2, 3] /* %a% */;
74+
foreach ($items as $item) /* %a% */ {
75+
if (!isset($formContainer[$item])) /* %a% */ continue;
76+
$this->global->formsStack[] = $formContainer = Nette\Bridges\FormsLatte\Runtime::item($item, $this->global) /* %a% */;
7777
echo ' ';
78-
echo Nette\Bridges\FormsLatte\Runtime::item('input', $this->global)->getControl() /* line %d% */;
78+
echo Nette\Bridges\FormsLatte\Runtime::item('input', $this->global)->getControl() /* %a% */;
7979
echo "\n";
8080
array_pop($this->global->formsStack);
8181
$formContainer = end($this->global->formsStack);
@@ -91,13 +91,13 @@
9191

9292
echo ' <tr>
9393
<th>';
94-
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getLabel()) /* line %d% */;
94+
echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getLabel()) /* %a% */;
9595
echo '</th>
9696
<td>';
97-
echo Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getControl() /* line %d% */;
97+
echo Nette\Bridges\FormsLatte\Runtime::item('input8', $this->global)->getControl() /* %a% */;
9898
echo '</td>
9999
</tr>
100100
</table>
101101
';
102-
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */;
102+
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* %a% */;
103103
%A%

tests/Forms.Latte3/expected/forms.get.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
22
%A%
3-
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */;
3+
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* %a% */;
44
Nette\Bridges\FormsLatte\Runtime::initializeForm($form);
5-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* line %d% */;
6-
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* line %d% */;
5+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, []) /* %a% */;
6+
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack)) /* %a% */;
77

88
echo '
99
1010
';
11-
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* line %d% */;
11+
$form = $this->global->formsStack[] = $this->global->uiControl['myForm'] /* %a% */;
1212
Nette\Bridges\FormsLatte\Runtime::initializeForm($form);
1313
echo '<form';
14-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* line %d% */;
14+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false) /* %a% */;
1515
echo '>
1616
';
17-
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* line %d% */;
17+
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(end($this->global->formsStack), false) /* %a% */;
1818
echo '</form>
1919
';
2020
array_pop($this->global->formsStack);

tests/Forms.Latte3/expected/forms.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@
9898
<input type="hidden" name="id" value=""></form>
9999

100100

101-
<FORM action="" method="post" class="form-class">
102-
<input type="text" name="username" class="control-class" id="frm-username">
103-
<input type="hidden" name="id" value=""></FORM>
104-
105-
106101
<select name="select" id="frm-select"><option value="m">male</option><option value="f">female</option></select>
107102

108103

0 commit comments

Comments
 (0)