view_component 3.0.0 → 3.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 639cd1c50a78567738c9d90363e98cb740f1f45ca70c9cb7ea20d22aacbce6e9
4
- data.tar.gz: cbec2597e6193dcb43ddab199d1147977d505dd320b765ed38eb11f877917f23
3
+ metadata.gz: e505722b47ce320345cbb123e06e5138362a3b9abc5fe8cc77c5849a71e8baf5
4
+ data.tar.gz: c9f053e92c067b2743ae64d8135334518a14933710c81ad68e058d0cd076b610
5
5
  SHA512:
6
- metadata.gz: b26863964af13fd7c3bca798f4acd88c87709965badda42b02fe8125151f6e91b879e5118551d5b4c041509bbe26c2d463fcd4470bf6cbe5f946bc99c34f6a9c
7
- data.tar.gz: e170eae333570563f5e068e8cbc1c4cfab05363671a9691169eaa2cbb30202076d38d8b59b8d7b28a73ab8777542c9173455e6f828f5f7344a3213424a69d049
6
+ metadata.gz: 3e3aab08e8665557c94e0f8df5c7f0f484b056bc9e0a85247a7d718cedfc3ff8aa3a2a6875fd4660626b15c0f6e002ac50797fdcce822f610ca91581afff8c9e
7
+ data.tar.gz: 2f25ccc3bcfefb4e3096a5c9289922b648353ba42c333ad963d59cc95f8bd1cf4d1db0f178494ad6cb4a59af6832a852b3b15f34f80dc3c2ebfa6cf78d65b445
@@ -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,58 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 3.2.0
14
+
15
+ * Fix viewcomponent.org Axe violations.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Fix example of RSpec configuration in docs
20
+
21
+ *Pasha Kalashnikov*
22
+
23
+ * Add URL helpers to previews
24
+
25
+ *Reegan Viljoen*
26
+
27
+ ## 3.1.0
28
+
29
+ * Check `defined?(Rails) && Rails.application` before using `ViewComponent::Base.config.view_component_path`.
30
+
31
+ *Donapieppo*
32
+
33
+ * Allow customization of polymorphic slot setters.
34
+
35
+ *Cameron Dutro*
36
+
37
+ * Fix duplication in configuration docs.
38
+
39
+ *Tom Chen*
40
+
41
+ * Fix helpers not reloading in development.
42
+
43
+ *Jonathan del Strother*
44
+
45
+ * Add `SECURITY.md`.
46
+
47
+ *Joel Hawksley*
48
+
49
+ * Add Ophelos to list of companies using ViewComponent.
50
+
51
+ *Graham Rogers*
52
+
53
+ * Add FlightLogger to list of companies using ViewComponent.
54
+
55
+ *Joseph Carpenter*
56
+
57
+ * Fix coverage reports overwriting each other when running locally.
58
+
59
+ *Jonathan del Strother*
60
+
61
+ * Add @reeganviljoen to triage team.
62
+
63
+ *Reegan Viljoen*
64
+
13
65
  ### v3.0.0
14
66
 
15
67
  1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
@@ -86,6 +138,10 @@ This release makes the following breaking changes, many of which have long been
86
138
 
87
139
  *Joel Hawksley*
88
140
 
141
+ * Add support for CSP nonces inside of components.
142
+
143
+ *Reegan Viljoen*
144
+
89
145
  ### v3.0.0.rc6
90
146
 
91
147
  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!
@@ -19,7 +19,7 @@ module ViewComponent
19
19
 
20
20
  # Returns the current config.
21
21
  #
22
- # @return [ViewComponent::Config]
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
- # Removes the first part of the path and the extension.
448
- child.virtual_path = child.source_location.gsub(
449
- /(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
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
@@ -4,6 +4,7 @@ require "active_support/descendants_tracker"
4
4
 
5
5
  module ViewComponent # :nodoc:
6
6
  class Preview
7
+ include Rails.application.routes.url_helpers
7
8
  include ActionView::Helpers::TagHelper
8
9
  include ActionView::Helpers::AssetTagHelper
9
10
  extend ActiveSupport::DescendantsTracker
@@ -97,7 +97,9 @@ module ViewComponent
97
97
  ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
98
98
 
99
99
  def html_safe?
100
+ # :nocov:
100
101
  to_s.html_safe?
102
+ # :nocov:
101
103
  end
102
104
 
103
105
  def respond_to_missing?(symbol, include_all = false)
@@ -206,38 +206,46 @@ module ViewComponent
206
206
  end
207
207
 
208
208
  def register_polymorphic_slot(slot_name, types, collection:)
209
- unless types.empty?
210
- getter_name = slot_name
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
- define_method("#{getter_name}?") do
217
- get_slot(slot_name).present?
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, poly_callable), memo|
222
- memo[poly_type] = define_slot(
223
- "#{slot_name}_#{poly_type}", collection: collection, callable: poly_callable
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
- setter_name =
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
- setter_method_name = :"with_#{setter_name}"
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_#{setter_name}_content" do |content|
248
+ define_method "with_#{poly_slot_name}_content" do |content|
241
249
  send(setter_method_name) { content.to_s }
242
250
 
243
251
  self
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 0
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
  PRE = nil
9
9
 
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.0.0
4
+ version: 3.2.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-04-24 00:00:00.000000000 Z
11
+ date: 2023-06-12 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.8.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.8.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: '5'
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: '5'
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.6.0
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.6.0
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.18.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.18.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.7.2
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.7.2
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: '4.0'
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: '4.0'
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.2.2
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.2.2
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.2.32
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