Skip to content

Commit e330342

Browse files
committed
Mark deprecation in docs, rebuild docs
1 parent d3b708d commit e330342

File tree

5 files changed

+83
-19
lines changed

5 files changed

+83
-19
lines changed

docs/api.md

+62-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ nav_order: 3
1414

1515
Returns the current config.
1616

17+
### `.identifier`[String]
18+
19+
The file path of the component Ruby file.
20+
1721
### `.sidecar_files(extensions)`
1822

1923
Find sidecar files for the given extensions.
@@ -23,7 +27,7 @@ strings starting without the dot, example: `["erb", "haml"]`.
2327

2428
For example, one might collect sidecar CSS files that need to be compiled.
2529

26-
### `.strip_trailing_whitespace(value = true)`
30+
### `.strip_trailing_whitespace(value = true)` (Deprecated)
2731

2832
Strips trailing whitespace from templates before compiling them.
2933

@@ -33,11 +37,20 @@ class MyComponent < ViewComponent::Base
3337
end
3438
```
3539

40+
_Use the new component-local configuration option instead.
41+
```ruby
42+
class MyComponent < ViewComponent::Base
43+
configure_component do |config|
44+
config.strip_trailing_whitespace = true
45+
end
46+
end
47+
```_
48+
3649
### `.strip_trailing_whitespace?` → [Boolean]
3750
3851
Whether trailing whitespace will be stripped before compilation.
3952
40-
### `.with_collection(collection, **args)`
53+
### `.with_collection(collection, spacer_component: nil, **args)`
4154
4255
Render a component for each element in a collection ([documentation](/guide/collections)):
4356
@@ -78,14 +91,14 @@ that inhibits encapsulation & reuse, often making testing difficult.
7891
A proxy through which to access helpers. Use sparingly as doing so introduces
7992
coupling that inhibits encapsulation & reuse, often making testing difficult.
8093

81-
### `#output_preamble`[String]
82-
83-
Optional content to be returned before the rendered template.
84-
8594
### `#output_postamble`[String]
8695

8796
Optional content to be returned after the rendered template.
8897

98+
### `#output_preamble`[String]
99+
100+
Optional content to be returned before the rendered template.
101+
89102
### `#render?`[Boolean]
90103

91104
Override to determine whether the ViewComponent should render.
@@ -191,6 +204,12 @@ Always generate a Stimulus controller alongside the component:
191204

192205
config.view_component.generate.stimulus_controller = true
193206

207+
#### `#typescript`
208+
209+
Generate TypeScript files instead of JavaScript files:
210+
211+
config.view_component.generate.typescript = true
212+
194213
#### `#locale`
195214

196215
Always generate translations file alongside the component:
@@ -223,6 +242,19 @@ Defaults to `""`. If this is blank, the generator will use
223242
`ViewComponent.config.preview_paths` if defined,
224243
`"test/components/previews"` otherwise
225244

245+
#### `#use_component_path_for_rspec_tests`
246+
247+
Whether to use the `config.view_component_path` when generating new
248+
RSpec component tests:
249+
250+
config.view_component.generate.use_component_path_for_rspec_tests = true
251+
252+
When set to `true`, the generator will use the `view_component_path` to
253+
decide where to generate the new RSpec component test.
254+
For example, if the `view_component_path` is
255+
`app/views/components`, then the generator will create a new spec file
256+
in `spec/views/components/` rather than the default `spec/components/`.
257+
226258
### `.instrumentation_enabled`
227259

228260
Whether ActiveSupport notifications are enabled.
@@ -325,6 +357,15 @@ In RSpec, `Preview` is appended to `described_class`.
325357

326358
Returns the result of a render_inline call.
327359

360+
### `#rendered_json`
361+
362+
`JSON.parse`-d component output.
363+
364+
```ruby
365+
render_inline(MyJsonComponent.new)
366+
assert_equal(rendered_json["hello"], "world")
367+
```
368+
328369
### `#vc_test_controller`[ActionController::Base]
329370

330371
Access the controller used by `render_inline`:
@@ -343,7 +384,7 @@ Access the request used by `render_inline`:
343384

344385
```ruby
345386
test "component does not render in Firefox" do
346-
vc_test_request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
387+
request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
347388
render_inline(NoFirefoxComponent.new)
348389
refute_component_rendered
349390
end
@@ -360,7 +401,17 @@ with_controller_class(UsersController) do
360401
end
361402
```
362403

363-
### `#with_request_url(full_path, host: nil, method: nil)`
404+
### `#with_format(format)`
405+
406+
Set format of the current request
407+
408+
```ruby
409+
with_format(:json) do
410+
render_inline(MyComponent.new)
411+
end
412+
```
413+
414+
### `#with_request_url(full_path, host: nil, method: nil, format: ViewComponent::Base::VC_INTERNAL_DEFAULT_FORMAT)`
364415

365416
Set the URL of the current request (such as when using request-dependent path helpers):
366417

@@ -418,7 +469,7 @@ To fix this issue, either use the `content` accessor directly or choose a differ
418469

419470
### `ControllerCalledBeforeRenderError`
420471

421-
`#controller` can't be used during initialization, as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
472+
`#controller` can't be used before rendering, as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
422473

423474
It's sometimes possible to fix this issue by moving code dependent on `#controller` to a [`#before_render` method](https://viewcomponent.org/api.html#before_render--void).
424475

@@ -444,7 +495,7 @@ See [the collections docs](https://viewcomponent.org/guide/collections.html) for
444495

445496
### `HelpersCalledBeforeRenderError`
446497

447-
`#helpers` can't be used during initialization as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
498+
`#helpers` can't be used before rendering as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
448499

449500
It's sometimes possible to fix this issue by moving code dependent on `#helpers` to a [`#before_render` method](https://viewcomponent.org/api.html#before_render--void).
450501

@@ -528,7 +579,7 @@ ViewComponent SystemTest controller must only be called in a test environment fo
528579

529580
### `TranslateCalledBeforeRenderError`
530581

531-
`#translate` can't be used during initialization as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
582+
`#translate` can't be used before rendering as it depends on the view context that only exists once a ViewComponent is passed to the Rails render pipeline.
532583

533584
It's sometimes possible to fix this issue by moving code dependent on `#translate` to a [`#before_render` method](https://viewcomponent.org/api.html#before_render--void).
534585

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

+9
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ def with_collection_parameter(parameter)
609609
# end
610610
# ```
611611
#
612+
# @deprecated Use the new component-local configuration option instead.
613+
# ```ruby
614+
# class MyComponent < ViewComponent::Base
615+
# configure_component do |config|
616+
# config.strip_trailing_whitespace = true
617+
# end
618+
# end
619+
# ```
620+
#
612621
# @param value [Boolean] Whether to strip newlines.
613622
def strip_trailing_whitespace(value = true)
614623
ViewComponent::Deprecation.deprecation_warning(

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)