Skip to content

Commit c4ad6b2

Browse files
committed
Mark deprecation in docs, rebuild docs
1 parent 4a023aa commit c4ad6b2

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

docs/guide/templates.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,18 @@ 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` class method.
184+
To strip trailing whitespace from component templates, use the `strip_trailing_whitespace` component-local config option.
185185

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

191193
# don't strip whitespace
192-
strip_trailing_whitespace(false)
194+
configure_component do |config|
195+
config.strip_trailing_whitespace = false
196+
end
193197
end
194198
```

lib/view_component/base.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -611,21 +611,29 @@ def with_collection_parameter(parameter)
611611
# end
612612
# ```
613613
#
614+
# @deprecated Use the new component-local configuration option instead.
615+
#
616+
# ```ruby
617+
# class MyComponent < ViewComponent::Base
618+
# configure_component do |config|
619+
# config.strip_trailing_whitespace = true
620+
# end
621+
# end
622+
# ```
623+
#
614624
# @param value [Boolean] Whether to strip newlines.
615625
def strip_trailing_whitespace(value = true)
616626
ViewComponent::Deprecation.deprecation_warning(
617627
"strip_trailing_whitespace",
618-
%(
628+
<<~DOC
619629
Use the new component-local configuration option instead:
620630
621-
```rb
622631
class #{self.class.name} < ViewComponent::Base
623632
configure_view_component do |config|
624633
config.strip_trailing_whitespace = #{value}
625634
end
626635
end
627-
```
628-
)
636+
DOC
629637
)
630638
view_component_config.strip_trailing_whitespace = value
631639
end

lib/view_component/docs_builder_component.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ nav_order: 3
1212
## <%= section.heading %>
1313

1414
<% section.methods.each do |method| %>
15-
### <%== render ViewComponent::DocsBuilderComponent::MethodDoc.new(method, section.show_types) %>
15+
### <%= render ViewComponent::DocsBuilderComponent::MethodDoc.new(method, section.show_types) %>
1616

1717
<% end %>
1818
<% section.error_klasses.each do |error_klass| %>
19-
### <%== render ViewComponent::DocsBuilderComponent::ErrorKlassDoc.new(error_klass, section.show_types) %>
19+
### <%= render ViewComponent::DocsBuilderComponent::ErrorKlassDoc.new(error_klass, section.show_types) %>
2020

2121
<% end %>
2222
<% end %>

lib/view_component/docs_builder_component.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def error_message
2424
end
2525

2626
def call
27-
<<~DOCS.chomp
27+
<<~DOCS.chomp.html_safe
2828
`#{klass_name}`
2929
3030
#{error_message}
@@ -67,15 +67,15 @@ def deprecation_text
6767
end
6868

6969
def docstring_and_deprecation_text
70-
<<~DOCS.strip
70+
<<~DOCS.strip.html_safe
7171
#{docstring}
7272
7373
#{"_#{deprecation_text}_" if deprecated?}
7474
DOCS
7575
end
7676

7777
def call
78-
<<~DOCS.chomp
78+
<<~DOCS.chomp.html_safe
7979
`#{separator}#{signature_or_name}`#{types}#{suffix}
8080
8181
#{docstring_and_deprecation_text}

0 commit comments

Comments
 (0)