Skip to content

Commit c7cf9a7

Browse files
committed
🗿 Rock-conaissance, also break config
The existing `ViewComponent::Config` object seems fit for purpose when it comes to component-local config, but I think what we want is: - a `RailsAppConfig` object that's responsible for the things that will still need to be set against `Rails.application.config` - a `ComponentLocalConfig` object that's effectively `ViewComponent::Config`. We should make sure that config is inheritable, and perhaps provide some kind of DSL to set it up, e.g.: ```rb class ApplicationComponent < ViewComponent::Base configure do some_option true some_other_option "value" end end ```
1 parent 37e89f8 commit c7cf9a7

File tree

8 files changed

+189
-220
lines changed

8 files changed

+189
-220
lines changed

lib/rails/generators/component/component_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ComponentGenerator < Rails::Generators::NamedBase
1313
check_class_collision suffix: "Component"
1414

1515
class_option :inline, type: :boolean, default: false
16+
# TODO: Settings in this file should be Rails app-local config.
1617
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
1718
class_option :parent, type: :string, desc: "The parent class for the generated component"
1819
class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview

lib/rails/generators/locale/component_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ComponentGenerator < ::Rails::Generators::NamedBase
1212
class_option :sidecar, type: :boolean, default: false
1313

1414
def create_locale_file
15+
# TODO: This should be app-local config
1516
if ViewComponent::Base.config.generate.distinct_locale_files
1617
I18n.available_locales.each do |locale|
1718
create_file destination(locale), translations_hash([locale]).to_yaml

lib/rails/generators/rspec/component_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def create_test_file
1616
private
1717

1818
def spec_component_path
19+
# TODO: This is probably Rails app-local config too.
1920
return "spec/components" unless ViewComponent::Base.config.generate.use_component_path_for_rspec_tests
2021

2122
configured_component_path = component_path

lib/view_component/base.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "action_view"
4-
require "active_support/configurable"
54
require "view_component/collection"
65
require "view_component/compile_cache"
76
require "view_component/compiler"
@@ -19,17 +18,6 @@
1918

2019
module ViewComponent
2120
class Base < ActionView::Base
22-
class << self
23-
delegate(*ViewComponent::Config.defaults.keys, to: :config)
24-
25-
# Returns the current config.
26-
#
27-
# @return [ActiveSupport::OrderedOptions]
28-
def config
29-
ViewComponent::Config.current
30-
end
31-
end
32-
3321
include ViewComponent::InlineTemplate
3422
include ViewComponent::UseHelpers
3523
include ViewComponent::Slotable
@@ -542,6 +530,7 @@ def render_template_for(requested_details)
542530
child.identifier = caller_locations(1, 10).reject { |l| l.base_label == "inherited" }[0].path
543531

544532
# If Rails application is loaded, removes the first part of the path and the extension.
533+
# FIXME: This seems like it'll be inflexible to configuration right now.
545534
if defined?(Rails) && Rails.application
546535
child.virtual_path = child.identifier.gsub(
547536
/(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""

0 commit comments

Comments
 (0)