Skip to content
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

Allow users to override scaffold generator templates #314

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Jan 7, 2024

Originally reported at #164

I think this PR is preferable to #247 because it has tests and is a simpler fix.

Note that in order to test this, the test suite now uses the same temporary directory for all tests, so we are then able to set Rails::Generators.templates_path before the generator classes are instantiated.

cc @dixpac

@flavorjones flavorjones requested a review from dhh January 7, 2024 22:44
@flavorjones flavorjones force-pushed the 164-flavorjones-override-erb-templates branch from b527209 to fd7e0c4 Compare January 8, 2024 02:30
@dixpac
Copy link
Contributor

dixpac commented Jan 8, 2024

Works great with scaffolds.
However, it doesn't work with controllers(bin/rails g controller Home index) or mailers(bin/rails g mailer User notify). I'm not certain how frequently people would need to override those, but in those cases, it is not working.

@flavorjones
Copy link
Member Author

@dixpac Yeah, I was hoping nobody would care about overriding those. 😆 😭

You're right, while I'm here I might as well add mailer and controller. Thanks for the review!

and set Rails::Generators.templates_path to include it before the
generator classes are instantiated so that the local 'lib/templates'
directory is part of the generators' `source_paths`.

Also see railties/lib/rails/generators/base.rb and
`Rails::Generators::Base.inherited`
Note that developers can override by placing templates in either:

- lib/templates/tailwindcss/{scaffold,mailer,controller}
- lib/templates/erb/{scaffold,mailer,controller}
@flavorjones flavorjones force-pushed the 164-flavorjones-override-erb-templates branch from fd7e0c4 to 85c2c4a Compare January 8, 2024 21:42
Copy link
Contributor

@dixpac dixpac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 😍

@flavorjones flavorjones merged commit c14c681 into main Jan 10, 2024
23 checks passed
@flavorjones flavorjones deleted the 164-flavorjones-override-erb-templates branch January 10, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants