Skip to content

Commit

Permalink
feature #1368 Use TwigComponent HTML syntax (smnandre)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 1.x-dev branch.

Discussion
----------

Use TwigComponent HTML syntax

 Use the new default HTML syntax

( `<twig:Alert />` instead of  `{{ component('Alert') }}` )

cc `@weaverryan`

Commits
-------

9d557b2 Use TwigComponent HTML syntax
  • Loading branch information
weaverryan committed Oct 10, 2023
2 parents ab025cd + 9d557b2 commit f154efd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
{
$command
->setDescription(self::getCommandDescription())
->addArgument('name', InputArgument::OPTIONAL, 'The name of your twig component (ie <fg=yellow>NotificationComponent</>)')
->addArgument('name', InputArgument::OPTIONAL, 'The name of your twig component (ie <fg=yellow>Notification</>)')
->addOption('live', null, InputOption::VALUE_NONE, 'Whether to create a live twig component (requires <fg=yellow>symfony/ux-live-component</>)')
;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen

$this->writeSuccessMessage($io);
$io->newLine();
$io->writeln(" To render the component, use {{ component('{$shortName}') }}.");
$io->writeln(" To render the component, use <fg=yellow><twig:{$shortName} /></>.");
$io->newLine();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/twig/Component.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent()]
#[AsTwigComponent]
final class <?= $class_name."\n" ?>
{
}
2 changes: 1 addition & 1 deletion src/Resources/skeleton/twig/LiveComponent.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent()]
#[AsLiveComponent]
final class <?= $class_name."\n" ?>
{
use DefaultActionTrait;
Expand Down
8 changes: 4 additions & 4 deletions tests/Maker/MakeTwigComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getTestDetails(): \Generator

$this->assertStringContainsString('src/Twig/Components/Alert.php', $output);
$this->assertStringContainsString('templates/components/Alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('Alert') }}.", $output);
$this->assertStringContainsString('To render the component, use <twig:Alert />.', $output);

$runner->copy(
'make-twig-component/tests/it_generates_twig_component.php',
Expand All @@ -46,7 +46,7 @@ public function getTestDetails(): \Generator

$this->assertStringContainsString('src/Twig/Components/FormInput.php', $output);
$this->assertStringContainsString('templates/components/FormInput.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('FormInput') }}.", $output);
$this->assertStringContainsString('To render the component, use <twig:FormInput />.', $output);

$runner->copy(
'make-twig-component/tests/it_generates_twig_component.php',
Expand All @@ -65,7 +65,7 @@ public function getTestDetails(): \Generator

$this->assertStringContainsString('src/Twig/Components/Alert.php', $output);
$this->assertStringContainsString('templates/components/Alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('Alert') }}.", $output);
$this->assertStringContainsString('To render the component, use <twig:Alert />.', $output);

$runner->copy(
'make-twig-component/tests/it_generates_live_component.php',
Expand All @@ -84,7 +84,7 @@ public function getTestDetails(): \Generator

$this->assertStringContainsString('src/Twig/Components/FormInput.php', $output);
$this->assertStringContainsString('templates/components/FormInput.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('FormInput') }}.", $output);
$this->assertStringContainsString('To render the component, use <twig:FormInput />.', $output);

$runner->copy(
'make-twig-component/tests/it_generates_live_component.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GeneratedTwigComponentTest extends KernelTestCase
{
public function testController()
{
$output = self::getContainer()->get('twig')->createTemplate("{{ component('{name}') }}")->render();
$output = self::getContainer()->get('twig')->createTemplate("<twig:{name} />")->render();

$this->assertStringContainsString('<div data-controller="live"', $output);
$this->assertStringContainsString('data-live-name-value="', $output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GeneratedTwigComponentTest extends KernelTestCase
{
public function testController()
{
$output = self::getContainer()->get('twig')->createTemplate("{{ component('{name}') }}")->render();
$output = self::getContainer()->get('twig')->createTemplate("<twig:{name} />")->render();

$this->assertSame("<div>\n <!-- component html -->\n</div>\n", $output);
}
Expand Down

0 comments on commit f154efd

Please sign in to comment.