Skip to content

Commit 5c92a63

Browse files
committed
Latte: added more comments /* line */
1 parent 770c8d1 commit 5c92a63

6 files changed

Lines changed: 111 additions & 103 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"nette/application": "^3.0",
2525
"nette/di": "^3.0",
2626
"nette/tester": "^2.0",
27-
"latte/latte": "^2.9.2",
27+
"latte/latte": "^2.10.2",
2828
"tracy/tracy": "^2.4",
2929
"phpstan/phpstan-nette": "^0.12"
3030
},

src/Bridges/FormsLatte/FormMacros.php

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public function macroForm(MacroNode $node, PhpWriter $writer)
6363
$node->replaced = true;
6464
$node->tokenizer->reset();
6565
return $writer->write(
66-
"/* line $node->startLine */\n"
67-
. 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $this->global->formsStack[] = '
66+
'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $this->global->formsStack[] = '
6867
. ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '')
69-
. '$this->global->uiControl[%node.word], %node.array);'
68+
. '$this->global->uiControl[%node.word], %node.array)'
69+
. " /* line $node->startLine */;"
7070
);
7171
}
7272

@@ -90,7 +90,8 @@ public function macroFormContext(MacroNode $node, PhpWriter $writer)
9090
return $writer->write(
9191
'$form = $this->global->formsStack[] = '
9292
. ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '')
93-
. '$this->global->uiControl[%node.word];'
93+
. '$this->global->uiControl[%node.word]'
94+
. " /* line $node->startLine */;"
9495
);
9596
}
9697

@@ -110,8 +111,9 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer)
110111
$node->tokenizer->reset();
111112
return $writer->write(
112113
'$this->global->formsStack[] = $formContainer = '
113-
. ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '')
114-
. 'end($this->global->formsStack)[%node.word];'
114+
. ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '')
115+
. 'end($this->global->formsStack)[%node.word]'
116+
. " /* line $node->startLine */;"
115117
);
116118
}
117119

@@ -131,9 +133,12 @@ public function macroLabel(MacroNode $node, PhpWriter $writer)
131133
$node->replaced = true;
132134
$name = array_shift($words);
133135
return $writer->write(
134-
($name[0] === '$' ? '$ʟ_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; if ($ʟ_label = $ʟ_input' : 'if ($ʟ_label = end($this->global->formsStack)[%0.word]')
135-
. '->%1.raw) echo $ʟ_label'
136-
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
136+
($name[0] === '$'
137+
? '$ʟ_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; if ($ʟ_label = $ʟ_input'
138+
: 'if ($ʟ_label = end($this->global->formsStack)[%0.word]'
139+
)
140+
. '->%1.raw) echo $ʟ_label'
141+
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : ''),
137142
$name,
138143
$words ? ('getLabelPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')') : 'getLabel()'
139144
);
@@ -168,9 +173,9 @@ public function macroInput(MacroNode $node, PhpWriter $writer)
168173
$name = array_shift($words);
169174
return $writer->write(
170175
($name[0] === '$' ? '$ʟ_input = $_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo $ʟ_input' : 'echo end($this->global->formsStack)[%0.word]')
171-
. '->%1.raw'
172-
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : '')
173-
. " /* line $node->startLine */",
176+
. '->%1.raw'
177+
. ($node->tokenizer->isNext() ? '->addAttributes(%node.array)' : '')
178+
. " /* line $node->startLine */;",
174179
$name,
175180
$words ? 'getControlPart(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')' : 'getControl()'
176181
);
@@ -199,7 +204,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
199204
$node->openingCode = $writer->write(
200205
'<?php $form = $this->global->formsStack[] = '
201206
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
202-
. '$this->global->uiControl[%0.word]; ?>',
207+
. "\$this->global->uiControl[%0.word] /* line $node->startLine */; ?>",
203208
$name
204209
);
205210
return $writer->write(
@@ -210,8 +215,9 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
210215
$method = $tagName === 'label' ? 'getLabel' : 'getControl';
211216
return $writer->write(
212217
'$ʟ_input = $_input = ' . ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
213-
. 'end($this->global->formsStack)[%0.word]; echo $ʟ_input->%1.raw'
214-
. ($definedHtmlAttributes ? '->addAttributes(%2.var)' : '') . '->attributes()',
218+
. 'end($this->global->formsStack)[%0.word]; echo $ʟ_input->%1.raw'
219+
. ($definedHtmlAttributes ? '->addAttributes(%2.var)' : '') . '->attributes()'
220+
. " /* line $node->startLine */;",
215221
$name,
216222
$method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')',
217223
array_fill_keys($definedHtmlAttributes, null)
@@ -234,17 +240,18 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
234240
{
235241
$tagName = strtolower($node->htmlNode->name);
236242
if ($tagName === 'form') {
237-
$node->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false); ?>';
243+
$node->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false)'
244+
. " /* line $node->startLine */; ?>";
238245
} elseif ($tagName === 'label') {
239246
if ($node->htmlNode->empty) {
240-
$node->innerContent = '<?php echo $ʟ_input->getLabelPart()->getHtml() ?>';
247+
$node->innerContent = "<?php echo \$ʟ_input->getLabelPart()->getHtml() /* line $node->startLine */; ?>";
241248
}
242249
} elseif ($tagName === 'button') {
243250
if ($node->htmlNode->empty) {
244-
$node->innerContent = '<?php echo htmlspecialchars($ʟ_input->getCaption()) ?>';
251+
$node->innerContent = "<?php echo htmlspecialchars(\$ʟ_input->getCaption()) /* line $node->startLine */; ?>";
245252
}
246253
} else { // select, textarea
247-
$node->innerContent = '<?php echo $ʟ_input->getControl()->getHtml() ?>';
254+
$node->innerContent = "<?php echo \$ʟ_input->getControl()->getHtml() /* line $node->startLine */; ?>";
248255
}
249256
}
250257

