-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Latte: NNameNode split to two classes
- Loading branch information
Showing
3 changed files
with
89 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Latte (https://latte.nette.org) | ||
* Copyright (c) 2008 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nette\Bridges\FormsLatte\Nodes; | ||
|
||
use Latte; | ||
use Latte\Compiler\Nodes\AreaNode; | ||
use Latte\Compiler\Nodes\AuxiliaryNode; | ||
use Latte\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\Scalar\StringNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
|
||
/** | ||
* <form n:name> | ||
*/ | ||
final class FormNNameNode extends StatementNode | ||
{ | ||
public ExpressionNode $name; | ||
public AreaNode $content; | ||
|
||
|
||
public static function create(Tag $tag): \Generator | ||
{ | ||
$tag->expectArguments(); | ||
$node = new static; | ||
$node->name = $tag->parser->parseUnquotedStringOrExpression(colon: false); | ||
[$node->content] = yield; | ||
$node->init($tag); | ||
return $node; | ||
} | ||
|
||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $this->content->print($context); | ||
} | ||
|
||
|
||
private function init(Tag $tag) | ||
{ | ||
$el = $tag->htmlElement; | ||
|
||
$tag->replaceNAttribute(new AuxiliaryNode(fn(PrintContext $context) => $context->format( | ||
'$form = $this->global->formsStack[] = ' | ||
. ($this->name instanceof StringNode | ||
? '$this->global->uiControl[%node]' | ||
: 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') | ||
. ' %line;' | ||
. 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %dump, false) %line;', | ||
$this->name, | ||
$this->position, | ||
array_fill_keys(FieldNNameNode::findUsedAttributes($el), null), | ||
$this->position, | ||
))); | ||
|
||
$el->content = new Latte\Compiler\Nodes\FragmentNode([ | ||
$el->content, | ||
new AuxiliaryNode(fn(PrintContext $context) => $context->format( | ||
'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack), false) %line;', | ||
$this->position, | ||
)), | ||
]); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->name; | ||
yield $this->content; | ||
} | ||
} |