File tree 4 files changed +16
-16
lines changed
4 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -618,21 +618,21 @@ def strip_trailing_whitespace(value = true)
618
618
619
619
```rb
620
620
class #{ self . class . name } < ViewComponent::Base
621
- configure do |config|
621
+ configure_view_component do |config|
622
622
config.strip_trailing_whitespace = #{ value }
623
623
end
624
624
end
625
625
```
626
626
)
627
627
)
628
- configuration . strip_trailing_whitespace = value
628
+ view_component_config . strip_trailing_whitespace = value
629
629
end
630
630
631
631
# Whether trailing whitespace will be stripped before compilation.
632
632
#
633
633
# @return [Boolean]
634
634
def strip_trailing_whitespace?
635
- configuration . strip_trailing_whitespace
635
+ view_component_config . strip_trailing_whitespace
636
636
end
637
637
638
638
# Ensure the component initializer accepts the
Original file line number Diff line number Diff line change @@ -28,32 +28,32 @@ def inheritable_copy
28
28
29
29
included do
30
30
# :nocov:
31
- def configuration
32
- @_configuration ||= self . class . configuration . inheritable_copy
31
+ def view_component_config
32
+ @__vc_config ||= self . class . view_component_config . inheritable_copy
33
33
end
34
34
35
35
private
36
36
37
37
def inherited ( child )
38
- child . instance_variable_set ( :@_configuration , nil )
38
+ child . instance_variable_set ( :@__vc_config , nil )
39
39
super
40
40
end
41
41
# :nocov:
42
42
end
43
43
44
44
class_methods do
45
- def configuration
46
- @_configuration ||= if respond_to? ( :superclass ) && superclass . respond_to? ( :configuration )
47
- superclass . configuration . inheritable_copy
45
+ def view_component_config
46
+ @__vc_config ||= if respond_to? ( :superclass ) && superclass . respond_to? ( :view_component_config )
47
+ superclass . view_component_config . inheritable_copy
48
48
else
49
49
# create a new "anonymous" class that will host the compiled reader methods
50
50
ViewComponent ::ComponentLocalConfig ::Configuration . new
51
51
end
52
52
end
53
53
54
- def configure ( &block )
55
- configuration . instance_eval ( &block )
56
- configuration . compile_methods!
54
+ def configure_component ( &block )
55
+ view_component_config . instance_eval ( &block )
56
+ view_component_config . compile_methods!
57
57
end
58
58
end
59
59
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
class ConfigurableComponent < ViewComponent ::Base
4
- configure do |config |
4
+ configure_component do |config |
5
5
config . strip_trailing_whitespace = true
6
6
end
7
7
end
Original file line number Diff line number Diff line change @@ -199,10 +199,10 @@ def test_uses_module_configuration
199
199
end
200
200
201
201
def test_component_local_config_is_inheritable
202
- assert_equal false , ViewComponent ::Base . configuration . strip_trailing_whitespace
202
+ assert_equal false , ViewComponent ::Base . view_component_config . strip_trailing_whitespace
203
203
# This component doesn't call configure, so it should inherit the defaults.
204
- assert_equal false , AnotherComponent . configuration . strip_trailing_whitespace
204
+ assert_equal false , AnotherComponent . view_component_config . strip_trailing_whitespace
205
205
# This component overrides the defaults.
206
- assert_equal true , ConfigurableComponent . configuration . strip_trailing_whitespace
206
+ assert_equal true , ConfigurableComponent . view_component_config . strip_trailing_whitespace
207
207
end
208
208
end
You can’t perform that action at this time.
0 commit comments