-
Notifications
You must be signed in to change notification settings - Fork 409
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
Project-wide config for generators #623
Comments
@Spone fantastic! I'm 👍🏻 to going this route. I'll have to give the Stimulus bit some more thought, but in the meantime let's definitely add these options for all of the existing generator options. |
For this same reason, we ended up writing our own generators in all apps we introduced components into. The generators included a custom ERB, sidecar CSS, JS, and translations, in one case the preview was changed to use ERB templates instead of the class, on another the JS was a custom controller class for AlpineJS. Not sure what's the best way to facilitate all of this. Maybe just suggesting users to generate their generator is enough, or explaining how to override generator templates, or a way to add/replace templates in the current generator. |
It makes sense to recommend using a custom generator tailored for each project, instead of adding more configuration flags (by the way it's also @palkan's approach in view_component-contrib). It's the most sensible approach to cater all needs without adding complexity to ViewComponent. But I also think that each flag available in the standard generator provided by ViewComponent should at least be available as a global configuration setting as well. It makes it easier to get started with the gem, then you can go further and write your own generator (ViewComponent could provide a easy path to do that). |
In preparation for v3 (#617) Let's sum up the progress on this. Here are the relevant PRs:
Thanks again to everyone who contributed :) The syntax is currently: config.view_component.generate.preview = true
config.view_component.generate.sidecar = true Do you think we should aim for the more conventional syntax described above? config.generators do |g|
g.view_component preview: true, sidecar: true # this would always create a preview and a sidecar directory
end If we do, it would be great to ship it in v3 to minimize disruption. |
The This feels like a similar discussion to where the config option landed in rails/rails#42279 — in that, we chose to isolate the config option to the most common thread (the ERB template handler) even though the user's perception of what this would affect differed (Action View). |
I have a few counter-examples:
I agree with this argument, even if in pratice, they are most of the time colocated in |
Seems like the pattern with those examples is to toggle whether or not to run related generators (e.g. with hooks). Running on that basis, If I could choose between either I'd personally lean towards configuring alongside the rest of |
There is also the argument that the |
Closing now that the last PR (#1194) is merged! Feel free to reopen if you want to continue the above discussion about config syntax. |
@boardfish have you used the I just tried in the config.view_component.generate.sidecar = true and start the server, you get:
|
Can confirm this is an issue. I've found the fix and I'll put a PR in now. |
Feature request
Currently, you have to pass the flags every time you run a generator. Being able to override the default values in
config/application.rb
would be useful.Here is the suggested syntax, that would follow Rails convention:
Another example:
There already is a way to configure the template engine (see below) so we wouldn't change that.
Such global config option could obviously be overridden when running the generator, by using flags as usual.
Motivation
In some cases, it makes sense to use generator flags every time you generate components (such as
--sidecar
), but you can easily forget.Related:
Reference
Existing generator flags
By the way, the
--inline
flag appears to be only taken into account by the ERB generator, it should be added to Slim and Haml as well. I opened a separate issue for that: #625Also, what about a
--stimulus
flag to generate the Stimulus controller? I opened another separate issue: #627Existing configuration settings
Here is a quick recap of the current configuration settings in ViewComponent.
The
generators.template_engine
option from Rails is taken into account.Apart from that, most of the ViewComponent-specific settings are for now related to previews.
The text was updated successfully, but these errors were encountered: