Skip to content

Commit

Permalink
bug #1569 Fix generated twig file location
Browse files Browse the repository at this point in the history
  • Loading branch information
IndraGunawan authored Jun 5, 2024
1 parent d4fa901 commit 10459ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -66,7 +65,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'Twig\\Components',
);

$shortName = Str::getShortClassName($factory->getShortName());
$templatePath = str_replace('\\', '/', $factory->getRelativeNameWithoutSuffix());
$shortName = str_replace('\\', ':', $factory->getRelativeNameWithoutSuffix());

$generator->generateClass(
$factory->getFullName(),
Expand All @@ -76,7 +76,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
]
);
$generator->generateTemplate(
"components/{$shortName}.html.twig",
"components/{$templatePath}.html.twig",
sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, 'component_template.tpl.php')
);

Expand Down
18 changes: 18 additions & 0 deletions tests/Maker/MakeTwigComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ public function getTestDetails(): \Generator
$runner->runTests();
}),
];

yield 'it_generates_live_component_on_subdirectory' => [$this->createMakerTest()
->addExtraDependencies('symfony/ux-live-component', 'symfony/twig-bundle')
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker(['Form\Input', 'y']);

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

$runner->copy(
'make-twig-component/tests/it_generates_live_component.php',
'tests/GeneratedLiveComponentTest.php'
);
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'Form:Input');
$runner->runTests();
}),
];
}

protected function getMakerClass(): string
Expand Down

0 comments on commit 10459ae

Please sign in to comment.