Skip to content

Commit 6ffc509

Browse files
committed
Migrate strip_trailing_whitespace to component-local-config
1 parent 58ffa74 commit 6ffc509

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/view_component/base.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ def config
4646
# For Content Security Policy nonces
4747
delegate :content_security_policy_nonce, to: :helpers
4848

49-
# Config option that strips trailing whitespace in templates before compiling them.
50-
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false
51-
self.__vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
52-
5349
attr_accessor :__vc_original_view_context
5450

5551
# Components render in their own view context. Helpers and other functionality
@@ -611,14 +607,28 @@ def with_collection_parameter(parameter)
611607
#
612608
# @param value [Boolean] Whether to strip newlines.
613609
def strip_trailing_whitespace(value = true)
614-
self.__vc_strip_trailing_whitespace = value
610+
ViewComponent::Deprecation.deprecation_warning(
611+
"strip_trailing_whitespace",
612+
%(
613+
Use the new component-local configuration option instead:
614+
615+
```rb
616+
class #{self.class.name} < ViewComponent::Base
617+
configure do |config|
618+
config.strip_trailing_whitespace = #{value}
619+
end
620+
end
621+
```
622+
)
623+
)
624+
configuration.strip_trailing_whitespace = value
615625
end
616626

617627
# Whether trailing whitespace will be stripped before compilation.
618628
#
619629
# @return [Boolean]
620630
def strip_trailing_whitespace?
621-
__vc_strip_trailing_whitespace
631+
configuration.strip_trailing_whitespace
622632
end
623633

624634
# Ensure the component initializer accepts the

lib/view_component/component_local_config.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module ViewComponent
44
module ComponentLocalConfig
55
class Configuration
66
def initialize
7-
@config = ActiveSupport::OrderedOptions[]
7+
@config = ActiveSupport::OrderedOptions[
8+
strip_trailing_whitespace: false
9+
]
810
end
911

1012
delegate_missing_to :@config
@@ -45,4 +47,4 @@ def configure(&block)
4547
end
4648
end
4749
end
48-
end
50+
end

0 commit comments

Comments
 (0)