9
9
10
10
use Nette ;
11
11
use Latte ;
12
+ use Latte \Helpers ;
12
13
use Latte \MacroNode ;
13
14
use Latte \PhpWriter ;
14
15
use Latte \CompileException ;
@@ -49,21 +50,22 @@ public static function install(Latte\Compiler $compiler)
49
50
public function macroForm (MacroNode $ node , PhpWriter $ writer )
50
51
{
51
52
if ($ node ->modifiers ) {
52
- throw new CompileException (" Modifiers are not allowed in { { $ node-> name } } " );
53
+ throw new CompileException (' Modifiers are not allowed in ' . Helpers:: formatNotation ( $ node) );
53
54
}
54
55
if ($ node ->prefix ) {
55
56
throw new CompileException ('Did you mean <form n:name=...> ? ' );
56
57
}
57
58
$ name = $ node ->tokenizer ->fetchWord ();
58
59
if ($ name === FALSE ) {
59
- throw new CompileException (" Missing form name in { { $ node-> name } }. " );
60
+ throw new CompileException (' Missing form name in ' . Helpers:: formatNotation ( $ node) );
60
61
}
61
62
$ node ->replaced = true ;
62
63
$ node ->tokenizer ->reset ();
63
64
return $ writer ->write (
64
- 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
65
+ "/* line $ node ->startLine */ \n"
66
+ . 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form = $_form = $this->global->formsStack[] = '
65
67
. ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
66
- . '$this->global->uiControl[%node.word], %node.array) '
68
+ . '$this->global->uiControl[%node.word], %node.array); '
67
69
);
68
70
}
69
71
@@ -74,17 +76,17 @@ public function macroForm(MacroNode $node, PhpWriter $writer)
74
76
public function macroFormContainer (MacroNode $ node , PhpWriter $ writer )
75
77
{
76
78
if ($ node ->modifiers ) {
77
- throw new CompileException (" Modifiers are not allowed in { { $ node-> name } } " );
79
+ throw new CompileException (' Modifiers are not allowed in ' . Helpers:: formatNotation ( $ node) );
78
80
}
79
81
$ name = $ node ->tokenizer ->fetchWord ();
80
82
if ($ name === FALSE ) {
81
- throw new CompileException (" Missing name in { { $ node-> name } }. " );
83
+ throw new CompileException (' Missing name in ' . Helpers:: formatNotation ( $ node) );
82
84
}
83
85
$ node ->tokenizer ->reset ();
84
86
return $ writer ->write (
85
87
'$this->global->formsStack[] = $formContainer = $_form = '
86
88
. ($ name [0 ] === '$ ' ? 'is_object(%node.word) ? %node.word : ' : '' )
87
- . 'end($this->global->formsStack)[%node.word] '
89
+ . 'end($this->global->formsStack)[%node.word]; '
88
90
);
89
91
}
90
92
@@ -95,11 +97,11 @@ public function macroFormContainer(MacroNode $node, PhpWriter $writer)
95
97
public function macroLabel (MacroNode $ node , PhpWriter $ writer )
96
98
{
97
99
if ($ node ->modifiers ) {
98
- throw new CompileException (" Modifiers are not allowed in { { $ node-> name } } " );
100
+ throw new CompileException (' Modifiers are not allowed in ' . Helpers:: formatNotation ( $ node) );
99
101
}
100
102
$ words = $ node ->tokenizer ->fetchWords ();
101
103
if (!$ words ) {
102
- throw new CompileException (" Missing name in { { $ node-> name } }. " );
104
+ throw new CompileException (' Missing name in ' . Helpers:: formatNotation ( $ node) );
103
105
}
104
106
$ node ->replaced = true ;
105
107
$ name = array_shift ($ words );
@@ -131,18 +133,19 @@ public function macroLabelEnd(MacroNode $node, PhpWriter $writer)
131
133
public function macroInput (MacroNode $ node , PhpWriter $ writer )
132
134
{
133
135
if ($ node ->modifiers ) {
134
- throw new CompileException (" Modifiers are not allowed in { { $ node-> name } } " );
136
+ throw new CompileException (' Modifiers are not allowed in ' . Helpers:: formatNotation ( $ node) );
135
137
}
136
138
$ words = $ node ->tokenizer ->fetchWords ();
137
139
if (!$ words ) {
138
- throw new CompileException (" Missing name in { { $ node-> name } }. " );
140
+ throw new CompileException (' Missing name in ' . Helpers:: formatNotation ( $ node) );
139
141
}
140
142
$ node ->replaced = true ;
141
143
$ name = array_shift ($ words );
142
144
return $ writer ->write (
143
145
($ name [0 ] === '$ ' ? '$_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo $_input ' : 'echo end($this->global->formsStack)[%0.word] ' )
144
146
. '->%1.raw '
145
- . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' ),
147
+ . ($ node ->tokenizer ->isNext () ? '->addAttributes(%node.array) ' : '' )
148
+ . " /* line $ node ->startLine */ " ,
146
149
$ name ,
147
150
$ words ? 'getControlPart( ' . implode (', ' , array_map ([$ writer , 'formatWord ' ], $ words )) . ') ' : 'getControl() '
148
151
);
@@ -156,11 +159,11 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)
156
159
{
157
160
$ words = $ node ->tokenizer ->fetchWords ();
158
161
if (!$ words ) {
159
- throw new CompileException (" Missing name in n: { $ node-> name } . " );
162
+ throw new CompileException (' Missing name in ' . Helpers:: formatNotation ( $ node) );
160
163
}
161
164
$ name = array_shift ($ words );
162
165
$ tagName = strtolower ($ node ->htmlNode ->name );
163
- $ node ->isEmpty = $ tagName === 'input ' ;
166
+ $ node ->empty = $ tagName === 'input ' ;
164
167
165
168
if ($ tagName === 'form ' ) {
166
169
return $ writer ->write (
@@ -198,13 +201,13 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
198
201
{
199
202
$ tagName = strtolower ($ node ->htmlNode ->name );
200
203
if ($ tagName === 'form ' ) {
201
- $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), FALSE) ?> ' ;
204
+ $ node ->innerContent .= '<?php echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), FALSE); ?> ' ;
202
205
} elseif ($ tagName === 'label ' ) {
203
- if ($ node ->htmlNode ->isEmpty ) {
206
+ if ($ node ->htmlNode ->empty ) {
204
207
$ node ->innerContent = "<?php echo \$_input->getLabelPart()->getHtml() ?> " ;
205
208
}
206
209
} elseif ($ tagName === 'button ' ) {
207
- if ($ node ->htmlNode ->isEmpty ) {
210
+ if ($ node ->htmlNode ->empty ) {
208
211
$ node ->innerContent = '<?php echo htmlspecialchars($_input->caption) ?> ' ;
209
212
}
210
213
} else { // select, textarea
@@ -219,16 +222,16 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
219
222
public function macroInputError (MacroNode $ node , PhpWriter $ writer )
220
223
{
221
224
if ($ node ->modifiers ) {
222
- throw new CompileException (" Modifiers are not allowed in { { $ node-> name } } " );
225
+ throw new CompileException (' Modifiers are not allowed in ' . Helpers:: formatNotation ( $ node) );
223
226
}
224
227
$ name = $ node ->tokenizer ->fetchWord ();
225
228
$ node ->replaced = true ;
226
229
if (!$ name ) {
227
- return $ writer ->write ('echo %escape($_input->getError()) ' );
230
+ return $ writer ->write ('echo %escape($_input->getError()); ' );
228
231
} elseif ($ name [0 ] === '$ ' ) {
229
- return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo %escape($_input->getError()) ' , $ name );
232
+ return $ writer ->write ('$_input = is_object(%0.word) ? %0.word : end($this->global->formsStack)[%0.word]; echo %escape($_input->getError()); ' , $ name );
230
233
} else {
231
- return $ writer ->write ('echo %escape(end($this->global->formsStack)[%0.word]->getError()) ' , $ name );
234
+ return $ writer ->write ('echo %escape(end($this->global->formsStack)[%0.word]->getError()); ' , $ name );
232
235
}
233
236
}
234
237
0 commit comments