-
-
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.
- Loading branch information
Showing
51 changed files
with
1,683 additions
and
27 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
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,34 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Nette Framework (https://nette.org) | ||
* Copyright (c) 2004 David Grudl (https://davidgrudl.com) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nette\Bridges\FormsLatte; | ||
|
||
use Latte; | ||
|
||
|
||
/** | ||
* Latte v3 extension for Nette Forms. | ||
*/ | ||
final class FormsExtension extends Latte\Extension | ||
{ | ||
public function getTags(): array | ||
{ | ||
return [ | ||
'form' => [Nodes\FormNode::class, 'create'], | ||
'formContext' => [Nodes\FormNode::class, 'create'], | ||
'formContainer' => [Nodes\FormContainerNode::class, 'create'], | ||
'label' => [Nodes\LabelNode::class, 'create'], | ||
'input' => [Nodes\InputNode::class, 'create'], | ||
'inputError' => [Nodes\InputErrorNode::class, 'create'], | ||
'formPrint' => [Nodes\FormPrintNode::class, 'create'], | ||
'formClassPrint' => [Nodes\FormPrintNode::class, 'create'], | ||
'n:name' => [Nodes\NNameNode::class, 'create'], | ||
]; | ||
} | ||
} |
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,64 @@ | ||
<?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\Compiler\Nodes\AreaNode; | ||
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; | ||
|
||
|
||
/** | ||
* {formContainer ...} | ||
*/ | ||
class FormContainerNode extends StatementNode | ||
{ | ||
public ExpressionNode $name; | ||
public AreaNode $content; | ||
|
||
|
||
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */ | ||
public static function create(Tag $tag): \Generator | ||
{ | ||
$tag->outputMode = $tag::OutputRemoveIndentation; | ||
$tag->expectArguments(); | ||
|
||
$node = new static; | ||
$node->name = $tag->parser->parseUnquotedStringOrExpression(); | ||
[$node->content] = yield; | ||
return $node; | ||
} | ||
|
||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format( | ||
'$this->global->formsStack[] = $formContainer = ' | ||
. ($this->name instanceof StringNode | ||
? 'end($this->global->formsStack)[%node]' | ||
: 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp]') | ||
. ' %line; %node ' | ||
. 'array_pop($this->global->formsStack); $formContainer = end($this->global->formsStack);' | ||
. "\n\n", | ||
$this->name, | ||
$this->position, | ||
$this->content, | ||
); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->name; | ||
yield $this->content; | ||
} | ||
} |
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,92 @@ | ||
<?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\CompileException; | ||
use Latte\Compiler\Nodes\AreaNode; | ||
use Latte\Compiler\Nodes\Php\Expression\ArrayNode; | ||
use Latte\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\Scalar\StringNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\Position; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
|
||
/** | ||
* {form name} ... {/form} | ||
* {formContext ...} | ||
*/ | ||
class FormNode extends StatementNode | ||
{ | ||
public ExpressionNode $name; | ||
public ArrayNode $attributes; | ||
public AreaNode $content; | ||
public bool $print; | ||
public ?Position $endLine; | ||
|
||
|
||
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static|AreaNode> */ | ||
public static function create(Tag $tag): \Generator | ||
{ | ||
if ($tag->isNAttribute()) { | ||
throw new CompileException('Did you mean <form n:name=...> ?', $tag->position); | ||
} | ||
|
||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
$tag->expectArguments(); | ||
$node = new static; | ||
$node->name = $tag->parser->parseUnquotedStringOrExpression(); | ||
$tag->parser->stream->tryConsume(','); | ||
$node->attributes = $tag->parser->parseArguments(); | ||
$node->print = $tag->name === 'form'; | ||
|
||
[$node->content, $endTag] = yield; | ||
$node->endLine = $endTag?->position; | ||
if ($endTag && $node->name instanceof StringNode) { | ||
$endTag->parser->stream->tryConsume($node->name->value); | ||
} | ||
|
||
return $node; | ||
} | ||
|
||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format( | ||
'$form = $this->global->formsStack[] = ' | ||
. ($this->name instanceof StringNode | ||
? '$this->global->uiControl[%node]' | ||
: 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]') | ||
. ' %line;' | ||
. ($this->print | ||
? 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin($form, %node) %1.line;' | ||
: '') | ||
. ' %3.node ' | ||
. ($this->print | ||
? 'echo Nette\Bridges\FormsLatte\Runtime::renderFormEnd(array_pop($this->global->formsStack))' | ||
: 'array_pop($this->global->formsStack)') | ||
. " %4.line;\n\n", | ||
$this->name, | ||
$this->position, | ||
$this->attributes, | ||
$this->content, | ||
$this->endLine, | ||
); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->name; | ||
yield $this->attributes; | ||
yield $this->content; | ||
} | ||
} |
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,63 @@ | ||
<?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\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\Scalar\StringNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
|
||
/** | ||
* {formPrint [ClassName]} | ||
* {formClassPrint [ClassName]} | ||
*/ | ||
class FormPrintNode extends StatementNode | ||
{ | ||
public ?ExpressionNode $name; | ||
public string $mode; | ||
|
||
|
||
public static function create(Tag $tag): static | ||
{ | ||
$node = new static; | ||
$node->name = $tag->parser->isEnd() | ||
? null | ||
: $tag->parser->parseUnquotedStringOrExpression(); | ||
$node->mode = $tag->name; | ||
return $node; | ||
} | ||
|
||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format( | ||
'Nette\Bridges\FormsLatte\Runtime::render%raw(' | ||
. match (true) { | ||
!$this->name => 'end($this->global->formsStack)', | ||
$this->name instanceof StringNode => '$this->global->uiControl[%node]', | ||
default => 'is_object($ʟ_tmp = %node) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp]', | ||
} | ||
. ') %line; exit;', | ||
$this->mode, | ||
$this->name, | ||
$this->position, | ||
); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
if ($this->name) { | ||
yield $this->name; | ||
} | ||
} | ||
} |
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,67 @@ | ||
<?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\Compiler\Nodes\Php\ExpressionNode; | ||
use Latte\Compiler\Nodes\Php\Scalar\StringNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
|
||
/** | ||
* {inputError ...} | ||
*/ | ||
class InputErrorNode extends StatementNode | ||
{ | ||
public ?ExpressionNode $name; | ||
|
||
|
||
public static function create(Tag $tag): static | ||
{ | ||
$tag->outputMode = $tag::OutputKeepIndentation; | ||
$node = new static; | ||
$node->name = $tag->parser->isEnd() | ||
? null | ||
: $tag->parser->parseUnquotedStringOrExpression(); | ||
return $node; | ||
} | ||
|
||
|
||
public function print(PrintContext $context): string | ||
{ | ||
if (!$this->name) { | ||
return $context->format('echo %escape($ʟ_input->getError()) %line;', $this->position); | ||
|
||
} elseif ($this->name instanceof StringNode) { | ||
return $context->format( | ||
'echo %escape(end($this->global->formsStack)[%node]->getError()) %line;', | ||
$this->name, | ||
$this->position, | ||
); | ||
|
||
} else { | ||
return $context->format( | ||
'$ʟ_input = is_object($ʟ_tmp = %node) ? $ʟ_tmp : end($this->global->formsStack)[$ʟ_tmp];' | ||
. 'echo %escape($ʟ_input->getError()) %line;', | ||
$this->name, | ||
$this->position, | ||
); | ||
} | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
if ($this->name) { | ||
yield $this->name; | ||
} | ||
} | ||
} |
Oops, something went wrong.