view_component 3.0.0 → 3.1.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/app/controllers/concerns/view_component/preview_actions.rb +4 -0
- data/docs/CHANGELOG.md +42 -0
- data/lib/view_component/base.rb +10 -5
- data/lib/view_component/config.rb +1 -1
- data/lib/view_component/errors.rb +10 -0
- data/lib/view_component/slot.rb +2 -0
- data/lib/view_component/slotable.rb +24 -16
- data/lib/view_component/version.rb +1 -1
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca112c2d340e4ade9bd258d515edafbd1cc66e0b19097acd12d3eab53b9ae4a4
|
4
|
+
data.tar.gz: 173223c31abaf369bbfb455eff47137dfa6b7ac98485b17ba58c8317d6f5c3e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d63eac1f6f698a44ae621b107194d5ae2e0f4ef16da352e8fbb4ee5514f61fadd70e596582d6f78fcbc5738be3046013846a8541d0e845a85a4d1257262d8ad
|
7
|
+
data.tar.gz: f7a415d645e7dc45cbd0300fed91c3356d10c543ea9331a24b7beb8e67efe0f3f05d09148a66a4dbecd14149861c884ea0481c033c9c32da5f398b3744c02b60
|
@@ -11,6 +11,10 @@ module ViewComponent
|
|
11
11
|
before_action :require_local!, unless: :show_previews?
|
12
12
|
|
13
13
|
content_security_policy(false) if respond_to?(:content_security_policy)
|
14
|
+
|
15
|
+
# Including helpers here ensures that we're loading the
|
16
|
+
# latest version of helpers if code-reloading is enabled
|
17
|
+
helper :all if include_all_helpers
|
14
18
|
end
|
15
19
|
|
16
20
|
def index
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,44 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 3.1.0
|
14
|
+
|
15
|
+
* Check `defined?(Rails) && Rails.application` before using `ViewComponent::Base.config.view_component_path`.
|
16
|
+
|
17
|
+
*Donapieppo*
|
18
|
+
|
19
|
+
* Allow customization of polymorphic slot setters.
|
20
|
+
|
21
|
+
*Cameron Dutro*
|
22
|
+
|
23
|
+
* Fix duplication in configuration docs.
|
24
|
+
|
25
|
+
*Tom Chen*
|
26
|
+
|
27
|
+
* Fix helpers not reloading in development.
|
28
|
+
|
29
|
+
*Jonathan del Strother*
|
30
|
+
|
31
|
+
* Add `SECURITY.md`.
|
32
|
+
|
33
|
+
*Joel Hawksley*
|
34
|
+
|
35
|
+
* Add Ophelos to list of companies using ViewComponent.
|
36
|
+
|
37
|
+
*Graham Rogers*
|
38
|
+
|
39
|
+
* Add FlightLogger to list of companies using ViewComponent.
|
40
|
+
|
41
|
+
*Joseph Carpenter*
|
42
|
+
|
43
|
+
* Fix coverage reports overwriting each other when running locally.
|
44
|
+
|
45
|
+
*Jonathan del Strother*
|
46
|
+
|
47
|
+
* Add @reeganviljoen to triage team.
|
48
|
+
|
49
|
+
*Reegan Viljoen*
|
50
|
+
|
13
51
|
### v3.0.0
|
14
52
|
|
15
53
|
1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
|
@@ -86,6 +124,10 @@ This release makes the following breaking changes, many of which have long been
|
|
86
124
|
|
87
125
|
*Joel Hawksley*
|
88
126
|
|
127
|
+
* Add support for CSP nonces inside of components.
|
128
|
+
|
129
|
+
*Reegan Viljoen*
|
130
|
+
|
89
131
|
### v3.0.0.rc6
|
90
132
|
|
91
133
|
Run into an issue with this release candidate? [Let us know](https://github.com/ViewComponent/view_component/issues/1629). We hope to release v3.0.0 in the near future!
|
data/lib/view_component/base.rb
CHANGED
@@ -19,7 +19,7 @@ module ViewComponent
|
|
19
19
|
|
20
20
|
# Returns the current config.
|
21
21
|
#
|
22
|
-
# @return [
|
22
|
+
# @return [ActiveSupport::OrderedOptions]
|
23
23
|
def config
|
24
24
|
@config ||= ActiveSupport::OrderedOptions.new
|
25
25
|
end
|
@@ -38,6 +38,9 @@ module ViewComponent
|
|
38
38
|
# For CSRF authenticity tokens in forms
|
39
39
|
delegate :form_authenticity_token, :protect_against_forgery?, :config, to: :helpers
|
40
40
|
|
41
|
+
# For Content Security Policy nonces
|
42
|
+
delegate :content_security_policy_nonce, to: :helpers
|
43
|
+
|
41
44
|
# Config option that strips trailing whitespace in templates before compiling them.
|
42
45
|
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false
|
43
46
|
self.__vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
|
@@ -444,10 +447,12 @@ module ViewComponent
|
|
444
447
|
# has been re-defined by the consuming application, likely in ApplicationComponent.
|
445
448
|
child.source_location = caller_locations(1, 10).reject { |l| l.label == "inherited" }[0].path
|
446
449
|
|
447
|
-
#
|
448
|
-
|
449
|
-
|
450
|
-
|
450
|
+
# If Rails application is loaded, removes the first part of the path and the extension.
|
451
|
+
if defined?(Rails) && Rails.application
|
452
|
+
child.virtual_path = child.source_location.gsub(
|
453
|
+
/(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
|
454
|
+
)
|
455
|
+
end
|
451
456
|
|
452
457
|
# Set collection parameter to the extended component
|
453
458
|
child.with_collection_parameter provided_collection_parameter
|
@@ -138,7 +138,7 @@ module ViewComponent
|
|
138
138
|
# A custom default layout used for the previews index page and individual
|
139
139
|
# previews.
|
140
140
|
# Defaults to `nil`. If this is falsy, `"component_preview"` is used.
|
141
|
-
|
141
|
+
|
142
142
|
# @!attribute capture_compatibility_patch_enabled
|
143
143
|
# @return [Boolean]
|
144
144
|
# Enables the experimental capture compatibility patch that makes ViewComponent
|
@@ -210,4 +210,14 @@ module ViewComponent
|
|
210
210
|
class SystemTestControllerNefariousPathError < BaseError
|
211
211
|
MESSAGE = "ViewComponent SystemTest controller attempted to load a file outside of the expected directory."
|
212
212
|
end
|
213
|
+
|
214
|
+
class AlreadyDefinedPolymorphicSlotSetterError < StandardError
|
215
|
+
MESSAGE =
|
216
|
+
"A method called 'SETTER_METHOD_NAME' already exists and would be overwritten by the 'SETTER_NAME' polymorphic " \
|
217
|
+
"slot setter.\n\nPlease choose a different setter name."
|
218
|
+
|
219
|
+
def initialize(setter_method_name, setter_name)
|
220
|
+
super(MESSAGE.gsub("SETTER_METHOD_NAME", setter_method_name.to_s).gsub("SETTER_NAME", setter_name.to_s))
|
221
|
+
end
|
222
|
+
end
|
213
223
|
end
|
data/lib/view_component/slot.rb
CHANGED
@@ -206,38 +206,46 @@ module ViewComponent
|
|
206
206
|
end
|
207
207
|
|
208
208
|
def register_polymorphic_slot(slot_name, types, collection:)
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
define_method(getter_name) do
|
213
|
-
get_slot(slot_name)
|
214
|
-
end
|
209
|
+
define_method(slot_name) do
|
210
|
+
get_slot(slot_name)
|
211
|
+
end
|
215
212
|
|
216
|
-
|
217
|
-
|
218
|
-
end
|
213
|
+
define_method("#{slot_name}?") do
|
214
|
+
get_slot(slot_name).present?
|
219
215
|
end
|
220
216
|
|
221
|
-
renderable_hash = types.each_with_object({}) do |(poly_type,
|
222
|
-
|
223
|
-
|
224
|
-
|
217
|
+
renderable_hash = types.each_with_object({}) do |(poly_type, poly_attributes_or_callable), memo|
|
218
|
+
if poly_attributes_or_callable.is_a?(Hash)
|
219
|
+
poly_callable = poly_attributes_or_callable[:renders]
|
220
|
+
poly_slot_name = poly_attributes_or_callable[:as]
|
221
|
+
else
|
222
|
+
poly_callable = poly_attributes_or_callable
|
223
|
+
poly_slot_name = nil
|
224
|
+
end
|
225
225
|
|
226
|
-
|
226
|
+
poly_slot_name ||=
|
227
227
|
if collection
|
228
228
|
"#{ActiveSupport::Inflector.singularize(slot_name)}_#{poly_type}"
|
229
229
|
else
|
230
230
|
"#{slot_name}_#{poly_type}"
|
231
231
|
end
|
232
232
|
|
233
|
-
|
233
|
+
memo[poly_type] = define_slot(
|
234
|
+
poly_slot_name, collection: collection, callable: poly_callable
|
235
|
+
)
|
236
|
+
|
237
|
+
setter_method_name = :"with_#{poly_slot_name}"
|
238
|
+
|
239
|
+
if instance_methods.include?(setter_method_name)
|
240
|
+
raise AlreadyDefinedPolymorphicSlotSetterError.new(setter_method_name, poly_slot_name)
|
241
|
+
end
|
234
242
|
|
235
243
|
define_method(setter_method_name) do |*args, &block|
|
236
244
|
set_polymorphic_slot(slot_name, poly_type, *args, &block)
|
237
245
|
end
|
238
246
|
ruby2_keywords(setter_method_name) if respond_to?(:ruby2_keywords, true)
|
239
247
|
|
240
|
-
define_method "with_#{
|
248
|
+
define_method "with_#{poly_slot_name}_content" do |content|
|
241
249
|
send(setter_method_name) { content.to_s }
|
242
250
|
|
243
251
|
self
|
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: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 2.
|
81
|
+
version: 2.12.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
88
|
+
version: 2.12.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: better_html
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '6'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
144
|
+
version: '6'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: jbuilder
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,16 +174,16 @@ dependencies:
|
|
174
174
|
name: minitest
|
175
175
|
requirement: !ruby/object:Gem::Requirement
|
176
176
|
requirements:
|
177
|
-
- -
|
177
|
+
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 5.
|
179
|
+
version: '5.18'
|
180
180
|
type: :development
|
181
181
|
prerelease: false
|
182
182
|
version_requirements: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
|
-
- -
|
184
|
+
- - "~>"
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: 5.
|
186
|
+
version: '5.18'
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: pry
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -246,56 +246,56 @@ dependencies:
|
|
246
246
|
requirements:
|
247
247
|
- - "~>"
|
248
248
|
- !ruby/object:Gem::Version
|
249
|
-
version: 0.
|
249
|
+
version: 0.22.0
|
250
250
|
type: :development
|
251
251
|
prerelease: false
|
252
252
|
version_requirements: !ruby/object:Gem::Requirement
|
253
253
|
requirements:
|
254
254
|
- - "~>"
|
255
255
|
- !ruby/object:Gem::Version
|
256
|
-
version: 0.
|
256
|
+
version: 0.22.0
|
257
257
|
- !ruby/object:Gem::Dependency
|
258
258
|
name: simplecov-console
|
259
259
|
requirement: !ruby/object:Gem::Requirement
|
260
260
|
requirements:
|
261
261
|
- - "~>"
|
262
262
|
- !ruby/object:Gem::Version
|
263
|
-
version: 0.
|
263
|
+
version: 0.9.1
|
264
264
|
type: :development
|
265
265
|
prerelease: false
|
266
266
|
version_requirements: !ruby/object:Gem::Requirement
|
267
267
|
requirements:
|
268
268
|
- - "~>"
|
269
269
|
- !ruby/object:Gem::Version
|
270
|
-
version: 0.
|
270
|
+
version: 0.9.1
|
271
271
|
- !ruby/object:Gem::Dependency
|
272
272
|
name: slim
|
273
273
|
requirement: !ruby/object:Gem::Requirement
|
274
274
|
requirements:
|
275
275
|
- - "~>"
|
276
276
|
- !ruby/object:Gem::Version
|
277
|
-
version: '
|
277
|
+
version: '5.1'
|
278
278
|
type: :development
|
279
279
|
prerelease: false
|
280
280
|
version_requirements: !ruby/object:Gem::Requirement
|
281
281
|
requirements:
|
282
282
|
- - "~>"
|
283
283
|
- !ruby/object:Gem::Version
|
284
|
-
version: '
|
284
|
+
version: '5.1'
|
285
285
|
- !ruby/object:Gem::Dependency
|
286
286
|
name: sprockets-rails
|
287
287
|
requirement: !ruby/object:Gem::Requirement
|
288
288
|
requirements:
|
289
289
|
- - "~>"
|
290
290
|
- !ruby/object:Gem::Version
|
291
|
-
version: 3.
|
291
|
+
version: 3.4.2
|
292
292
|
type: :development
|
293
293
|
prerelease: false
|
294
294
|
version_requirements: !ruby/object:Gem::Requirement
|
295
295
|
requirements:
|
296
296
|
- - "~>"
|
297
297
|
- !ruby/object:Gem::Version
|
298
|
-
version: 3.
|
298
|
+
version: 3.4.2
|
299
299
|
- !ruby/object:Gem::Dependency
|
300
300
|
name: yard
|
301
301
|
requirement: !ruby/object:Gem::Requirement
|
@@ -420,7 +420,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
420
420
|
- !ruby/object:Gem::Version
|
421
421
|
version: '0'
|
422
422
|
requirements: []
|
423
|
-
rubygems_version: 3.
|
423
|
+
rubygems_version: 3.4.5
|
424
424
|
signing_key:
|
425
425
|
specification_version: 4
|
426
426
|
summary: A framework for building reusable, testable & encapsulated view components
|