Skip to content

Commit

Permalink
minor #1606 move templates to root template dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow authored Sep 28, 2024
1 parent 673c3a5 commit 6e1ed41
Show file tree
Hide file tree
Showing 69 changed files with 32 additions and 5 deletions.
33 changes: 30 additions & 3 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function generateClass(string $className, string $templateName, array $va
*
* @internal
*
* @param string $templateName Template name in Resources/skeleton to use
* @param string $templateName Template name in the templates/ dir to use
* @param array $variables Array of variables to pass to the template
* @param bool $isController Set to true if generating a Controller that needs
* access to the TemplateComponentGenerator ("generator") in
Expand Down Expand Up @@ -299,10 +299,14 @@ private function addOperation(string $targetPath, string $templateName, array $v

$templatePath = $templateName;
if (!file_exists($templatePath)) {
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;
$templatePath = \sprintf('%s/templates/%s', \dirname(__DIR__), $templateName);

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
$templatePath = $this->getTemplateFromLegacySkeletonPath($templateName);
}

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s" in the templates/ dir.', $templateName));
}
}

Expand All @@ -311,4 +315,27 @@ private function addOperation(string $targetPath, string $templateName, array $v
'variables' => $variables,
];
}

/**
* @legacy - Remove when public generate methods become "internal" to MakerBundle in v2
*/
private function getTemplateFromLegacySkeletonPath(string $templateName): string
{
$templatePath = $templateName;
if (!file_exists($templatePath)) {
$templatePath = __DIR__.'/Resources/skeleton/'.$templateName;

if (!file_exists($templatePath)) {
throw new \Exception(\sprintf('Cannot find template "%s"', $templateName));
}
}

@trigger_deprecation(
'symfony/maker-bundle',
'1.62.0',
'Storing templates in src/Resources/skeleton is deprecated. Store MakerBundle templates in the "~/templates/" dir instead.',
);

return $templatePath;
}
}
4 changes: 2 additions & 2 deletions src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen

$generator->generateClass(
$factory->getFullName(),
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
[
'live' => $live,
]
);
$generator->generateTemplate(
"components/{$templatePath}.html.twig",
\sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, 'component_template.tpl.php')
\sprintf('%s/templates/twig/%s', \dirname(__DIR__, 2), 'component_template.tpl.php')
);

$generator->writeChanges();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6e1ed41

Please sign in to comment.