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

Better configuration scaffolding #2188

Open
armchairdj opened this issue Dec 22, 2024 · 0 comments
Open

Better configuration scaffolding #2188

armchairdj opened this issue Dec 22, 2024 · 0 comments

Comments

@armchairdj
Copy link

armchairdj commented Dec 22, 2024

Feature request

Current the ViewComponent website has zero documentation about how to set configuration options. The available configuration keys are documented, but there isn't even a nod to how to set up an initializer.

Trial and error taught me that I have to configure this gem as if I'm configuring Rails itself:

# config/initializers/view_component.rb
Rails.application.configure do
  config.view_component.component_parent_class = "ApplicationComponent"
end

Many popular gems (RSpec, Kaminari) provide their ownconfigure hook for setting these values. This would be far more expected syntax:

# config/initializers/view_component.rb
ViewComponent.configure do
  config.component_parent_class = "ApplicationComponent"
end

It would be even cooler if there were a generator for creating a view_component initializer and if it came with a giant commented-out list of all available configurations, with examples. Again, this would bring ViewComponent inline w/ many popular Rails libraries.

Finally: The docs state:

It’s common practice to create and inherit from an ApplicationComponent that’s a subclass of ViewComponent::Base.

If that's the case, why not detect that such a file exists and automatically configure the generator to use it as a base class when present?

If an initializer generator were created, perhaps it could be something like rails g view_component:install and it could generate a bare ApplicationComponent alongside an initializer.

Motivation

As I prepared to create my second or third ViewComponent, I realized I didn't want to have to type --parent ApplicationComponent every single time I used the generator. So I sought to use provided configuration option and spent 15 minutes googling "ViewComponent initializer", reading the source code and generally looking for any information about how to actually set one of these configuration options — to no avail.

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

No branches or pull requests

1 participant