view_component 2.75.0 → 2.77.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/docs/CHANGELOG.md +63 -21
- data/lib/view_component/base.rb +13 -19
- data/lib/view_component/compiler.rb +19 -2
- data/lib/view_component/config.rb +5 -5
- data/lib/view_component/docs_builder_component.html.erb +1 -1
- data/lib/view_component/docs_builder_component.rb +1 -1
- data/lib/view_component/polymorphic_slots.rb +1 -1
- data/lib/view_component/test_helpers.rb +18 -15
- data/lib/view_component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb24cfba68b7323e80beee43cfb7a676ddc833bc87d63201d953d16301defe5d
|
4
|
+
data.tar.gz: 40599c33c49d1dcaa29ae1ec0b6b9e93f191735c2e28207d88717f3f9c77a561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6dd24af9a10eae0a9fc81c18570fe410686bad3db5cbb9840ee0f52038185eff956c64d260b9231d75226ae7e06a7fcdcafcbc4c37214917bf7155b64d2dc59
|
7
|
+
data.tar.gz: 863f21e3be9102ddc02b6a20a7c804b4b1490c7714fbbf2ea848b79a3b5da6cec960afa28fe7bb752e882da6cb4df89a4db67a7d462dfaaf40261b8b2bbf64d1
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,15 +10,57 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
+
## 2.77.0
|
14
|
+
|
15
|
+
* Support variants with dashes in their names.
|
16
|
+
|
17
|
+
*Javi Martín*
|
18
|
+
|
19
|
+
## 2.76.0
|
20
|
+
|
21
|
+
* `Component.with_collection` supports components that accept splatted keyword arguments.
|
22
|
+
|
23
|
+
*Zee Spencer*
|
24
|
+
|
25
|
+
* Remove `config.view_component.use_consistent_rendering_lifecycle` since it is no longer planned for 3.0.
|
26
|
+
|
27
|
+
*Blake Williams*
|
28
|
+
|
29
|
+
* Prevent polymorphic slots from calculating `content` when setting a slot.
|
30
|
+
|
31
|
+
*Blake Williams*
|
32
|
+
|
33
|
+
* Add ability to pass in the preview class to `render_preview`.
|
34
|
+
|
35
|
+
*Jon Rohan*
|
36
|
+
|
37
|
+
* Fix issue causing PVC tests to fail in CI.
|
38
|
+
|
39
|
+
*Cameron Dutro*
|
40
|
+
|
41
|
+
* Fix YARD docs build task.
|
42
|
+
|
43
|
+
*Hans Lemuet*
|
44
|
+
|
45
|
+
* Add Startup Jobs to list of companies using ViewComponent.
|
46
|
+
|
47
|
+
*Marc Köhlbrugge*
|
48
|
+
|
49
|
+
* Run PVC's accessibility tests in a single process to avoid resource contention in CI.
|
50
|
+
|
51
|
+
*Cameron Dutro*
|
52
|
+
|
13
53
|
## 2.75.0
|
14
54
|
|
15
55
|
* Avoid loading ActionView::Base during Rails initialization.
|
16
56
|
|
17
57
|
*Jonathan del Strother*
|
18
58
|
|
59
|
+
<!-- vale off -->
|
19
60
|
* Mention lambda slots rendering returned values lazily in the guide.
|
20
61
|
|
21
62
|
*Graham Rogers*
|
63
|
+
<!-- vale on -->
|
22
64
|
|
23
65
|
* Add "ViewComponent In The Wild" articles to resources.
|
24
66
|
|
@@ -287,7 +329,7 @@ nav_order: 5
|
|
287
329
|
|
288
330
|
* 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
331
|
|
290
|
-
*Joel Hawksley
|
332
|
+
*Joel Hawksley, Blake Williams*
|
291
333
|
|
292
334
|
* Revert change making content evaluation consistent.
|
293
335
|
|
@@ -370,7 +412,7 @@ nav_order: 5
|
|
370
412
|
|
371
413
|
* Add @boardfish and @spone as maintainers.
|
372
414
|
|
373
|
-
*Joel Hawksley
|
415
|
+
*Joel Hawksley, Cameron Dutro, Blake Williams*
|
374
416
|
|
375
417
|
* Re-compile updated, inherited templates when class caching is disabled.
|
376
418
|
|
@@ -430,13 +472,13 @@ nav_order: 5
|
|
430
472
|
|
431
473
|
* Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
|
432
474
|
|
433
|
-
*Tyson Gach
|
475
|
+
*Tyson Gach, Richard Macklin, Joel Hawksley*
|
434
476
|
|
435
477
|
## 2.56.1
|
436
478
|
|
437
479
|
* Rename private accessor `rendered_component` to `rendered_content`.
|
438
480
|
|
439
|
-
*Yoshiyuki Hirano
|
481
|
+
*Yoshiyuki Hirano, Simon Dawson*
|
440
482
|
|
441
483
|
## 2.56.0
|
442
484
|
|
@@ -527,7 +569,7 @@ nav_order: 5
|
|
527
569
|
|
528
570
|
* Skip Rails 5.2 in local test environment if using incompatible Ruby version.
|
529
571
|
|
530
|
-
*Cameron Dutro
|
572
|
+
*Cameron Dutro, Blake Williams, Joel Hawksley*
|
531
573
|
|
532
574
|
* Improve landing page documentation.
|
533
575
|
|
@@ -553,7 +595,7 @@ nav_order: 5
|
|
553
595
|
|
554
596
|
* Add the option to use a "global" output buffer so `form_for` and friends can be used with view components.
|
555
597
|
|
556
|
-
*Cameron Dutro
|
598
|
+
*Cameron Dutro, Blake Williams*
|
557
599
|
|
558
600
|
* Fix fragment caching in partials when global output buffer is enabled.
|
559
601
|
* Fix template inheritance when eager loading is disabled.
|
@@ -690,7 +732,7 @@ nav_order: 5
|
|
690
732
|
|
691
733
|
* Add generators to support `tailwindcss-rails`.
|
692
734
|
|
693
|
-
*Dino Maric
|
735
|
+
*Dino Maric, Hans Lemuet*
|
694
736
|
|
695
737
|
* Add a namespaced component example to docs.
|
696
738
|
|
@@ -871,7 +913,7 @@ nav_order: 5
|
|
871
913
|
|
872
914
|
* Rename internal accessor to use private naming.
|
873
915
|
|
874
|
-
*Joel Hawksley
|
916
|
+
*Joel Hawksley, Blake Williams, Cameron Dutro*
|
875
917
|
|
876
918
|
* Add Github repo link to docs website header.
|
877
919
|
|
@@ -939,7 +981,7 @@ nav_order: 5
|
|
939
981
|
|
940
982
|
* Add support for `image_path` helper in previews.
|
941
983
|
|
942
|
-
*Tobias Ahlin
|
984
|
+
*Tobias Ahlin, Joel Hawksley*
|
943
985
|
|
944
986
|
* Add section to docs listing users of ViewComponent. Please submit a PR to add your team to the list!
|
945
987
|
|
@@ -977,7 +1019,7 @@ nav_order: 5
|
|
977
1019
|
|
978
1020
|
* Fix bug where `helpers` would instantiate and use a new `view_context` in each component.
|
979
1021
|
|
980
|
-
*Blake Williams
|
1022
|
+
*Blake Williams, Ian C. Anderson*
|
981
1023
|
|
982
1024
|
* Implement polymorphic slots as experimental feature. See the Slots documentation to learn more.
|
983
1025
|
|
@@ -1004,7 +1046,7 @@ nav_order: 5
|
|
1004
1046
|
|
1005
1047
|
* Fix bug where `with_collection_parameter` didn't inherit from parent component.
|
1006
1048
|
|
1007
|
-
*Will Drexler
|
1049
|
+
*Will Drexler, Christian Campoli*
|
1008
1050
|
|
1009
1051
|
* Allow query parameters in `with_request_url` test helper.
|
1010
1052
|
|
@@ -1044,7 +1086,7 @@ nav_order: 5
|
|
1044
1086
|
|
1045
1087
|
* Clarify documentation of `with_variant` as an override of Action Pack.
|
1046
1088
|
|
1047
|
-
*Blake Williams
|
1089
|
+
*Blake Williams, Cameron Dutro, Joel Hawksley*
|
1048
1090
|
|
1049
1091
|
* Update docs page to be called Javascript and CSS, rename Building ViewComponents to Guide.
|
1050
1092
|
|
@@ -1069,7 +1111,7 @@ nav_order: 5
|
|
1069
1111
|
|
1070
1112
|
* Clarify slots example in docs to reduce naming confusion.
|
1071
1113
|
|
1072
|
-
*Joel Hawksley
|
1114
|
+
*Joel Hawksley, Blake Williams*
|
1073
1115
|
|
1074
1116
|
* Fix error in documentation for `render_many` passthrough slots.
|
1075
1117
|
|
@@ -1531,7 +1573,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1531
1573
|
|
1532
1574
|
* Add support for templates as ViewComponent::Preview examples.
|
1533
1575
|
|
1534
|
-
*Juan Manuel Ramallo
|
1576
|
+
*Juan Manuel Ramallo*
|
1535
1577
|
|
1536
1578
|
## 2.14.1
|
1537
1579
|
|
@@ -1908,11 +1950,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1908
1950
|
|
1909
1951
|
*Rainer Borene*
|
1910
1952
|
|
1953
|
+
<!-- vale off -->
|
1911
1954
|
* Fix edge case issue with extracting variants from less conventional source_locations.
|
1912
1955
|
|
1913
|
-
<!-- vale proselint.GenderBias = NO -->
|
1914
1956
|
*Ryan Workman*
|
1915
|
-
<!-- vale
|
1957
|
+
<!-- vale on -->
|
1916
1958
|
|
1917
1959
|
## v1.6.0
|
1918
1960
|
|
@@ -1930,7 +1972,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1930
1972
|
|
1931
1973
|
* Template-less variants fall back to default template.
|
1932
1974
|
|
1933
|
-
*Asger Behncke Jacobsen
|
1975
|
+
*Asger Behncke Jacobsen, Cesario Uy*
|
1934
1976
|
|
1935
1977
|
* Generated tests use new naming convention.
|
1936
1978
|
|
@@ -1946,11 +1988,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1946
1988
|
|
1947
1989
|
## v1.5.3
|
1948
1990
|
|
1991
|
+
<!-- vale off -->
|
1949
1992
|
* Add support for RSpec to generators.
|
1950
1993
|
|
1951
|
-
<!-- vale proselint.GenderBias = NO -->
|
1952
1994
|
*Dylan Clark, Ryan Workman*
|
1953
|
-
<!-- vale
|
1995
|
+
<!-- vale on -->
|
1954
1996
|
|
1955
1997
|
* Require controllers as part of setting autoload paths.
|
1956
1998
|
|
@@ -1972,11 +2014,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1972
2014
|
|
1973
2015
|
Note: `actionview-component` is now loaded by requiring `actionview/component`, not `actionview/component/base`.
|
1974
2016
|
|
2017
|
+
<!-- vale off -->
|
1975
2018
|
* Fix issue with generating component method signatures.
|
1976
2019
|
|
1977
|
-
<!-- vale proselint.GenderBias = NO -->
|
1978
2020
|
*Ryan Workman, Dylan Clark*
|
1979
|
-
<!-- vale
|
2021
|
+
<!-- vale off -->
|
1980
2022
|
|
1981
2023
|
* Create component generator.
|
1982
2024
|
|
data/lib/view_component/base.rb
CHANGED
@@ -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
|
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
|
|
@@ -92,7 +92,7 @@ module ViewComponent
|
|
92
92
|
|
93
93
|
def define_render_template_for
|
94
94
|
variant_elsifs = variants.compact.uniq.map do |variant|
|
95
|
-
"elsif variant.to_sym ==
|
95
|
+
"elsif variant.to_sym == :'#{variant}'\n #{call_method_name(variant)}"
|
96
96
|
end.join("\n")
|
97
97
|
|
98
98
|
body = <<-RUBY
|
@@ -163,6 +163,19 @@ module ViewComponent
|
|
163
163
|
"There can only be a template file or inline render method per variant."
|
164
164
|
end
|
165
165
|
|
166
|
+
uniq_variants = variants.compact.uniq
|
167
|
+
normalized_variants = uniq_variants.map { |variant| normalized_variant_name(variant) }
|
168
|
+
|
169
|
+
colliding_variants = uniq_variants.select do |variant|
|
170
|
+
normalized_variants.count(normalized_variant_name(variant)) > 1
|
171
|
+
end
|
172
|
+
|
173
|
+
unless colliding_variants.empty?
|
174
|
+
errors <<
|
175
|
+
"Colliding templates #{colliding_variants.sort.map { |v| "'#{v}'" }.to_sentence} " \
|
176
|
+
"found in #{component_class}."
|
177
|
+
end
|
178
|
+
|
166
179
|
errors
|
167
180
|
end
|
168
181
|
end
|
@@ -234,12 +247,16 @@ module ViewComponent
|
|
234
247
|
|
235
248
|
def call_method_name(variant)
|
236
249
|
if variant.present? && variants.include?(variant)
|
237
|
-
"call_#{variant}"
|
250
|
+
"call_#{normalized_variant_name(variant)}"
|
238
251
|
else
|
239
252
|
"call"
|
240
253
|
end
|
241
254
|
end
|
242
255
|
|
256
|
+
def normalized_variant_name(variant)
|
257
|
+
variant.to_s.gsub("-", "__")
|
258
|
+
end
|
259
|
+
|
243
260
|
def should_compile_superclass?
|
244
261
|
development? &&
|
245
262
|
templates.empty? &&
|
@@ -34,25 +34,25 @@ module ViewComponent
|
|
34
34
|
# All options under this namespace default to `false` unless otherwise
|
35
35
|
# stated.
|
36
36
|
#
|
37
|
-
# ####
|
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
|
-
# ####
|
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
|
-
# ####
|
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
|
-
# ####
|
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
|
-
# ####
|
64
|
+
# #### `#preview`
|
65
65
|
#
|
66
66
|
# Always generate a preview alongside the component:
|
67
67
|
#
|
@@ -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] &&
|
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] = "#{
|
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
|
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.77.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-
|
11
|
+
date: 2022-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|