@@ -260,11 +267,15 @@ public function macroInputError(MacroNode $node, PhpWriter $writer)
260267
$name = $node->tokenizer->fetchWord();
261268
$node->replaced = true;
262269
if (!$name) {
263-
return $writer->write('echo %escape($ʟ_input->getError());');
270+
return $writer->write("echo %escape(\$ʟ_input->getError()) /* line $node->startLine */;");
264271
} elseif ($name[0] === '$') {
265-
return $writer->write('$ʟ_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo %escape($ʟ_input->getError());', $name);
272+
return $writer->write(
273+
'$ʟ_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word];'
274+
. "echo %escape(\$ʟ_input->getError()) /* line $node->startLine */;",
275+
$name
276+
);
266277
} else {
267-
return $writer->write('echo %escape(end($this->global->formsStack)[%0.word]->getError());', $name);
278+
return $writer->write("echo %escape(end(\$this->global->formsStack)[%0.word]->getError()) /* line $node->startLine */;", $name);
268279
}
269280
}
270281

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<?php
22
%A%
3-
$form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
3+
$form = $this->global->formsStack[] = $this->global->uiControl["myForm"] /* line 1 */;
44
echo '<form';
55
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), [], false);
66
echo '>
77
<button';
88
$ʟ_input = $_input = end($this->global->formsStack)["send"];
9-
echo $ʟ_input->getControlPart()->attributes();
9+
echo $ʟ_input->getControlPart()->attributes() /* line 2 */;
1010
echo '>
1111
description of button
1212
</button>
1313
1414
<button';
1515
$ʟ_input = $_input = end($this->global->formsStack)["send"];
16-
echo $ʟ_input->getControlPart()->attributes();
16+
echo $ʟ_input->getControlPart()->attributes() /* line 6 */;
1717
echo '></button>
1818
1919
<button';
2020
$ʟ_input = $_input = end($this->global->formsStack)["send"];
21-
echo $ʟ_input->getControlPart()->attributes();
21+
echo $ʟ_input->getControlPart()->attributes() /* line 8 */;
2222
echo '>';
23-
echo htmlspecialchars($ʟ_input->getCaption());
23+
echo htmlspecialchars($ʟ_input->getCaption()) /* line 8 */;
2424
echo '</button>
2525
';
26-
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false);
26+
echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) /* line 1 */;
2727
echo '</form>
2828
';
2929
%A%

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
%A%
3-
/* line 1 */
4-
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $this->global->formsStack[] = $this->global->uiControl["myForm"], []);
3+
echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $this->global->formsStack[] = $this->global->uiControl["myForm"], []) /* line 1 */;
54
echo '
65
<table>
76
<tr>
@@ -13,7 +12,7 @@
1312
echo '</td>
1413
</tr>
1514
';
16-
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["cont1"];
15+
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["cont1"] /* line 7 */;
1716
echo ' <tr>
1817
<th>';
1918
if ($ʟ_label = end($this->global->formsStack)["input2"]->getLabel()) echo $ʟ_label;
@@ -34,11 +33,11 @@
3433
<th>Checkboxes</th>
3534
<td>
3635
';
37-
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["cont2"];
36+
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["cont2"] /* line 19 */;
3837
echo ' <ol>
3938
';
4039
$iterations = 0;
41-
foreach ($formContainer->controls AS $name => $field) {
40+
foreach ($formContainer->controls AS $name => $field) /* line 19 */ {
4241
echo ' <li>';
4342
$ʟ_input = $_input = is_object($field) ? $field : end($this->global->formsStack)[$field];
4443
echo $ʟ_input->getControl() /* line 20 */;
@@ -63,16 +62,16 @@
6362
';
6463
array_pop($this->global->formsStack);
6564
$formContainer = end($this->global->formsStack);
66-
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["items"];
65+
$this->global->formsStack[] = $formContainer = end($this->global->formsStack)["items"] /* line 29 */;
6766
echo ' <tr>
6867
<th>Items</th>
6968
<td>
7069
';
71-
$items = array(1, 2, 3);
70+
$items = array(1, 2, 3) /* line 33 */;
7271
$iterations = 0;
73-
foreach ($items as $item) {
74-
if (!isset($formContainer[$item])) continue;
75-
$this->global->formsStack[] = $formContainer = is_object($item) ? $item : end($this->global->formsStack)[$item];
72+
foreach ($items as $item) /* line 34 */ {
73+
if (!isset($formContainer[$item])) /* line 35 */ continue;
74+
$this->global->formsStack[] = $formContainer = is_object($item) ? $item : end($this->global->formsStack)[$item] /* line 36 */;
7675
echo ' ';
7776
echo end($this->global->formsStack)["input"]->getControl() /* line 37 */;
7877
echo "\n";

0 commit comments

Comments
 (0)