diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index bd07bb660..b2068accb 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 266902db6..16a6ea65e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/composer.json b/composer.json index 9ae31e55f..a0130b8f9 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,13 @@ "nette/application": "^3.0", "nette/di": "^3.0", "nette/tester": "^2.0", - "latte/latte": "^2.10.2", + "latte/latte": "^2.10.2 || ^3.0", "tracy/tracy": "^2.4", "phpstan/phpstan-nette": "^0.12" }, "conflict": { "nette/di": "<3.0-stable", - "latte/latte": ">=3.0" + "latte/latte": ">=3.1" }, "autoload": { "classmap": ["src/"] diff --git a/examples/latte.php b/examples/latte.php index 32bc421d4..3995b8441 100644 --- a/examples/latte.php +++ b/examples/latte.php @@ -39,8 +39,6 @@ } $latte = new Latte\Engine; -$latte->onCompile[] = function ($latte) { - Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler()); -}; +$latte->addExtension(new Nette\Bridges\FormsLatte\FormsExtension); $latte->render(__DIR__ . '/latte/page.latte', ['form' => $form]); diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index b411d5bc8..f2d7fbdb7 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -17,7 +17,7 @@ /** - * Latte macros for Nette\Forms. + * Latte v2 macros for Nette\Forms. * * - {form name} ... {/form} * - {input name} diff --git a/src/Bridges/FormsLatte/FormsExtension.php b/src/Bridges/FormsLatte/FormsExtension.php new file mode 100644 index 000000000..71fd693d1 --- /dev/null +++ b/src/Bridges/FormsLatte/FormsExtension.php @@ -0,0 +1,34 @@ + [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'], + ]; + } +} diff --git a/src/Bridges/FormsLatte/Nodes/FormContainerNode.php b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php new file mode 100644 index 000000000..18eed8aac --- /dev/null +++ b/src/Bridges/FormsLatte/Nodes/FormContainerNode.php @@ -0,0 +1,64 @@ + */ + 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; + } +} diff --git a/src/Bridges/FormsLatte/Nodes/FormNode.php b/src/Bridges/FormsLatte/Nodes/FormNode.php new file mode 100644 index 000000000..c2902d78d --- /dev/null +++ b/src/Bridges/FormsLatte/Nodes/FormNode.php @@ -0,0 +1,92 @@ + */ + public static function create(Tag $tag): \Generator + { + if ($tag->isNAttribute()) { + throw new CompileException('Did you mean