view_component 2.56.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 338f95cb25ce1684e1be8486d44f84130f7a2a1b96f01d3a99b9909cb64ff650
4
- data.tar.gz: ac955c1551852c4ef4f5c884bacca4513f10b08b59e6a6b9aa635cfc20a7481c
3
+ metadata.gz: 1c0dea17d60642f97d9edad061c538054015eac0f774bc58d37ba30c177a76ac
4
+ data.tar.gz: bb12f7080b7c90ab0e475550bf44577ef25d2b1e0d0966cc5f07c272d9ea5fec
5
5
  SHA512:
6
- metadata.gz: efc8cebe7198a787d2534bf1d5ddadbea1d90940495df41cd1c13fe8f2f8ec2f4f065c6a7ee874e4e0c84cb823a02bdbcc3b912c29f00580b04b7475c1384755
7
- data.tar.gz: 0c4f543ec0047ce0cbd7fbbeafd38ddc973051e6e010e19b36a3040a89ebdd96a3dc108c48b7aeb2ce95416908bbefad0387fe965f7400940ea07284f177c5eb
6
+ metadata.gz: 3eb53d5be8bdb0ab083f0c57938bda3df2094c6368619efb59254bd8ce6a749ffcd4d1dab653b80be48a17f361fa15611c9086c2a526891d81e92527ffd67c9d
7
+ data.tar.gz: 418af4138439260637f53b025de631a11f222a699030afe36d3b51b7a31c5f451e7d3eb2ec5c6d13fa39b9b44e12e27fae972b631c92133bfbf054079695b80d
data/docs/CHANGELOG.md CHANGED
@@ -9,6 +9,33 @@ 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
+
19
+ ## 2.57.0
20
+
21
+ * Add missing `require` for `Translatable` module in `Base`.
22
+
23
+ *Hans Lemuet*
24
+
25
+ * Allow anything that responds to `#render_in` to be rendered in the parent component's view context.
26
+
27
+ *Cameron Dutro*
28
+
29
+ * Fix script/release so it honors semver.
30
+
31
+ *Cameron Dutro*
32
+
33
+ ## 2.56.2
34
+
35
+ * Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
36
+
37
+ *Tyson Gach*, *Richard Macklin*, *Joel Hawksley*
38
+
12
39
  ## 2.56.1
13
40
 
14
41
  * Rename private accessor `rendered_component` to `rendered_content`.
@@ -9,6 +9,7 @@ require "view_component/polymorphic_slots"
9
9
  require "view_component/previewable"
10
10
  require "view_component/slotable"
11
11
  require "view_component/slotable_v2"
12
+ require "view_component/translatable"
12
13
  require "view_component/with_content_helper"
13
14
 
14
15
  module ViewComponent
@@ -32,6 +33,19 @@ module ViewComponent
32
33
 
33
34
  attr_accessor :__vc_original_view_context
34
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
+
35
49
  # EXPERIMENTAL: This API is experimental and may be removed at any time.
36
50
  # Hook for allowing components to do work as part of the compilation process.
37
51
  #
@@ -113,24 +127,25 @@ module ViewComponent
113
127
  @current_template = old_current_template
114
128
  end
115
129
 
130
+ # @private
116
131
  def perform_render
117
132
  render_template_for(@__vc_variant).to_s + _output_postamble
118
133
  end
119
134
 
120
135
  # Subclass components that call `super` inside their template code will cause a
121
- # double render if they accidentally emit the result:
122
- #
123
- # <%= super %> # double-renders
136
+ # double render if they emit the result:
124
137
  #
125
- # <% super %> # does not double-render
138
+ # <%= super %> # double-renders
139
+ # <% super %> # does not double-render
126
140
  #
127
- # Calls `super`, returning nil to avoid rendering the result twice.
141
+ # Calls `super`, returning `nil` to avoid rendering the result twice.
128
142
  def render_parent
129
143
  mtd = @__vc_variant ? "call_#{@__vc_variant}" : "call"
130
144
  method(mtd).super_method.call
131
145
  nil
132
146
  end
133
147
 
148
+ # @private
134
149
  # :nocov:
135
150
  def render_template_for(variant = nil)
136
151
  # Force compilation here so the compiler always redefines render_template_for.
@@ -182,8 +197,8 @@ module ViewComponent
182
197
  #
183
198
  # @private
184
199
  def render(options = {}, args = {}, &block)
185
- if options.is_a? ViewComponent::Base
186
- options.__vc_original_view_context = __vc_original_view_context
200
+ if options.respond_to?(:set_original_view_context)
201
+ options.set_original_view_context(self.__vc_original_view_context)
187
202
  super
188
203
  else
189
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
@@ -32,6 +32,15 @@ module ViewComponent
32
32
  # @private
33
33
  attr_reader :rendered_content
34
34
 
35
+ def rendered_component
36
+ ViewComponent::Deprecation.warn(
37
+ "`rendered_component` is deprecated and will be removed in v3.0.0. " \
38
+ "Use `page` instead."
39
+ )
40
+
41
+ rendered_content
42
+ end
43
+
35
44
  # Render a component inline. Internally sets `page` to be a `Capybara::Node::Simple`,
36
45
  # allowing for Capybara assertions to be used:
37
46
  #
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 56
6
+ MINOR = 57
7
7
  PATCH = 1
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.56.1
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-01 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