11# frozen_string_literal: true
22
33require "action_view"
4- require "active_support/configurable"
54require "view_component/collection"
65require "view_component/compile_cache"
76require "view_component/compiler"
@@ -45,6 +44,8 @@ def config
4544 class_attribute :__vc_strip_trailing_whitespace , instance_accessor : false , instance_predicate : false
4645 self . __vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
4746
47+ delegate :component_config , to : :class
48+
4849 attr_accessor :__vc_original_view_context
4950
5051 # Components render in their own view context. Helpers and other functionality
@@ -231,7 +232,7 @@ def controller
231232 # @return [ActionView::Base]
232233 def helpers
233234 raise HelpersCalledBeforeRenderError if view_context . nil?
234- raise StrictHelperError unless ViewComponent :: Base . config . helpers_enabled
235+ raise StrictHelperError unless GlobalConfig . helpers_enabled
235236 # Attempt to re-use the original view_context passed to the first
236237 # component rendered in the rendering pipeline. This prevents the
237238 # instantiation of a new view_context via `controller.view_context` which
@@ -248,7 +249,7 @@ def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToM
248249 super
249250 rescue => e # rubocop:disable Style/RescueStandardError
250251 e . set_backtrace e . backtrace . tap ( &:shift )
251- if !ViewComponent :: Base . config . helpers_enabled
252+ if !GlobalConfig . helpers_enabled
252253 raise e , <<~MESSAGE . chomp if view_context && e . is_a? ( NameError ) && ( __vc_original_view_context . respond_to? ( method_name ) || controller . view_context . respond_to? ( method_name ) )
253254 #{ e . message }
254255
@@ -519,15 +520,13 @@ def inherited(child)
519520 # `compile` defines
520521 compile
521522
522- child . include ActiveSupport ::Configurable
523-
524523 if child . superclass == ViewComponent ::Base
525- child . define_singleton_method ( :config ) do
526- @@config ||= Rails . application . config . view_component . inheritable_copy
524+ child . define_singleton_method ( :component_config ) do
525+ @@component_config ||= Rails . application . config . view_component . inheritable_copy
527526 end
528527 else
529- child . define_singleton_method ( :config ) do
530- @@config ||= superclass . config . inheritable_copy
528+ child . define_singleton_method ( :component_config ) do
529+ @@component_config ||= superclass . component_config . inheritable_copy
531530 end
532531 end
533532
@@ -563,7 +562,7 @@ def render_template_for(variant = nil, format = nil)
563562 # If Rails application is loaded, removes the first part of the path and the extension.
564563 if defined? ( Rails ) && Rails . application
565564 child . virtual_path = child . source_location . gsub (
566- /(.*#{ Regexp . quote ( ViewComponent :: Base . config . view_component_path ) } )|(\. rb)/ , ""
565+ /(.*#{ Regexp . quote ( GlobalConfig . view_component_path ) } )|(\. rb)/ , ""
567566 )
568567 end
569568
0 commit comments