Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

## Class methods

### `.after_compile`

Hook called by the compiler after a component is compiled.

Extensions can override this class method to run logic after
compilation (e.g., generate helpers, register metadata, etc.).

Check failure on line 18 in docs/api.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Microsoft.Foreign] Use 'for example' instead of 'e.g.,'. Raw Output: {"message": "[Microsoft.Foreign] Use 'for example' instead of 'e.g.,'.", "location": {"path": "docs/api.md", "range": {"start": {"line": 18, "column": 14}}}, "severity": "ERROR"}

By default, this is a no-op.

### `.config` → [ActiveSupport::OrderedOptions]

Returns the current config.
Expand All @@ -18,11 +27,6 @@

The file path of the component Ruby file.

### `.new(...)`

Redefine `new` so we can pre-allocate instance variables to optimize
for Ruby object shapes.

### `.sidecar_files(extensions)`

Find sidecar files for the given extensions.
Expand Down Expand Up @@ -64,6 +68,11 @@

## Instance methods

### `#around_render` → [void]

Called around rendering the component. Override to wrap the rendering of a
component in custom instrumentation, etc.

### `#before_render` → [void]

Called before rendering the component. Override to perform operations that
Expand All @@ -86,11 +95,21 @@

Returns the value of attribute current_template.

### `#format`

Rails expects us to define `format` on all renderables,
but we do not know the `format` of a ViewComponent until runtime.

Check failure on line 101 in docs/api.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Microsoft.Contractions] Use 'don't' instead of 'do not'. Raw Output: {"message": "[Microsoft.Contractions] Use 'don't' instead of 'do not'.", "location": {"path": "docs/api.md", "range": {"start": {"line": 101, "column": 8}}}, "severity": "ERROR"}

### `#helpers` → [ActionView::Base]

A proxy through which to access helpers. Use sparingly as doing so introduces
coupling that inhibits encapsulation & reuse, often making testing difficult.

### `#initialize` → [Base]

Including `Rails.application.routes.url_helpers` defines an initializer that accepts (...),

Check failure on line 110 in docs/api.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [proselint.Typography] Consider using the '…' symbol instead of '...'. Raw Output: {"message": "[proselint.Typography] Consider using the '…' symbol instead of '...'.", "location": {"path": "docs/api.md", "range": {"start": {"line": 110, "column": 87}}}, "severity": "ERROR"}

Check warning on line 110 in docs/api.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Microsoft.Ellipses] In general, don't use an ellipsis. Raw Output: {"message": "[Microsoft.Ellipses] In general, don't use an ellipsis.", "location": {"path": "docs/api.md", "range": {"start": {"line": 110, "column": 87}}}, "severity": "WARNING"}
so we have to define our own empty initializer to overwrite it.

Check failure on line 111 in docs/api.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Microsoft.Contractions] Use 'we've' instead of 'we have'. Raw Output: {"message": "[Microsoft.Contractions] Use 'we've' instead of 'we have'.", "location": {"path": "docs/api.md", "range": {"start": {"line": 111, "column": 4}}}, "severity": "ERROR"}

### `#output_postamble` → [String]

Optional content to be returned after the rendered template.
Expand All @@ -103,7 +122,7 @@

Override to determine whether the ViewComponent should render.

### `#render_in(view_context, &block)` → [String]
### `#render_in(view_context, **, &block)` → [String]

Entrypoint for rendering components.

Expand Down Expand Up @@ -311,13 +330,6 @@
assert_text("Hello, World!")
```

Note: `#rendered_preview` expects a preview to be defined with the same class
name as the calling test, but with `Test` replaced with `Preview`:

MyComponentTest -> MyComponentPreview etc.

In RSpec, `Preview` is appended to `described_class`.

### `#rendered_content` → [ActionView::OutputBuffer]

Returns the result of a render_inline call.
Expand Down Expand Up @@ -365,6 +377,11 @@
end
```

### `#vc_test_view_context` → [ActionView::Base]

Returns the view context used to render components in tests. Note that the view context
is reset after each call to `render_inline`.

### `#with_controller_class(klass)`

Set the controller to be used while executing the given block,
Expand All @@ -386,7 +403,7 @@
end
```

### `#with_request_url(full_path, host: nil, method: nil)`
### `#with_request_url(full_path, host: nil, method: nil, protocol: nil)`

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

Expand All @@ -412,6 +429,14 @@
end
```

To specify a protocol, pass the protocol param:

```ruby
with_request_url("/users/42", protocol: :https) do
render_inline(MyComponent.new)
end
```

### `#with_variant(*variants)`

Set the Action Pack request variant for the given block:
Expand Down
Loading