Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
view_component (3.25.0)
view_component (3.26.0)
activesupport (>= 5.2.0, < 8.2)
concurrent-ruby (~> 1)
method_source (~> 1.0)
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ nav_order: 6

## main

## 3.26.0

* Fix rendering partials from components rendered as a collection when the original view context is explicitly stashed as `nil`.

*Justin Coyne, Joel Hawksley*
Expand Down
2 changes: 1 addition & 1 deletion docs/_data/library.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: 3.25.0
version: 3.26.0
65 changes: 54 additions & 11 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

Returns the current config.

### `.identifier` → [String]

The file path of the component Ruby file.

### `.sidecar_files(extensions)`

Find sidecar files for the given extensions.
Expand All @@ -37,7 +41,7 @@

Whether trailing whitespace will be stripped before compilation.

### `.with_collection(collection, **args)`
### `.with_collection(collection, spacer_component: nil, **args)`

Render a component for each element in a collection ([documentation](/guide/collections)):

Expand Down Expand Up @@ -78,23 +82,24 @@
A proxy through which to access helpers. Use sparingly as doing so introduces
coupling that inhibits encapsulation & reuse, often making testing difficult.

### `#output_preamble` → [String]

Optional content to be returned before the rendered template.

### `#output_postamble` → [String]

Optional content to be returned after the rendered template.

### `#output_preamble` → [String]

Optional content to be returned before the rendered template.

### `#render?` → [Boolean]

Override to determine whether the ViewComponent should render.

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

Entrypoint for rendering components.

- `view_context`: ActionView context from calling view
- `options`: optional render options (e.g., locals)

Check failure on line 102 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": 102, "column": 39}}}, "severity": "ERROR"}
- `block`: optional block to be captured within the view context

Returns HTML that has been escaped by the respective template handler.
Expand Down Expand Up @@ -191,6 +196,12 @@

config.view_component.generate.stimulus_controller = true

#### `#typescript`

Generate TypeScript files instead of JavaScript files:

config.view_component.generate.typescript = true

#### `#locale`

Always generate translations file alongside the component:
Expand Down Expand Up @@ -223,6 +234,19 @@
`ViewComponent.config.preview_paths` if defined,
`"test/components/previews"` otherwise

#### `#use_component_path_for_rspec_tests`

Whether to use the `config.view_component_path` when generating new
RSpec component tests:

config.view_component.generate.use_component_path_for_rspec_tests = true

When set to `true`, the generator will use the `view_component_path` to
decide where to generate the new RSpec component test.
For example, if the `view_component_path` is
`app/views/components`, then the generator will create a new spec file
in `spec/views/components/` rather than the default `spec/components/`.

### `.instrumentation_enabled`

Whether ActiveSupport notifications are enabled.
Expand Down Expand Up @@ -325,6 +349,15 @@

Returns the result of a render_inline call.

### `#rendered_json`

`JSON.parse`-d component output.

```ruby
render_inline(MyJsonComponent.new)
assert_equal(rendered_json["hello"], "world")
```

### `#vc_test_controller` → [ActionController::Base]

Access the controller used by `render_inline`:
Expand All @@ -343,7 +376,7 @@

```ruby
test "component does not render in Firefox" do
vc_test_request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
request.env["HTTP_USER_AGENT"] = "Mozilla/5.0"
render_inline(NoFirefoxComponent.new)
refute_component_rendered
end
Expand All @@ -360,7 +393,17 @@
end
```

### `#with_request_url(full_path, host: nil, method: nil)`
### `#with_format(format)`

Set format of the current request

```ruby
with_format(:json) do
render_inline(MyComponent.new)
end
```

### `#with_request_url(full_path, host: nil, method: nil, format: ViewComponent::Base::VC_INTERNAL_DEFAULT_FORMAT)`

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

Expand Down Expand Up @@ -418,7 +461,7 @@

### `ControllerCalledBeforeRenderError`

`#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.
`#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.

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).

Expand All @@ -444,7 +487,7 @@

### `HelpersCalledBeforeRenderError`

`#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.
`#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.

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).

Expand Down Expand Up @@ -528,7 +571,7 @@

### `TranslateCalledBeforeRenderError`

`#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.
`#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.

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).

Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ViewComponent
module VERSION
MAJOR = 3
MINOR = 25
MINOR = 26
PATCH = 0
PRE = nil

Expand Down
Loading