You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
Many popular gems (RSpec, Kaminari) provide their own
configure
hook for setting these values. This would be far more expected syntax: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:
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 bareApplicationComponent
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.The text was updated successfully, but these errors were encountered: