view_component 2.31.1 → 2.32.0
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/CHANGELOG.md +28 -0
- data/lib/view_component/base.rb +36 -5
- data/lib/view_component/engine.rb +1 -1
- data/lib/view_component/slotable_v2.rb +4 -4
- data/lib/view_component/test_helpers.rb +6 -1
- data/lib/view_component/version.rb +2 -2
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cdb5a57cbe401fab359e9daedfcb0180b2e6ec07bd332e7616c6a611442df13
|
4
|
+
data.tar.gz: 11ec2515ac60b615adc2a52cc7b526c7632871363a24a7b3128ca9a4873d57a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba44487de1f76102ec0fa9ea4fdd4af85c079c665c0e879855af5fe57577878a176badfef0af2a3d06d3384e852986048ab1332ed0a78fc589adea83f087b037
|
7
|
+
data.tar.gz: 32b565ca3c4759b366acf47de7f42a74ec52adb96d951013759cb5a289ffc16956b432bbee8e0dd79c3291c16386655fd7b8332da2ad3ba29db9dadcc87456a9
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,32 @@
|
|
2
2
|
|
3
3
|
## main
|
4
4
|
|
5
|
+
## 2.32.0
|
6
|
+
|
7
|
+
* Enable previews by default in test environment.
|
8
|
+
|
9
|
+
*Edouard Piron*
|
10
|
+
|
11
|
+
* Fix test helper compatibility with Rails 7.0, TestRequest, and TestSession.
|
12
|
+
|
13
|
+
*Leo Correa*
|
14
|
+
|
15
|
+
* Add experimental `_output_postamble` lifecyle method.
|
16
|
+
|
17
|
+
*Joel Hawksley*
|
18
|
+
|
19
|
+
* Add compatibility notes on FAQ.
|
20
|
+
|
21
|
+
*Matheus Richard*
|
22
|
+
|
23
|
+
* Add Bridgetown on Compatibility documentation.
|
24
|
+
|
25
|
+
*Matheus Richard*
|
26
|
+
|
27
|
+
* Are you interested in building the future of ViewComponent? GitHub is looking to hire a Senior Engineer to work on Primer ViewComponents and ViewComponent. Apply here: [US/Canada](https://github.com/careers) / [Europe](https://boards.greenhouse.io/github/jobs/3132294). Feel free to reach out to joelhawksley@github.com with any questions.
|
28
|
+
|
29
|
+
*Joel Hawksley*
|
30
|
+
|
5
31
|
## 2.31.1
|
6
32
|
|
7
33
|
* Fix `DEPRECATION WARNING: before_render_check` when compiling `ViewComponent::Base`
|
@@ -10,6 +36,8 @@
|
|
10
36
|
|
11
37
|
## 2.31.0
|
12
38
|
|
39
|
+
_Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot should not be returned. (`<%`)_
|
40
|
+
|
13
41
|
* Add `#with_content` to allow setting content without a block.
|
14
42
|
|
15
43
|
*Jordan Raine, Manuel Puyol*
|
data/lib/view_component/base.rb
CHANGED
@@ -30,6 +30,7 @@ module ViewComponent
|
|
30
30
|
# Hook for allowing components to do work as part of the compilation process.
|
31
31
|
#
|
32
32
|
# For example, one might compile component-specific assets at this point.
|
33
|
+
# @private TODO: add documentation
|
33
34
|
def self._after_compile
|
34
35
|
# noop
|
35
36
|
end
|
@@ -58,6 +59,7 @@ module ViewComponent
|
|
58
59
|
# returns:
|
59
60
|
# <span title="greeting">Hello, world!</span>
|
60
61
|
#
|
62
|
+
# @private
|
61
63
|
def render_in(view_context, &block)
|
62
64
|
self.class.compile(raise_errors: true)
|
63
65
|
|
@@ -89,7 +91,7 @@ module ViewComponent
|
|
89
91
|
before_render
|
90
92
|
|
91
93
|
if render?
|
92
|
-
render_template_for(@variant)
|
94
|
+
render_template_for(@variant) + _output_postamble
|
93
95
|
else
|
94
96
|
""
|
95
97
|
end
|
@@ -97,18 +99,36 @@ module ViewComponent
|
|
97
99
|
@current_template = old_current_template
|
98
100
|
end
|
99
101
|
|
102
|
+
# EXPERIMENTAL: Optional content to be returned after the rendered template.
|
103
|
+
#
|
104
|
+
# @return [String]
|
105
|
+
def _output_postamble
|
106
|
+
""
|
107
|
+
end
|
108
|
+
|
109
|
+
# Called before rendering the component. Override to perform operations that depend on having access to the view context, such as helpers.
|
110
|
+
#
|
111
|
+
# @return [void]
|
100
112
|
def before_render
|
101
113
|
before_render_check
|
102
114
|
end
|
103
115
|
|
116
|
+
# Called after rendering the component.
|
117
|
+
#
|
118
|
+
# @deprecated Use `before_render` instead. Will be removed in v3.0.0.
|
119
|
+
# @return [void]
|
104
120
|
def before_render_check
|
105
121
|
# noop
|
106
122
|
end
|
107
123
|
|
124
|
+
# Override to determine whether the ViewComponent should render.
|
125
|
+
#
|
126
|
+
# @return [Boolean]
|
108
127
|
def render?
|
109
128
|
true
|
110
129
|
end
|
111
130
|
|
131
|
+
# @private
|
112
132
|
def initialize(*); end
|
113
133
|
|
114
134
|
# Re-use original view_context if we're not rendering a component.
|
@@ -116,6 +136,7 @@ module ViewComponent
|
|
116
136
|
# This prevents an exception when rendering a partial inside of a component that has also been rendered outside
|
117
137
|
# of the component. This is due to the partials compiled template method existing in the parent `view_context`,
|
118
138
|
# and not the component's `view_context`.
|
139
|
+
# @private
|
119
140
|
def render(options = {}, args = {}, &block)
|
120
141
|
if options.is_a? ViewComponent::Base
|
121
142
|
super
|
@@ -124,28 +145,36 @@ module ViewComponent
|
|
124
145
|
end
|
125
146
|
end
|
126
147
|
|
148
|
+
# The current controller. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
|
149
|
+
#
|
150
|
+
# @return [ActionController::Base]
|
127
151
|
def controller
|
128
152
|
raise ViewContextCalledBeforeRenderError, "`controller` can only be called at render time." if view_context.nil?
|
129
153
|
@controller ||= view_context.controller
|
130
154
|
end
|
131
155
|
|
132
|
-
#
|
156
|
+
# A proxy through which to access helpers. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
|
157
|
+
#
|
158
|
+
# @return [ActionView::Base]
|
133
159
|
def helpers
|
134
160
|
raise ViewContextCalledBeforeRenderError, "`helpers` can only be called at render time." if view_context.nil?
|
135
161
|
@helpers ||= controller.view_context
|
136
162
|
end
|
137
163
|
|
138
164
|
# Exposes .virtual_path as an instance method
|
165
|
+
# @private
|
139
166
|
def virtual_path
|
140
167
|
self.class.virtual_path
|
141
168
|
end
|
142
169
|
|
143
170
|
# For caching, such as #cache_if
|
171
|
+
# @private
|
144
172
|
def view_cache_dependencies
|
145
173
|
[]
|
146
174
|
end
|
147
175
|
|
148
176
|
# For caching, such as #cache_if
|
177
|
+
# @private
|
149
178
|
def format
|
150
179
|
# Ruby 2.6 throws a warning without checking `defined?`, 2.7 does not
|
151
180
|
if defined?(@variant)
|
@@ -154,6 +183,7 @@ module ViewComponent
|
|
154
183
|
end
|
155
184
|
|
156
185
|
# Assign the provided content to the content area accessor
|
186
|
+
# @private
|
157
187
|
def with(area, content = nil, &block)
|
158
188
|
unless content_areas.include?(area)
|
159
189
|
raise ArgumentError.new "Unknown content_area '#{area}' - expected one of '#{content_areas}'"
|
@@ -167,15 +197,16 @@ module ViewComponent
|
|
167
197
|
nil
|
168
198
|
end
|
169
199
|
|
200
|
+
# @private TODO: add documentation
|
170
201
|
def with_variant(variant)
|
171
202
|
@variant = variant
|
172
203
|
|
173
204
|
self
|
174
205
|
end
|
175
206
|
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
207
|
+
# The current request. Use sparingly as doing so introduces coupling that inhibits encapsulation & reuse, often making testing difficult.
|
208
|
+
#
|
209
|
+
# @return [ActionDispatch::Request]
|
179
210
|
def request
|
180
211
|
@request ||= controller.request
|
181
212
|
end
|
@@ -12,7 +12,7 @@ module ViewComponent
|
|
12
12
|
options = app.config.view_component
|
13
13
|
|
14
14
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
15
|
-
options.show_previews = Rails.env.development? if options.show_previews.nil?
|
15
|
+
options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
|
16
16
|
options.preview_route ||= ViewComponent::Base.preview_route
|
17
17
|
options.preview_controller ||= ViewComponent::Base.preview_controller
|
18
18
|
|
@@ -60,7 +60,7 @@ module ViewComponent
|
|
60
60
|
# helper method with the same name as the slot.
|
61
61
|
#
|
62
62
|
# <%= render_inline(MyComponent.new) do |component| %>
|
63
|
-
#
|
63
|
+
# <% component.header(classes: "Foo") do %>
|
64
64
|
# <p>Bar</p>
|
65
65
|
# <% end %>
|
66
66
|
# <% end %>
|
@@ -95,7 +95,7 @@ module ViewComponent
|
|
95
95
|
# helper method with the same name as the slot.
|
96
96
|
#
|
97
97
|
# <h1>
|
98
|
-
#
|
98
|
+
# <% items.each do |item| %>
|
99
99
|
# <%= item %>
|
100
100
|
# <% end %>
|
101
101
|
# </h1>
|
@@ -107,11 +107,11 @@ module ViewComponent
|
|
107
107
|
# called multiple times to append to the slot.
|
108
108
|
#
|
109
109
|
# <%= render_inline(MyComponent.new) do |component| %>
|
110
|
-
#
|
110
|
+
# <% component.item(name: "Foo") do %>
|
111
111
|
# <p>One</p>
|
112
112
|
# <% end %>
|
113
113
|
#
|
114
|
-
#
|
114
|
+
# <% component.item(name: "Bar") do %>
|
115
115
|
# <p>two</p>
|
116
116
|
# <% end %>
|
117
117
|
# <% end %>
|
@@ -39,7 +39,12 @@ module ViewComponent
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def request
|
42
|
-
@request ||=
|
42
|
+
@request ||=
|
43
|
+
begin
|
44
|
+
request = ActionDispatch::TestRequest.create
|
45
|
+
request.session = ActionController::TestSession.new
|
46
|
+
request
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
50
|
def with_variant(variant)
|
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.
|
4
|
+
version: 2.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -212,7 +212,21 @@ dependencies:
|
|
212
212
|
- - "~>"
|
213
213
|
- !ruby/object:Gem::Version
|
214
214
|
version: '0.13'
|
215
|
-
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: yard
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - "~>"
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: 0.9.25
|
222
|
+
type: :development
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - "~>"
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: 0.9.25
|
229
|
+
description:
|
216
230
|
email:
|
217
231
|
- opensource+view_component@github.com
|
218
232
|
executables: []
|
@@ -272,7 +286,7 @@ licenses:
|
|
272
286
|
- MIT
|
273
287
|
metadata:
|
274
288
|
allowed_push_host: https://rubygems.org
|
275
|
-
post_install_message:
|
289
|
+
post_install_message:
|
276
290
|
rdoc_options: []
|
277
291
|
require_paths:
|
278
292
|
- lib
|
@@ -287,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
301
|
- !ruby/object:Gem::Version
|
288
302
|
version: '0'
|
289
303
|
requirements: []
|
290
|
-
rubygems_version: 3.
|
291
|
-
signing_key:
|
304
|
+
rubygems_version: 3.2.3
|
305
|
+
signing_key:
|
292
306
|
specification_version: 4
|
293
307
|
summary: View components for Rails
|
294
308
|
test_files: []
|