view_component 3.0.0.rc6 → 3.1.0

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: d82093cc048c5af21538ee6ec01aa2ef474b71b97d2cae0fd02413f036b97616
4
- data.tar.gz: 376d3bf8597d3eccd871ab9f8f1fa71a55f9564e44f7fcf920115c50e89b6224
3
+ metadata.gz: ca112c2d340e4ade9bd258d515edafbd1cc66e0b19097acd12d3eab53b9ae4a4
4
+ data.tar.gz: 173223c31abaf369bbfb455eff47137dfa6b7ac98485b17ba58c8317d6f5c3e5
5
5
  SHA512:
6
- metadata.gz: e410d228fd97a8007d50f7a4bfc262c20481ac3e1279f7e2cfada131fb475ca65991e99a2af6ee059c16dea38913974c72aca62d1d4c1d4530dcce8c13159721
7
- data.tar.gz: 1d7bccb010f977dde4435af3aab5c4df57af2157684b924dea54b43b788d3624d1a914e15602f138184d9c222e9a43c80c2088c95b34269a8d994ec6eb5058c7
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,124 @@ 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
+
51
+ ### v3.0.0
52
+
53
+ 1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
54
+
55
+ We're so grateful for all the work of community members to get us to this release. Whether it’s filing bug reports, designing APIs in long-winded discussion threads, or writing code itself, ViewComponent is built by the community, for the community. We couldn’t be more proud of what we’re building together :heart:
56
+
57
+ This release makes the following breaking changes, many of which have long been deprecated:
58
+
59
+ * BREAKING: Remove deprecated slots setter methods. Use `with_SLOT_NAME` instead.
60
+
61
+ *Joel Hawksley*
62
+
63
+ * BREAKING: Remove deprecated SlotsV1 in favor of current SlotsV2.
64
+
65
+ *Joel Hawksley*
66
+
67
+ * BREAKING: Remove deprecated `content_areas` feature. Use Slots instead.
68
+
69
+ *Joel Hawksley*
70
+
71
+ * BREAKING: Remove deprecated support for loading ViewComponent engine manually. Make sure `require "view_component/engine"` is removed from `Gemfile`.
72
+
73
+ *Joel Hawksley*
74
+
75
+ * BREAKING: Remove deprecated `generate_*` methods. Use `generate.*` instead.
76
+
77
+ *Joel Hawksley*
78
+
79
+ * BREAKING: Remove deprecated `with_variant` method.
80
+
81
+ *Joel Hawksley*
82
+
83
+ * BREAKING: Remove deprecated `rendered_component` in favor of `rendered_content`.
84
+
85
+ *Joel Hawksley*
86
+
87
+ * BREAKING: Remove deprecated `config.preview_path` in favor of `config.preview_paths`.
88
+
89
+ *Joel Hawksley*
90
+
91
+ * BREAKING: Support Ruby 2.7+ instead of 2.4+
92
+
93
+ *Joel Hawksley*
94
+
95
+ * BREAKING: Remove deprecated `before_render_check`.
96
+
97
+ *Joel Hawksley*
98
+
99
+ * BREAKING: Change counter variable to start iterating from `0` instead of `1`.
100
+
101
+ *Frank S*
102
+
103
+ * BREAKING: `#SLOT_NAME` getter no longer accepts arguments. This change was missed as part of the earlier deprecation in `3.0.0.rc1`.
104
+
105
+ *Joel Hawksley*
106
+
107
+ * BREAKING: Raise `TranslateCalledBeforeRenderError`, `ControllerCalledBeforeRenderError`, or `HelpersCalledBeforeRenderError` instead of `ViewContextCalledBeforeRenderError`.
108
+
109
+ *Joel Hawksley*
110
+
111
+ * BREAKING: Raise `SlotPredicateNameError`, `RedefinedSlotError`, `ReservedSingularSlotNameError`, `ContentSlotNameError`, `InvalidSlotDefinitionError`, `ReservedPluralSlotNameError`, `ContentAlreadySetForPolymorphicSlotErrror`, `SystemTestControllerOnlyAllowedInTestError`, `SystemTestControllerNefariousPathError`, `NoMatchingTemplatesForPreviewError`, `MultipleMatchingTemplatesForPreviewError`, `DuplicateContentError`, `EmptyOrInvalidInitializerError`, `MissingCollectionArgumentError`, `ReservedParameterError`, `InvalidCollectionArgumentError`, `MultipleInlineTemplatesError`, `MissingPreviewTemplateError`, `DuplicateSlotContentError` or `NilWithContentError` instead of generic error classes.
112
+
113
+ *Joel Hawksley*
114
+
115
+ * BREAKING: Rename `SlotV2` to `Slot` and `SlotableV2` to `Slotable`.
116
+
117
+ *Joel Hawksley*
118
+
119
+ * BREAKING: Incorporate `PolymorphicSlots` into `Slotable`. To migrate, remove any references to `PolymorphicSlots` as they are no longer necessary.
120
+
121
+ *Joel Hawksley*
122
+
123
+ * BREAKING: Rename private TestHelpers#controller, #build_controller, #request, and #preview_class to avoid conflicts. Note: While these methods were undocumented and marked as private, they were accessible in tests. As such, we're considering this to be a breaking change.
124
+
125
+ *Joel Hawksley*
126
+
127
+ * Add support for CSP nonces inside of components.
128
+
129
+ *Reegan Viljoen*
130
+
13
131
  ### v3.0.0.rc6
14
132
 
15
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!
@@ -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
@@ -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,9 +3,9 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 3
6
- MINOR = 0
6
+ MINOR = 1
7
7
  PATCH = 0
8
- PRE = "rc6"
8
+ PRE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  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: 3.0.0.rc6
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-04-12 00:00:00.000000000 Z
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.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
@@ -416,11 +416,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
416
416
  version: 2.7.0
417
417
  required_rubygems_version: !ruby/object:Gem::Requirement
418
418
  requirements:
419
- - - ">"
419
+ - - ">="
420
420
  - !ruby/object:Gem::Version
421
- version: 1.3.1
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