Skip to content

Commit e346071

Browse files
authored
Revert "Migrate strip_trailing_whitespace to use component-local config und…" (#2313)
This reverts commit a8ae59a.
1 parent f400c2d commit e346071

File tree

6 files changed

+9
-112
lines changed

6 files changed

+9
-112
lines changed

docs/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ nav_order: 6
1010

1111
## main
1212

13-
* Introduce component-local config and migrate `strip_trailing_whitespace` to use it under the hood.
14-
15-
*Simon Fish*
16-
1713
* Add docs about Slack channel in Ruby Central workspace. (Join us! #oss-view-component). Email [email protected] for an invite.
1814

1915
*Joel Hawksley

docs/guide/templates.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,14 @@ end
181181

182182
Code editors commonly add a trailing newline character to source files in keeping with the Unix standard. Including trailing whitespace in component templates can result in unwanted whitespace in the HTML, eg. if the component is rendered before the period at the end of a sentence.
183183

184-
To strip trailing whitespace from component templates, use the `strip_trailing_whitespace` component-local config option.
184+
To strip trailing whitespace from component templates, use the `strip_trailing_whitespace` class method.
185185

186186
```ruby
187187
class MyComponent < ViewComponent::Base
188188
# do strip whitespace
189-
configure_view_component do |config|
190-
config.strip_trailing_whitespace = true
191-
end
189+
strip_trailing_whitespace
192190

193191
# don't strip whitespace
194-
configure_view_component do |config|
195-
config.strip_trailing_whitespace = false
196-
end
192+
strip_trailing_whitespace(false)
197193
end
198194
```

lib/view_component/base.rb

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require "view_component/collection"
66
require "view_component/compile_cache"
77
require "view_component/compiler"
8-
require "view_component/component_local_config"
98
require "view_component/config"
109
require "view_component/errors"
1110
require "view_component/inline_template"
@@ -40,7 +39,6 @@ def config
4039
include ViewComponent::Slotable
4140
include ViewComponent::Translatable
4241
include ViewComponent::WithContentHelper
43-
include ViewComponent::ComponentLocalConfig
4442

4543
RESERVED_PARAMETER = :content
4644
VC_INTERNAL_DEFAULT_FORMAT = :html
@@ -51,6 +49,10 @@ def config
5149
# For Content Security Policy nonces
5250
delegate :content_security_policy_nonce, to: :helpers
5351

52+
# Config option that strips trailing whitespace in templates before compiling them.
53+
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false
54+
self.__vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
55+
5456
attr_accessor :__vc_original_view_context
5557

5658
# Components render in their own view context. Helpers and other functionality
@@ -612,38 +614,16 @@ def with_collection_parameter(parameter)
612614
# end
613615
# ```
614616
#
615-
# @deprecated Use the new component-local configuration option instead.
616-
#
617-
# ```ruby
618-
# class MyComponent < ViewComponent::Base
619-
# configure_view_component do |config|
620-
# config.strip_trailing_whitespace = true
621-
# end
622-
# end
623-
# ```
624-
#
625617
# @param value [Boolean] Whether to strip newlines.
626618
def strip_trailing_whitespace(value = true)
627-
ViewComponent::Deprecation.deprecation_warning(
628-
"strip_trailing_whitespace",
629-
<<~DOC
630-
Use the new component-local configuration option instead:
631-
632-
class #{self.class.name} < ViewComponent::Base
633-
configure_view_component do |config|
634-
config.strip_trailing_whitespace = #{value}
635-
end
636-
end
637-
DOC
638-
)
639-
view_component_config.strip_trailing_whitespace = value
619+
self.__vc_strip_trailing_whitespace = value
640620
end
641621

642622
# Whether trailing whitespace will be stripped before compilation.
643623
#
644624
# @return [Boolean]
645625
def strip_trailing_whitespace?
646-
view_component_config.strip_trailing_whitespace
626+
__vc_strip_trailing_whitespace
647627
end
648628

649629
# Ensure the component initializer accepts the

lib/view_component/component_local_config.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.

test/sandbox/app/components/configurable_component.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/sandbox/test/base_test.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,4 @@ def test_uses_module_configuration
197197
assert_equal "AnotherController", TestAlreadyConfigurableModule::SomeComponent.test_controller
198198
assert_equal "AnotherController", TestAlreadyConfiguredModule::SomeComponent.test_controller
199199
end
200-
201-
def test_component_local_config_is_inheritable
202-
assert_equal false, ViewComponent::Base.view_component_config.strip_trailing_whitespace
203-
# This component doesn't call configure, so it should inherit the defaults.
204-
assert_equal false, AnotherComponent.view_component_config.strip_trailing_whitespace
205-
# This component overrides the defaults.
206-
assert_equal true, ConfigurableComponent.view_component_config.strip_trailing_whitespace
207-
end
208200
end

0 commit comments

Comments
 (0)