view_component 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +24 -6
- data/lib/view_component/base.rb +27 -4
- data/lib/view_component/collection.rb +8 -0
- data/lib/view_component/test_helpers.rb +13 -3
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c8fa66735f8008894ba88d64885dc307bc71381e2b88391798fa4266da7279
|
4
|
+
data.tar.gz: f217babfa1c1894f377fff73fc3b603755122422c8596e349ffd0d8689e86708
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a10d8362a64c181f11dd0aff69725eb7045a4a4cb546c2e960183bf416083dc8b5bcee76c807be3341dd01919eba3fdc2636083de2794101d8751f1c405396a1
|
7
|
+
data.tar.gz: 2ae8c40ff912472d16d27e3a92af772905d74b3ab010ced00578208ee281f53f59adc31bc0ef0b170cf1ea8c64cd0750db0c0804bb65deca11a33f430cc7012d
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,25 @@ nav_order: 6
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 4.0.2
|
14
|
+
|
15
|
+
* Share the view context in tests to prevent out-of-order rendering issues for certain advanced use-cases, eg. testing instances of Rails' `FormBuilder`.
|
16
|
+
* Fix double rendering issue for partials that yield.
|
17
|
+
|
18
|
+
*Cameron Dutro*
|
19
|
+
|
20
|
+
## 4.0.1
|
21
|
+
|
22
|
+
* Setup Trusted Publishing to RubyGems to improve software supply chain safety.
|
23
|
+
|
24
|
+
*Hans Lemuet*
|
25
|
+
|
26
|
+
* Conditionally add the `ViewComponent::Base#format` method back for Rails 7.1 only.
|
27
|
+
* Compute and check lockfiles into source control.
|
28
|
+
* Constrain Rails versions in gemfiles to only allow the patch version to vary, eg. `~> 7.1.0` instead of `~> 7.1`.
|
29
|
+
|
30
|
+
*Cameron Dutro*
|
31
|
+
|
13
32
|
## 4.0.0
|
14
33
|
|
15
34
|
Two years after releasing [3.0.0](https://github.com/ViewComponent/view_component/releases/tag/v3.0.0) and almost six years since [1.0.0](https://github.com/ViewComponent/view_component/releases/tag/v1.0.0), we're proud to ship ViewComponent 4. This release marks a shift towards a Long Term Support model for the project, having reached significant feature maturity. While contributions are always welcome, we're unlikely to accept further breaking changes or major feature additions.
|
@@ -37,11 +56,10 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
37
56
|
|
38
57
|
### Breaking changes (dev/test)
|
39
58
|
|
40
|
-
*
|
41
|
-
*
|
42
|
-
* `config.
|
59
|
+
* Remove `config.view_component.test_controller` in favor of `vc_test_controller_class` test helper method.
|
60
|
+
* `config.view_component.component_parent_class` is now `config.view_component.generate.parent_class`, moving the generator-specific option to the generator configuration namespace.
|
61
|
+
* `config.view_component.view_component_path` is now `config.view_component.generate.path`, as components have long since been able to exist in any directory.
|
43
62
|
* Move previews-related configuration (`enabled`, `route`, `paths`, `default_layout`, `controller`) to under `previews` namespace.
|
44
|
-
* `config.view_component_path` is now `config.generate.path`, as components have long since been able to exist in any directory.
|
45
63
|
* `--inline` generator option now generates inline template. Use `--call` to generate `#call` method.
|
46
64
|
* Remove broken integration with `rails stats` that ignored components outside of `app/components`.
|
47
65
|
* Remove `preview_source` functionality. Consider using [Lookbook](https://lookbook.build/) instead.
|
@@ -66,7 +84,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
66
84
|
### Bug fixes
|
67
85
|
|
68
86
|
* Fix bug where virtual path wasn't reset, breaking translations outside of components.
|
69
|
-
* Fix bug where `config.previews.enabled` didn't function properly in production environments.
|
87
|
+
* Fix bug where `config.view_component.previews.enabled` didn't function properly in production environments.
|
70
88
|
* Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
|
71
89
|
* Fix bug where request-aware helpers didn't work outside of the request context.
|
72
90
|
* `ViewComponentsSystemTestController` shouldn't be useable outside of test environment
|
@@ -81,7 +99,7 @@ Please report any issues at [https://github.com/ViewComponent/view_component/iss
|
|
81
99
|
* Update documentation on performance to reflect more representative benchmark showing 2-3x speed increase over partials.
|
82
100
|
* Add documentation note about instrumentation negatively affecting performance.
|
83
101
|
* Remove unnecessary ENABLE_RELOADING test suite flag.
|
84
|
-
* `config.previews.default_layout` should default to nil.
|
102
|
+
* `config.view_component.previews.default_layout` should default to nil.
|
85
103
|
* Add test coverage for uncovered code.
|
86
104
|
* Test against `turbo-rails` `v2` and `rspec-rails` `v7`.
|
87
105
|
|
data/lib/view_component/base.rb
CHANGED
@@ -246,17 +246,32 @@ module ViewComponent
|
|
246
246
|
|
247
247
|
# Re-use original view_context if we're not rendering a component.
|
248
248
|
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
249
|
+
# As of v4, ViewComponent::Base re-uses the existing view context created
|
250
|
+
# by ActionView, meaning the current view context and the original view
|
251
|
+
# context are the same object. set_original_view_context is still called
|
252
|
+
# to maintain backwards compatibility.
|
252
253
|
#
|
253
254
|
# @private
|
254
255
|
def render(options = {}, args = {}, &block)
|
255
256
|
if options.respond_to?(:set_original_view_context)
|
256
257
|
options.set_original_view_context(self.__vc_original_view_context)
|
258
|
+
|
259
|
+
# We assume options is a component, so there's no need to evaluate the
|
260
|
+
# block in the view context as we do below.
|
257
261
|
@view_context.render(options, args, &block)
|
262
|
+
elsif block
|
263
|
+
__vc_original_view_context.render(options, args) do
|
264
|
+
# Partials are rendered to their own buffer and do not append to the
|
265
|
+
# original @output_buffer we retain a reference to in #render_in. This
|
266
|
+
# is a problem since the block passed to us here in the #render method
|
267
|
+
# is evaluated within the context of ViewComponent::Base, and thus
|
268
|
+
# appends to the original @output_buffer. To avoid this, we evaluate the
|
269
|
+
# block in the view context instead, which will append to the output buffer
|
270
|
+
# created for the partial.
|
271
|
+
__vc_original_view_context.instance_exec(&block)
|
272
|
+
end
|
258
273
|
else
|
259
|
-
__vc_original_view_context.render(options, args
|
274
|
+
__vc_original_view_context.render(options, args)
|
260
275
|
end
|
261
276
|
end
|
262
277
|
|
@@ -316,6 +331,14 @@ module ViewComponent
|
|
316
331
|
[]
|
317
332
|
end
|
318
333
|
|
334
|
+
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
335
|
+
# Rails expects us to define `format` on all renderables,
|
336
|
+
# but we do not know the `format` of a ViewComponent until runtime.
|
337
|
+
def format
|
338
|
+
nil
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
319
342
|
# The current request. Use sparingly as doing so introduces coupling that
|
320
343
|
# inhibits encapsulation & reuse, often making testing difficult.
|
321
344
|
#
|
@@ -19,6 +19,14 @@ module ViewComponent
|
|
19
19
|
components.each(&block)
|
20
20
|
end
|
21
21
|
|
22
|
+
if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 1
|
23
|
+
# Rails expects us to define `format` on all renderables,
|
24
|
+
# but we do not know the `format` of a ViewComponent until runtime.
|
25
|
+
def format
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
22
30
|
private
|
23
31
|
|
24
32
|
def components
|
@@ -38,9 +38,19 @@ module ViewComponent
|
|
38
38
|
# @return [Nokogiri::HTML5]
|
39
39
|
def render_inline(component, **args, &block)
|
40
40
|
@page = nil
|
41
|
-
@rendered_content =
|
41
|
+
@rendered_content = vc_test_view_context.render(component, args, &block)
|
42
42
|
|
43
|
-
Nokogiri::HTML5.fragment(@rendered_content)
|
43
|
+
fragment = Nokogiri::HTML5.fragment(@rendered_content)
|
44
|
+
@vc_test_view_context = nil
|
45
|
+
fragment
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the view context used to render components in tests. Note that the view context
|
49
|
+
# is reset after each call to `render_inline`.
|
50
|
+
#
|
51
|
+
# @return [ActionView::Base]
|
52
|
+
def vc_test_view_context
|
53
|
+
@vc_test_view_context ||= vc_test_controller.view_context
|
44
54
|
end
|
45
55
|
|
46
56
|
# `JSON.parse`-d component output.
|
@@ -103,7 +113,7 @@ module ViewComponent
|
|
103
113
|
# ```
|
104
114
|
def render_in_view_context(...)
|
105
115
|
@page = nil
|
106
|
-
@rendered_content =
|
116
|
+
@rendered_content = vc_test_view_context.instance_exec(...)
|
107
117
|
Nokogiri::HTML5.fragment(@rendered_content)
|
108
118
|
end
|
109
119
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.6.
|
130
|
+
rubygems_version: 3.6.9
|
131
131
|
specification_version: 4
|
132
132
|
summary: A framework for building reusable, testable & encapsulated view components
|
133
133
|
in Ruby on Rails.
|