view_component 4.0.0.rc1 → 4.0.0.rc3
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 +20 -0
- data/lib/view_component/base.rb +25 -4
- data/lib/view_component/slot.rb +6 -2
- data/lib/view_component/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9389db3857fccdd96788494eb6992ceca37f1934f9587317b806a992f53a599
|
4
|
+
data.tar.gz: 675ca1e487f5724cc5ac33e397fb9b1f2027347c6ca569223e4e5e772150ad05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4810cd0a918e52322ef4f0b36b830cbb79cd80b2fce6d9cc680b9b43f5b490e76b412d8504aee3cc577bf6892053ac5ed789fdb14c8c2d71fce582b0011efc95
|
7
|
+
data.tar.gz: b8821ec370dbf668ad03c19b832ccbd8754d0da6a23b131d77f6c4898088214d2d51cb3e0c404ad919a75bf63ea387324f95decf03a497df30f8396650c2cd35
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,26 @@ nav_order: 6
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 4.0.0.rc3
|
14
|
+
|
15
|
+
* Reformat the avatars section to arrange them in a grid.
|
16
|
+
|
17
|
+
*Josh Cohen*
|
18
|
+
|
19
|
+
* Fix bug where relative paths in `translate` didn't work in blocks passed to ViewComponents.
|
20
|
+
|
21
|
+
*Joel Hawksley*
|
22
|
+
|
23
|
+
* Add SerpApi to "Who uses ViewComponent" list.
|
24
|
+
|
25
|
+
*Andy from SerpApi*
|
26
|
+
|
27
|
+
## 4.0.0.rc2
|
28
|
+
|
29
|
+
* Add `around_render` lifecyle method for wrapping component rendering in custom instrumentation, etc.
|
30
|
+
|
31
|
+
*Joel Hawksley*, *Blake Williams*
|
32
|
+
|
13
33
|
## 4.0.0.rc1
|
14
34
|
|
15
35
|
Almost six years after releasing [v1.0.0](https://github.com/ViewComponent/view_component/releases/tag/v1.0.0), we're proud to ship the first release candidate of 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.
|
data/lib/view_component/base.rb
CHANGED
@@ -108,7 +108,7 @@ module ViewComponent
|
|
108
108
|
self.class.__vc_compile(raise_errors: true)
|
109
109
|
|
110
110
|
@view_context = view_context
|
111
|
-
old_virtual_path = view_context.instance_variable_get(:@virtual_path)
|
111
|
+
@old_virtual_path = view_context.instance_variable_get(:@virtual_path)
|
112
112
|
self.__vc_original_view_context ||= view_context
|
113
113
|
|
114
114
|
@output_buffer = view_context.output_buffer
|
@@ -143,7 +143,10 @@ module ViewComponent
|
|
143
143
|
@output_buffer.with_buffer do
|
144
144
|
@view_context.instance_variable_set(:@virtual_path, virtual_path)
|
145
145
|
|
146
|
-
rendered_template =
|
146
|
+
rendered_template =
|
147
|
+
around_render do
|
148
|
+
render_template_for(@__vc_requested_details).to_s
|
149
|
+
end
|
147
150
|
|
148
151
|
# Avoid allocating new string when output_preamble and output_postamble are blank
|
149
152
|
value = if output_preamble.blank? && output_postamble.blank?
|
@@ -163,7 +166,7 @@ module ViewComponent
|
|
163
166
|
""
|
164
167
|
end
|
165
168
|
ensure
|
166
|
-
view_context.instance_variable_set(:@virtual_path, old_virtual_path)
|
169
|
+
view_context.instance_variable_set(:@virtual_path, @old_virtual_path)
|
167
170
|
@current_template = old_current_template
|
168
171
|
end
|
169
172
|
|
@@ -228,6 +231,14 @@ module ViewComponent
|
|
228
231
|
# noop
|
229
232
|
end
|
230
233
|
|
234
|
+
# Called around rendering the component. Override to wrap the rendering of a
|
235
|
+
# component in custom instrumentation, etc.
|
236
|
+
#
|
237
|
+
# @return [void]
|
238
|
+
def around_render
|
239
|
+
yield
|
240
|
+
end
|
241
|
+
|
231
242
|
# Override to determine whether the ViewComponent should render.
|
232
243
|
#
|
233
244
|
# @return [Boolean]
|
@@ -330,7 +341,9 @@ module ViewComponent
|
|
330
341
|
|
331
342
|
@__vc_content =
|
332
343
|
if __vc_render_in_block_provided?
|
333
|
-
|
344
|
+
with_original_virtual_path do
|
345
|
+
view_context.capture(self, &@__vc_render_in_block)
|
346
|
+
end
|
334
347
|
elsif __vc_content_set_by_with_content_defined?
|
335
348
|
@__vc_content_set_by_with_content
|
336
349
|
end
|
@@ -347,6 +360,14 @@ module ViewComponent
|
|
347
360
|
self.class.__vc_response_format
|
348
361
|
end
|
349
362
|
|
363
|
+
# @private
|
364
|
+
def with_original_virtual_path
|
365
|
+
@view_context.instance_variable_set(:@virtual_path, @old_virtual_path)
|
366
|
+
yield
|
367
|
+
ensure
|
368
|
+
@view_context.instance_variable_set(:@virtual_path, virtual_path)
|
369
|
+
end
|
370
|
+
|
350
371
|
private
|
351
372
|
|
352
373
|
attr_reader :view_context
|
data/lib/view_component/slot.rb
CHANGED
@@ -58,7 +58,9 @@ module ViewComponent
|
|
58
58
|
if defined?(@__vc_content_block)
|
59
59
|
# render_in is faster than `parent.render`
|
60
60
|
@__vc_component_instance.render_in(view_context) do |*args|
|
61
|
-
@
|
61
|
+
@parent.with_original_virtual_path do
|
62
|
+
@__vc_content_block.call(*args)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
else
|
64
66
|
@__vc_component_instance.render_in(view_context)
|
@@ -66,7 +68,9 @@ module ViewComponent
|
|
66
68
|
elsif defined?(@__vc_content)
|
67
69
|
@__vc_content
|
68
70
|
elsif defined?(@__vc_content_block)
|
69
|
-
|
71
|
+
@parent.with_original_virtual_path do
|
72
|
+
view_context.capture(&@__vc_content_block)
|
73
|
+
end
|
70
74
|
elsif defined?(@__vc_content_set_by_with_content)
|
71
75
|
@__vc_content_set_by_with_content
|
72
76
|
end
|