-
-
Notifications
You must be signed in to change notification settings - Fork 422
[RFC] Allow to override the skeleton files? #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
👍 adding logic to the skeleton template (like conditional code and blocks) look good to me and solve ideas like described by @weaverryan here #22 (comment) |
I disagree with adding Twig as a dependency. I don't want API-only projects to end up with a And I also don't think that our templates should be overridable - and opinion that I'm sure won't make me very popular with some people :). Making a generation command is very easy, and you can even extend from our |
@weaverryan so if I need add for example add to top
I need copy of exist command with change only skeleton? If I don't need change logic or add new variables, I think is violates the principle DRY, isn't it? So I think I need have some solution when we need change only template. |
I agree with Ryan ... but I'd also love to find a simple solution to help solve the needs of developers like @eugenekurasov. |
<?php declare(strict_types = 1);
.... For now, yes. We have a tricky balance to strike: if we make the bundle very extendible, then we need to be much more careful when adding/changing features so we don't break those extensions. By saying "create your own custom commands", the bundle can stay innovative. We learned this lesson with SensioGeneratorBundle. Of course, if you want to make your own command, we should make it as easy as possible. Right now, it's pretty easy, since we have the |
So problem only with BC, if it is so this is another problem. I don't give solution for this issue now, but you can see how trying resolved same issue in doctrineMigrationsBundle - they give option for override they skeleton. I think you can found other solution. |
Could be #50 enough to solve the issue? |
--- after a bit of thought, I'd like to recommend,
|
As with the proposed php bin/console make:crud Foobar --origin=src/Resources/Maker Pro:
Con:
The last con would probably require us to define which variables are available inside the templates. |
Hello,
Then use this variable '$customSkeletonDir' when calling templates: $generator->generateController( $controllerClassDetails->getFullName(), $customSkeletonDir.'crud/controller/Controller.tpl.php', ... and lines ~199: foreach ($templates as $template => $variables) { $generator->generateTemplate( customSkeletonDir.$templatesPath.'/'.$template.'.html.twig', $customSkeletonDir.'crud/templates/'.$template.'.tpl.php', $variables ); } I've tested for "*.tpl.php" templates, and it work like a charm ! |
Perfect! Two small changes:
This is really a handy solution! Thank you for this. |
I'm a bit late, but I think this is/was a perfect use case for Twig. I think that https://github.com/symfony/maker-bundle/pull/520/files should be held off. No offense meant @weaverryan, we just disagree, but I don't see how having a Twig is a templating language, nothing more, and code to be generated belongs in templates. In fact, all of the code that's generated already lives in templates, it's just that they are in PHP templates which loses the awesome behavior that Twig allows. Going further, the maker bundle is for generating code in my application. I don't see why overriding templates or generation code should be made difficult for the developer. Sure, I can make my own makers/generators, but why force that on me if overriding templates can be done easier? [EDIT AGAIN] - I also didn't see the Feature tag... wow, I really should've read this more before I wrote anything. Apologies! For an example, my current case is that I want to remove the commented out examples in generated Repositories like the one below. Even if it's easy to create my own maker command, I don't think I should be forced to do that for something as simple as this. I also don't think that changing the directory of the PHP templates is the answer as in #520. I think we should definitely still consider Twig's use case here. Another good example of something where I shouldn't have to create a whole command is if I want to just add PHPDoc blocks. It's trivial to just add them after the fact, but I'd love if I could just override a Twig template/block instead.
|
What would be the benefits of using Twig as a dependency? MUbedaSJ's proposal seems to me to be a good compromise, which gives everyone the possibility to override default templates, without having to create a new command, and also allows to use, or not, Twig in the custom templates. |
that's exactly what i did in my PR |
@MrYamous, @MagnusDot. Oops, responded with another account. Responding with correct one. Remember that I'm late to this RFC and to this bundle, but it was still open so I felt like adding my thoughts. I haven't reviewed all of the maker code yet, but I'll expand on my thoughts.
So far, it looks like your PR is changing the crud maker to allow it to read from a directory relative to your current working directory. I don't know if that's the right approach. My CWD is not always relative to the project, meaning I have to cd into a certain directory for that command to load a template from a certain directory, and it's only for the crud maker at the moment.
The bundle doesn't seem extensible in the way I need. How would I change the template for the repository that's created from the Writing my own command simply to change minor template content seems like overkill. And perhaps I can override the generator services themselves but that definitely seems like overkill. I know that changing the template directories is a possibility discussed and coded a bit in the PR, but we're still just left with PHP templates that would need to be copied completely, the PHP templates in maker bundle do not have the power of Twig templates.
The code is generated from templates that already have conditions, there are use cases for inheritance of these templates when people just want to override certain parts or the whole template, and twig is a templating language built for things like that. I don't see the harm in adding dependencies that are used for their intended purpose. I definitely appreciate the challenges, but it seems as though there's hesitancy to Twig for whatever reason and I'm curious why. Although these are templates for maker-generated coded, they are still just templates with conditions where inheritance would be beneficial for minor tweaks. These are perfect use cases for Twig (twig can be used for many template needs, web, email, others) and I don't think it makes anything more complicated. Perhaps there's a bit of dev to do in maker bundle to add Twig, but it's not that much work, and I think the flexibility it would provide users/clients is worth it. |
Anyway, for the developers that disagree with the decision to distrust their ability to write their own templates, enjoy the following ridiculous workaround which exploits the brilliant code that we're not allowed to override: $controllerPath = $generator->generateController(
$controllerClassNameDetails->getFullName(),
'../../../../../../src/Maker/skeleton/controller/MyController.tpl.php',
[
'use_statements' => $controllerUseStatements,
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
]
); (Along with creating |
We didn't agree on this ... so let's close as "won't fix" ... and for those needing it, they can use the "hack" shown in the previous comment. Thanks. |
When creating this bundle we decided to not require Twig to keep things simple. That means that our skeleton files can't have complex logic and we need to interpolate the placeholder variables ourselves. Not a big deal ... but not using Twig and not defining skeleton files as Twig templates has another problem...
... you can't easily override the skeleton files in your project (see #32 and lots of related issues in the SensioGeneratorBundle). Should we...
... add Twig as dependency and turn skeletons into templates?
... try to make the skeleton files overridable using the kernel file locator ?
... not support this feature explicitly?
The text was updated successfully, but these errors were encountered: