view_component 2.57.0 → 2.57.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +7 -0
- data/lib/view_component/base.rb +21 -10
- data/lib/view_component/collection.rb +7 -0
- 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: 1c0dea17d60642f97d9edad061c538054015eac0f774bc58d37ba30c177a76ac
|
4
|
+
data.tar.gz: bb12f7080b7c90ab0e475550bf44577ef25d2b1e0d0966cc5f07c272d9ea5fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb53d5be8bdb0ab083f0c57938bda3df2094c6368619efb59254bd8ce6a749ffcd4d1dab653b80be48a17f361fa15611c9086c2a526891d81e92527ffd67c9d
|
7
|
+
data.tar.gz: 418af4138439260637f53b025de631a11f222a699030afe36d3b51b7a31c5f451e7d3eb2ec5c6d13fa39b9b44e12e27fae972b631c92133bfbf054079695b80d
|
data/docs/CHANGELOG.md
CHANGED
@@ -9,6 +9,13 @@ title: Changelog
|
|
9
9
|
|
10
10
|
## main
|
11
11
|
|
12
|
+
## 2.57.1
|
13
|
+
|
14
|
+
* Fix issue causing `NoMethodError`s when calling helper methods from components rendered as part of a collection.
|
15
|
+
* Fix syntax error in the ERB example in the polymorphic slots docs.
|
16
|
+
|
17
|
+
*Cameron Dutro*
|
18
|
+
|
12
19
|
## 2.57.0
|
13
20
|
|
14
21
|
* Add missing `require` for `Translatable` module in `Base`.
|
data/lib/view_component/base.rb
CHANGED
@@ -33,6 +33,19 @@ module ViewComponent
|
|
33
33
|
|
34
34
|
attr_accessor :__vc_original_view_context
|
35
35
|
|
36
|
+
# Components render in their own view context. Helpers and other functionality
|
37
|
+
# require a reference to the original Rails view context, an instance of
|
38
|
+
# `ActionView::Base`. Use this method to set a reference to the original
|
39
|
+
# view context. Objects that implement this method will render in the component's
|
40
|
+
# view context, while objects that don't will render in the original view context
|
41
|
+
# so helpers, etc work as expected.
|
42
|
+
#
|
43
|
+
# @param view_context [ActionView::Base] The original view context.
|
44
|
+
# @return [void]
|
45
|
+
def set_original_view_context(view_context)
|
46
|
+
self.__vc_original_view_context = view_context
|
47
|
+
end
|
48
|
+
|
36
49
|
# EXPERIMENTAL: This API is experimental and may be removed at any time.
|
37
50
|
# Hook for allowing components to do work as part of the compilation process.
|
38
51
|
#
|
@@ -114,24 +127,25 @@ module ViewComponent
|
|
114
127
|
@current_template = old_current_template
|
115
128
|
end
|
116
129
|
|
130
|
+
# @private
|
117
131
|
def perform_render
|
118
132
|
render_template_for(@__vc_variant).to_s + _output_postamble
|
119
133
|
end
|
120
134
|
|
121
135
|
# Subclass components that call `super` inside their template code will cause a
|
122
|
-
# double render if they
|
136
|
+
# double render if they emit the result:
|
123
137
|
#
|
124
|
-
#
|
138
|
+
# <%= super %> # double-renders
|
139
|
+
# <% super %> # does not double-render
|
125
140
|
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# Calls `super`, returning nil to avoid rendering the result twice.
|
141
|
+
# Calls `super`, returning `nil` to avoid rendering the result twice.
|
129
142
|
def render_parent
|
130
143
|
mtd = @__vc_variant ? "call_#{@__vc_variant}" : "call"
|
131
144
|
method(mtd).super_method.call
|
132
145
|
nil
|
133
146
|
end
|
134
147
|
|
148
|
+
# @private
|
135
149
|
# :nocov:
|
136
150
|
def render_template_for(variant = nil)
|
137
151
|
# Force compilation here so the compiler always redefines render_template_for.
|
@@ -183,11 +197,8 @@ module ViewComponent
|
|
183
197
|
#
|
184
198
|
# @private
|
185
199
|
def render(options = {}, args = {}, &block)
|
186
|
-
if options.respond_to?(:
|
187
|
-
|
188
|
-
options.__vc_original_view_context = __vc_original_view_context
|
189
|
-
end
|
190
|
-
|
200
|
+
if options.respond_to?(:set_original_view_context)
|
201
|
+
options.set_original_view_context(self.__vc_original_view_context)
|
191
202
|
super
|
192
203
|
else
|
193
204
|
__vc_original_view_context.render(options, args, &block)
|
@@ -10,8 +10,15 @@ module ViewComponent
|
|
10
10
|
delegate :format, to: :component
|
11
11
|
delegate :size, to: :@collection
|
12
12
|
|
13
|
+
attr_accessor :__vc_original_view_context
|
14
|
+
|
15
|
+
def set_original_view_context(view_context)
|
16
|
+
self.__vc_original_view_context = view_context
|
17
|
+
end
|
18
|
+
|
13
19
|
def render_in(view_context, &block)
|
14
20
|
components.map do |component|
|
21
|
+
component.set_original_view_context(self.__vc_original_view_context)
|
15
22
|
component.render_in(view_context, &block)
|
16
23
|
end.join.html_safe # rubocop:disable Rails/OutputSafety
|
17
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.57.
|
4
|
+
version: 2.57.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|