view_component 2.57.0 → 2.57.1

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.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a22d7248560f80072ed000776afa4f92b164cd80931570feb4a3416bb6ba3627
4
- data.tar.gz: 9bc617ae2ff51bad6f61b41412b4b3827c4bbe3f2366e0a3829ee00216d9518d
3
+ metadata.gz: 1c0dea17d60642f97d9edad061c538054015eac0f774bc58d37ba30c177a76ac
4
+ data.tar.gz: bb12f7080b7c90ab0e475550bf44577ef25d2b1e0d0966cc5f07c272d9ea5fec
5
5
  SHA512:
6
- metadata.gz: 648585993d06389775c8d14edee060fc551394edadaa7337a4b10709183941f9143cad71dc045ec4dca50db5bd568b8b57066518c0222e32e569f89e787043af
7
- data.tar.gz: 4c8fbee2640a2fba303ce93010bdf789cbe094f233e7253dc4491207cadd3101914d86ae22c4b85e7c3db78b18e048b14955b41ce86ceb510fd4495e6ef216dc
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`.
@@ -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 accidentally emit the result:
136
+ # double render if they emit the result:
123
137
  #
124
- # <%= super %> # double-renders
138
+ # <%= super %> # double-renders
139
+ # <% super %> # does not double-render
125
140
  #
126
- # <% super %> # does not double-render
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?(:render_in)
187
- if options.is_a?(ViewComponent::Base)
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
@@ -4,7 +4,7 @@ module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
6
  MINOR = 57
7
- PATCH = 0
7
+ PATCH = 1
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  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.0
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-10 00:00:00.000000000 Z
11
+ date: 2022-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport