view_component 2.75.0 → 2.76.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: '0856bb7b57478e7604bb8f129a36448c937907308536649c59dc62a324fb8645'
4
- data.tar.gz: 2211a54534c91373217a438c504d737054e538bb0f019d574eadd705b02b47ae
3
+ metadata.gz: c17ad11c023d788b67aab113d0f09522d73606a41078742b81c0f807ea35aa23
4
+ data.tar.gz: 8d1c75623f80627af69d1cae1859d42b02c21729b45524516a6e76ad8ca63892
5
5
  SHA512:
6
- metadata.gz: 21585851a66d7a087e33a43a24c53284d5dd633703f636d202bf583f19d6c25b31830ebf47e7757ef38fa36ff981144ee16d4fe9d5dbc87eb7c2baddbddd039c
7
- data.tar.gz: f16688c10f6c3fe6928573b199b2313436a8462e7fbb8d94b12aff9a36cde5cbbb090f8f9a2f3561c6dfa2b264192df746bc329bcb899905ca27046e60349d6e
6
+ metadata.gz: 57192b2d9de4714b4ee3ca786e169c02ad654fe7dda69b3e538c1d1f115eff7738326c64d0edbaf78efbb84356a9a5248a940fa0d311c033968a62afc276c76d
7
+ data.tar.gz: 6bac50c320935e1cf1fd17a0ce2d846c1aedc40b63ed9c081a0010f04c5696b1b9b92938997a581df4876c846dbcc3fe2d08e1fc17a593d03842168423e878a6
data/docs/CHANGELOG.md CHANGED
@@ -10,15 +10,51 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 2.76.0
14
+
15
+ * `Component.with_collection` supports components that accept splatted keyword arguments.
16
+
17
+ *Zee Spencer*
18
+
19
+ * Remove `config.view_component.use_consistent_rendering_lifecycle` since it is no longer planned for 3.0.
20
+
21
+ *Blake Williams*
22
+
23
+ * Prevent polymorphic slots from calculating `content` when setting a slot.
24
+
25
+ *Blake Williams*
26
+
27
+ * Add ability to pass in the preview class to `render_preview`.
28
+
29
+ *Jon Rohan*
30
+
31
+ * Fix issue causing PVC tests to fail in CI.
32
+
33
+ *Cameron Dutro*
34
+
35
+ * Fix YARD docs build task.
36
+
37
+ *Hans Lemuet*
38
+
39
+ * Add Startup Jobs to list of companies using ViewComponent.
40
+
41
+ *Marc Köhlbrugge*
42
+
43
+ * Run PVC's accessibility tests in a single process to avoid resource contention in CI.
44
+
45
+ *Cameron Dutro*
46
+
13
47
  ## 2.75.0
14
48
 
15
49
  * Avoid loading ActionView::Base during Rails initialization.
16
50
 
17
51
  *Jonathan del Strother*
18
52
 
53
+ <!-- vale off -->
19
54
  * Mention lambda slots rendering returned values lazily in the guide.
20
55
 
21
56
  *Graham Rogers*
57
+ <!-- vale on -->
22
58
 
23
59
  * Add "ViewComponent In The Wild" articles to resources.
24
60
 
@@ -287,7 +323,7 @@ nav_order: 5
287
323
 
288
324
  * Revert `Expose Capybara DSL methods directly inside tests.` This change unintentionally broke other Capybara methods and thus introduced a regression. We aren't confident that we can fail forward so we have decided to revert this change.
289
325
 
290
- *Joel Hawksley*, *Blake Williams*
326
+ *Joel Hawksley, Blake Williams*
291
327
 
292
328
  * Revert change making content evaluation consistent.
293
329
 
@@ -370,7 +406,7 @@ nav_order: 5
370
406
 
371
407
  * Add @boardfish and @spone as maintainers.
372
408
 
373
- *Joel Hawksley*, *Cameron Dutro*, *Blake Williams*
409
+ *Joel Hawksley, Cameron Dutro, Blake Williams*
374
410
 
375
411
  * Re-compile updated, inherited templates when class caching is disabled.
376
412
 
@@ -430,13 +466,13 @@ nav_order: 5
430
466
 
431
467
  * Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
432
468
 
433
- *Tyson Gach*, *Richard Macklin*, *Joel Hawksley*
469
+ *Tyson Gach, Richard Macklin, Joel Hawksley*
434
470
 
435
471
  ## 2.56.1
436
472
 
437
473
  * Rename private accessor `rendered_component` to `rendered_content`.
438
474
 
439
- *Yoshiyuki Hirano*, *Simon Dawson*
475
+ *Yoshiyuki Hirano, Simon Dawson*
440
476
 
441
477
  ## 2.56.0
442
478
 
@@ -527,7 +563,7 @@ nav_order: 5
527
563
 
528
564
  * Skip Rails 5.2 in local test environment if using incompatible Ruby version.
529
565
 
530
- *Cameron Dutro*, *Blake Williams*, *Joel Hawksley*
566
+ *Cameron Dutro, Blake Williams, Joel Hawksley*
531
567
 
532
568
  * Improve landing page documentation.
533
569
 
@@ -553,7 +589,7 @@ nav_order: 5
553
589
 
554
590
  * Add the option to use a "global" output buffer so `form_for` and friends can be used with view components.
555
591
 
556
- *Cameron Dutro*, *Blake Williams*
592
+ *Cameron Dutro, Blake Williams*
557
593
 
558
594
  * Fix fragment caching in partials when global output buffer is enabled.
559
595
  * Fix template inheritance when eager loading is disabled.
@@ -690,7 +726,7 @@ nav_order: 5
690
726
 
691
727
  * Add generators to support `tailwindcss-rails`.
692
728
 
693
- *Dino Maric*, *Hans Lemuet*
729
+ *Dino Maric, Hans Lemuet*
694
730
 
695
731
  * Add a namespaced component example to docs.
696
732
 
@@ -871,7 +907,7 @@ nav_order: 5
871
907
 
872
908
  * Rename internal accessor to use private naming.
873
909
 
874
- *Joel Hawksley*, *Blake Williams*, *Cameron Dutro*
910
+ *Joel Hawksley, Blake Williams, Cameron Dutro*
875
911
 
876
912
  * Add Github repo link to docs website header.
877
913
 
@@ -939,7 +975,7 @@ nav_order: 5
939
975
 
940
976
  * Add support for `image_path` helper in previews.
941
977
 
942
- *Tobias Ahlin*, *Joel Hawksley*
978
+ *Tobias Ahlin, Joel Hawksley*
943
979
 
944
980
  * Add section to docs listing users of ViewComponent. Please submit a PR to add your team to the list!
945
981
 
@@ -977,7 +1013,7 @@ nav_order: 5
977
1013
 
978
1014
  * Fix bug where `helpers` would instantiate and use a new `view_context` in each component.
979
1015
 
980
- *Blake Williams*, *Ian C. Anderson*
1016
+ *Blake Williams, Ian C. Anderson*
981
1017
 
982
1018
  * Implement polymorphic slots as experimental feature. See the Slots documentation to learn more.
983
1019
 
@@ -1004,7 +1040,7 @@ nav_order: 5
1004
1040
 
1005
1041
  * Fix bug where `with_collection_parameter` didn't inherit from parent component.
1006
1042
 
1007
- *Will Drexler*, *Christian Campoli*
1043
+ *Will Drexler, Christian Campoli*
1008
1044
 
1009
1045
  * Allow query parameters in `with_request_url` test helper.
1010
1046
 
@@ -1044,7 +1080,7 @@ nav_order: 5
1044
1080
 
1045
1081
  * Clarify documentation of `with_variant` as an override of Action Pack.
1046
1082
 
1047
- *Blake Williams*, *Cameron Dutro*, *Joel Hawksley*
1083
+ *Blake Williams, Cameron Dutro, Joel Hawksley*
1048
1084
 
1049
1085
  * Update docs page to be called Javascript and CSS, rename Building ViewComponents to Guide.
1050
1086
 
@@ -1069,7 +1105,7 @@ nav_order: 5
1069
1105
 
1070
1106
  * Clarify slots example in docs to reduce naming confusion.
1071
1107
 
1072
- *Joel Hawksley*, *Blake Williams*
1108
+ *Joel Hawksley, Blake Williams*
1073
1109
 
1074
1110
  * Fix error in documentation for `render_many` passthrough slots.
1075
1111
 
@@ -1531,7 +1567,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
1531
1567
 
1532
1568
  * Add support for templates as ViewComponent::Preview examples.
1533
1569
 
1534
- *Juan Manuel Ramallo
1570
+ *Juan Manuel Ramallo*
1535
1571
 
1536
1572
  ## 2.14.1
1537
1573
 
@@ -1908,11 +1944,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
1908
1944
 
1909
1945
  *Rainer Borene*
1910
1946
 
1947
+ <!-- vale off -->
1911
1948
  * Fix edge case issue with extracting variants from less conventional source_locations.
1912
1949
 
1913
- <!-- vale proselint.GenderBias = NO -->
1914
1950
  *Ryan Workman*
1915
- <!-- vale proselint.GenderBias = YES -->
1951
+ <!-- vale on -->
1916
1952
 
1917
1953
  ## v1.6.0
1918
1954
 
@@ -1930,7 +1966,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
1930
1966
 
1931
1967
  * Template-less variants fall back to default template.
1932
1968
 
1933
- *Asger Behncke Jacobsen*, *Cesario Uy*
1969
+ *Asger Behncke Jacobsen, Cesario Uy*
1934
1970
 
1935
1971
  * Generated tests use new naming convention.
1936
1972
 
@@ -1946,11 +1982,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
1946
1982
 
1947
1983
  ## v1.5.3
1948
1984
 
1985
+ <!-- vale off -->
1949
1986
  * Add support for RSpec to generators.
1950
1987
 
1951
- <!-- vale proselint.GenderBias = NO -->
1952
1988
  *Dylan Clark, Ryan Workman*
1953
- <!-- vale proselint.GenderBias = YES -->
1989
+ <!-- vale on -->
1954
1990
 
1955
1991
  * Require controllers as part of setting autoload paths.
1956
1992
 
@@ -1972,11 +2008,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
1972
2008
 
1973
2009
  Note: `actionview-component` is now loaded by requiring `actionview/component`, not `actionview/component/base`.
1974
2010
 
2011
+ <!-- vale off -->
1975
2012
  * Fix issue with generating component method signatures.
1976
2013
 
1977
- <!-- vale proselint.GenderBias = NO -->
1978
2014
  *Ryan Workman, Dylan Clark*
1979
- <!-- vale proselint.GenderBias = YES -->
2015
+ <!-- vale off -->
1980
2016
 
1981
2017
  * Create component generator.
1982
2018
 
@@ -19,9 +19,15 @@ module ViewComponent
19
19
  class << self
20
20
  delegate(*ViewComponent::Config.defaults.keys, to: :config)
21
21
 
22
+ # Returns the current config.
23
+ #
24
+ # @return [ViewComponent::Config]
22
25
  def config
23
26
  @config ||= ActiveSupport::OrderedOptions.new
24
27
  end
28
+
29
+ # Replaces the entire config. You shouldn't need to use this directly
30
+ # unless you're building a `ViewComponent::Config` elsewhere.
25
31
  attr_writer :config
26
32
  end
27
33
 
@@ -124,11 +130,6 @@ module ViewComponent
124
130
  before_render
125
131
 
126
132
  if render?
127
- # Ensure `content` is evaluated before rendering the template, this is
128
- # needed so slots and other side-effects are performed before the
129
- # component template is evaluated.
130
- content if self.class.use_consistent_rendering_lifecycle
131
-
132
133
  render_template_for(@__vc_variant).to_s + output_postamble
133
134
  else
134
135
  ""
@@ -334,18 +335,6 @@ module ViewComponent
334
335
  # Defaults to `nil`. If this is falsy, `app/components` is used.
335
336
  #
336
337
 
337
- # Evaluate `#content` before `#call` to ensure side-effects are present
338
- # during component renders. This will be the default behavior in a future
339
- # release.
340
- #
341
- # ```ruby
342
- # config.view_component.use_consistent_rendering_lifecycle = true
343
- # ```
344
- #
345
- # Defaults to `false`
346
- #
347
- mattr_accessor :use_consistent_rendering_lifecycle, instance_writer: false, default: false
348
-
349
338
  # Parent class for generated components
350
339
  #
351
340
  # ```ruby
@@ -413,7 +402,7 @@ module ViewComponent
413
402
  # Find sidecar files for the given extensions.
414
403
  #
415
404
  # The provided array of extensions is expected to contain
416
- # strings starting without the "dot", example: `["erb", "haml"]`.
405
+ # strings starting without the dot, example: `["erb", "haml"]`.
417
406
  #
418
407
  # For example, one might collect sidecar CSS files that need to be compiled.
419
408
  # @param extensions [Array<String>] Extensions of which to return matching sidecar files.
@@ -591,7 +580,7 @@ module ViewComponent
591
580
  parameter = validate_default ? collection_parameter : provided_collection_parameter
592
581
 
593
582
  return unless parameter
594
- return if initialize_parameter_names.include?(parameter)
583
+ return if initialize_parameter_names.include?(parameter) || splatted_keyword_argument_present?
595
584
 
596
585
  # If Ruby can't parse the component class, then the initalize
597
586
  # parameters will be empty and ViewComponent will not be able to render
@@ -647,6 +636,11 @@ module ViewComponent
647
636
 
648
637
  private
649
638
 
639
+ def splatted_keyword_argument_present?
640
+ initialize_parameters.flatten.include?(:keyrest) &&
641
+ !initialize_parameters.include?([:keyrest, :**]) # Un-named splatted keyword args don't count!
642
+ end
643
+
650
644
  def initialize_parameter_names
651
645
  return attribute_names.map(&:to_sym) if respond_to?(:attribute_names)
652
646
 
@@ -34,25 +34,25 @@ module ViewComponent
34
34
  # All options under this namespace default to `false` unless otherwise
35
35
  # stated.
36
36
  #
37
- # #### #sidecar
37
+ # #### `#sidecar`
38
38
  #
39
39
  # Always generate a component with a sidecar directory:
40
40
  #
41
41
  # config.view_component.generate.sidecar = true
42
42
  #
43
- # #### #stimulus_controller
43
+ # #### `#stimulus_controller`
44
44
  #
45
45
  # Always generate a Stimulus controller alongside the component:
46
46
  #
47
47
  # config.view_component.generate.stimulus_controller = true
48
48
  #
49
- # #### #locale
49
+ # #### `#locale`
50
50
  #
51
51
  # Always generate translations file alongside the component:
52
52
  #
53
53
  # config.view_component.generate.locale = true
54
54
  #
55
- # #### #distinct_locale_files
55
+ # #### `#distinct_locale_files`
56
56
  #
57
57
  # Always generate as many translations files as available locales:
58
58
  #
@@ -61,7 +61,7 @@ module ViewComponent
61
61
  # One file will be generated for each configured `I18n.available_locales`,
62
62
  # falling back to `[:en]` when no `available_locales` is defined.
63
63
  #
64
- # #### #preview
64
+ # #### `#preview`
65
65
  #
66
66
  # Always generate a preview alongside the component:
67
67
  #
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  layout: default
3
- title: API
3
+ title: API reference
4
4
  nav_order: 3
5
5
  ---
6
6
 
@@ -57,7 +57,7 @@ module ViewComponent
57
57
 
58
58
  def call
59
59
  <<~DOCS.chomp
60
- #{separator}#{signature_or_name}#{types}#{suffix}
60
+ `#{separator}#{signature_or_name}`#{types}#{suffix}
61
61
 
62
62
  #{docstring_and_deprecation_text}
63
63
  DOCS
@@ -89,7 +89,7 @@ module ViewComponent
89
89
  def set_polymorphic_slot(slot_name, poly_type = nil, *args, &block)
90
90
  slot_definition = self.class.registered_slots[slot_name]
91
91
 
92
- if !slot_definition[:collection] && get_slot(slot_name)
92
+ if !slot_definition[:collection] && (defined?(@__vc_set_slots) && @__vc_set_slots[slot_name])
93
93
  raise ArgumentError, "content for slot '#{slot_name}' has already been provided"
94
94
  end
95
95
 
@@ -81,22 +81,10 @@ module ViewComponent
81
81
  # In RSpec, `Preview` is appended to `described_class`.
82
82
  #
83
83
  # @param name [String] The name of the preview to be rendered.
84
+ # @param from [ViewComponent::Preview] The class of the preview to be rendered.
84
85
  # @param params [Hash] Parameters to be passed to the preview.
85
86
  # @return [Nokogiri::HTML]
86
- def render_preview(name, params: {})
87
- begin
88
- preview_klass = if respond_to?(:described_class)
89
- raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
90
-
91
- "#{described_class}Preview"
92
- else
93
- self.class.name.gsub("Test", "Preview")
94
- end
95
- preview_klass = preview_klass.constantize
96
- rescue NameError
97
- raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
98
- end
99
-
87
+ def render_preview(name, from: preview_class, params: {})
100
88
  previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
101
89
 
102
90
  # From what I can tell, it's not possible to overwrite all request parameters
@@ -105,7 +93,7 @@ module ViewComponent
105
93
  previews_controller.request.params[k] = v
106
94
  end
107
95
 
108
- previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
96
+ previews_controller.request.params[:path] = "#{from.preview_name}/#{name}"
109
97
  previews_controller.response = ActionDispatch::Response.new
110
98
  result = previews_controller.previews
111
99
 
@@ -216,5 +204,20 @@ module ViewComponent
216
204
  def build_controller(klass)
217
205
  klass.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers)
218
206
  end
207
+
208
+ private
209
+
210
+ def preview_class
211
+ result = if respond_to?(:described_class)
212
+ raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
213
+
214
+ "#{described_class}Preview"
215
+ else
216
+ self.class.name.gsub("Test", "Preview")
217
+ end
218
+ result = result.constantize
219
+ rescue NameError
220
+ raise NameError, "`render_preview` expected to find #{result}, but it does not exist."
221
+ end
219
222
  end
220
223
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 75
6
+ MINOR = 76
7
7
  PATCH = 0
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.75.0
4
+ version: 2.76.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: 2022-11-02 00:00:00.000000000 Z
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport