view_component 2.74.1 → 2.76.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 +71 -21
- data/lib/view_component/base.rb +15 -20
- 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/engine.rb +4 -5
- data/lib/view_component/polymorphic_slots.rb +1 -1
- data/lib/view_component/test_helpers.rb +18 -15
- data/lib/view_component/version.rb +2 -2
- 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: c17ad11c023d788b67aab113d0f09522d73606a41078742b81c0f807ea35aa23
|
4
|
+
data.tar.gz: 8d1c75623f80627af69d1cae1859d42b02c21729b45524516a6e76ad8ca63892
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57192b2d9de4714b4ee3ca786e169c02ad654fe7dda69b3e538c1d1f115eff7738326c64d0edbaf78efbb84356a9a5248a940fa0d311c033968a62afc276c76d
|
7
|
+
data.tar.gz: 6bac50c320935e1cf1fd17a0ce2d846c1aedc40b63ed9c081a0010f04c5696b1b9b92938997a581df4876c846dbcc3fe2d08e1fc17a593d03842168423e878a6
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,6 +10,56 @@ 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
|
+
|
47
|
+
## 2.75.0
|
48
|
+
|
49
|
+
* Avoid loading ActionView::Base during Rails initialization.
|
50
|
+
|
51
|
+
*Jonathan del Strother*
|
52
|
+
|
53
|
+
<!-- vale off -->
|
54
|
+
* Mention lambda slots rendering returned values lazily in the guide.
|
55
|
+
|
56
|
+
*Graham Rogers*
|
57
|
+
<!-- vale on -->
|
58
|
+
|
59
|
+
* Add "ViewComponent In The Wild" articles to resources.
|
60
|
+
|
61
|
+
*Alexander Baygeldin*
|
62
|
+
|
13
63
|
## 2.74.1
|
14
64
|
|
15
65
|
* Add more users of ViewComponent to docs.
|
@@ -273,7 +323,7 @@ nav_order: 5
|
|
273
323
|
|
274
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.
|
275
325
|
|
276
|
-
*Joel Hawksley
|
326
|
+
*Joel Hawksley, Blake Williams*
|
277
327
|
|
278
328
|
* Revert change making content evaluation consistent.
|
279
329
|
|
@@ -356,7 +406,7 @@ nav_order: 5
|
|
356
406
|
|
357
407
|
* Add @boardfish and @spone as maintainers.
|
358
408
|
|
359
|
-
*Joel Hawksley
|
409
|
+
*Joel Hawksley, Cameron Dutro, Blake Williams*
|
360
410
|
|
361
411
|
* Re-compile updated, inherited templates when class caching is disabled.
|
362
412
|
|
@@ -416,13 +466,13 @@ nav_order: 5
|
|
416
466
|
|
417
467
|
* Restore removed `rendered_component`, marking it for deprecation in v3.0.0.
|
418
468
|
|
419
|
-
*Tyson Gach
|
469
|
+
*Tyson Gach, Richard Macklin, Joel Hawksley*
|
420
470
|
|
421
471
|
## 2.56.1
|
422
472
|
|
423
473
|
* Rename private accessor `rendered_component` to `rendered_content`.
|
424
474
|
|
425
|
-
*Yoshiyuki Hirano
|
475
|
+
*Yoshiyuki Hirano, Simon Dawson*
|
426
476
|
|
427
477
|
## 2.56.0
|
428
478
|
|
@@ -513,7 +563,7 @@ nav_order: 5
|
|
513
563
|
|
514
564
|
* Skip Rails 5.2 in local test environment if using incompatible Ruby version.
|
515
565
|
|
516
|
-
*Cameron Dutro
|
566
|
+
*Cameron Dutro, Blake Williams, Joel Hawksley*
|
517
567
|
|
518
568
|
* Improve landing page documentation.
|
519
569
|
|
@@ -539,7 +589,7 @@ nav_order: 5
|
|
539
589
|
|
540
590
|
* Add the option to use a "global" output buffer so `form_for` and friends can be used with view components.
|
541
591
|
|
542
|
-
*Cameron Dutro
|
592
|
+
*Cameron Dutro, Blake Williams*
|
543
593
|
|
544
594
|
* Fix fragment caching in partials when global output buffer is enabled.
|
545
595
|
* Fix template inheritance when eager loading is disabled.
|
@@ -676,7 +726,7 @@ nav_order: 5
|
|
676
726
|
|
677
727
|
* Add generators to support `tailwindcss-rails`.
|
678
728
|
|
679
|
-
*Dino Maric
|
729
|
+
*Dino Maric, Hans Lemuet*
|
680
730
|
|
681
731
|
* Add a namespaced component example to docs.
|
682
732
|
|
@@ -857,7 +907,7 @@ nav_order: 5
|
|
857
907
|
|
858
908
|
* Rename internal accessor to use private naming.
|
859
909
|
|
860
|
-
*Joel Hawksley
|
910
|
+
*Joel Hawksley, Blake Williams, Cameron Dutro*
|
861
911
|
|
862
912
|
* Add Github repo link to docs website header.
|
863
913
|
|
@@ -925,7 +975,7 @@ nav_order: 5
|
|
925
975
|
|
926
976
|
* Add support for `image_path` helper in previews.
|
927
977
|
|
928
|
-
*Tobias Ahlin
|
978
|
+
*Tobias Ahlin, Joel Hawksley*
|
929
979
|
|
930
980
|
* Add section to docs listing users of ViewComponent. Please submit a PR to add your team to the list!
|
931
981
|
|
@@ -963,7 +1013,7 @@ nav_order: 5
|
|
963
1013
|
|
964
1014
|
* Fix bug where `helpers` would instantiate and use a new `view_context` in each component.
|
965
1015
|
|
966
|
-
*Blake Williams
|
1016
|
+
*Blake Williams, Ian C. Anderson*
|
967
1017
|
|
968
1018
|
* Implement polymorphic slots as experimental feature. See the Slots documentation to learn more.
|
969
1019
|
|
@@ -990,7 +1040,7 @@ nav_order: 5
|
|
990
1040
|
|
991
1041
|
* Fix bug where `with_collection_parameter` didn't inherit from parent component.
|
992
1042
|
|
993
|
-
*Will Drexler
|
1043
|
+
*Will Drexler, Christian Campoli*
|
994
1044
|
|
995
1045
|
* Allow query parameters in `with_request_url` test helper.
|
996
1046
|
|
@@ -1030,7 +1080,7 @@ nav_order: 5
|
|
1030
1080
|
|
1031
1081
|
* Clarify documentation of `with_variant` as an override of Action Pack.
|
1032
1082
|
|
1033
|
-
*Blake Williams
|
1083
|
+
*Blake Williams, Cameron Dutro, Joel Hawksley*
|
1034
1084
|
|
1035
1085
|
* Update docs page to be called Javascript and CSS, rename Building ViewComponents to Guide.
|
1036
1086
|
|
@@ -1055,7 +1105,7 @@ nav_order: 5
|
|
1055
1105
|
|
1056
1106
|
* Clarify slots example in docs to reduce naming confusion.
|
1057
1107
|
|
1058
|
-
*Joel Hawksley
|
1108
|
+
*Joel Hawksley, Blake Williams*
|
1059
1109
|
|
1060
1110
|
* Fix error in documentation for `render_many` passthrough slots.
|
1061
1111
|
|
@@ -1517,7 +1567,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1517
1567
|
|
1518
1568
|
* Add support for templates as ViewComponent::Preview examples.
|
1519
1569
|
|
1520
|
-
*Juan Manuel Ramallo
|
1570
|
+
*Juan Manuel Ramallo*
|
1521
1571
|
|
1522
1572
|
## 2.14.1
|
1523
1573
|
|
@@ -1894,11 +1944,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1894
1944
|
|
1895
1945
|
*Rainer Borene*
|
1896
1946
|
|
1947
|
+
<!-- vale off -->
|
1897
1948
|
* Fix edge case issue with extracting variants from less conventional source_locations.
|
1898
1949
|
|
1899
|
-
<!-- vale proselint.GenderBias = NO -->
|
1900
1950
|
*Ryan Workman*
|
1901
|
-
<!-- vale
|
1951
|
+
<!-- vale on -->
|
1902
1952
|
|
1903
1953
|
## v1.6.0
|
1904
1954
|
|
@@ -1916,7 +1966,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1916
1966
|
|
1917
1967
|
* Template-less variants fall back to default template.
|
1918
1968
|
|
1919
|
-
*Asger Behncke Jacobsen
|
1969
|
+
*Asger Behncke Jacobsen, Cesario Uy*
|
1920
1970
|
|
1921
1971
|
* Generated tests use new naming convention.
|
1922
1972
|
|
@@ -1932,11 +1982,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1932
1982
|
|
1933
1983
|
## v1.5.3
|
1934
1984
|
|
1985
|
+
<!-- vale off -->
|
1935
1986
|
* Add support for RSpec to generators.
|
1936
1987
|
|
1937
|
-
<!-- vale proselint.GenderBias = NO -->
|
1938
1988
|
*Dylan Clark, Ryan Workman*
|
1939
|
-
<!-- vale
|
1989
|
+
<!-- vale on -->
|
1940
1990
|
|
1941
1991
|
* Require controllers as part of setting autoload paths.
|
1942
1992
|
|
@@ -1958,11 +2008,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
1958
2008
|
|
1959
2009
|
Note: `actionview-component` is now loaded by requiring `actionview/component`, not `actionview/component/base`.
|
1960
2010
|
|
2011
|
+
<!-- vale off -->
|
1961
2012
|
* Fix issue with generating component method signatures.
|
1962
2013
|
|
1963
|
-
<!-- vale proselint.GenderBias = NO -->
|
1964
2014
|
*Ryan Workman, Dylan Clark*
|
1965
|
-
<!-- vale
|
2015
|
+
<!-- vale off -->
|
1966
2016
|
|
1967
2017
|
* Create component generator.
|
1968
2018
|
|
data/lib/view_component/base.rb
CHANGED
@@ -19,9 +19,16 @@ 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
|
-
@config ||=
|
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.
|
31
|
+
attr_writer :config
|
25
32
|
end
|
26
33
|
|
27
34
|
include ViewComponent::ContentAreas
|
@@ -123,11 +130,6 @@ module ViewComponent
|
|
123
130
|
before_render
|
124
131
|
|
125
132
|
if render?
|
126
|
-
# Ensure `content` is evaluated before rendering the template, this is
|
127
|
-
# needed so slots and other side-effects are performed before the
|
128
|
-
# component template is evaluated.
|
129
|
-
content if self.class.use_consistent_rendering_lifecycle
|
130
|
-
|
131
133
|
render_template_for(@__vc_variant).to_s + output_postamble
|
132
134
|
else
|
133
135
|
""
|
@@ -333,18 +335,6 @@ module ViewComponent
|
|
333
335
|
# Defaults to `nil`. If this is falsy, `app/components` is used.
|
334
336
|
#
|
335
337
|
|
336
|
-
# Evaluate `#content` before `#call` to ensure side-effects are present
|
337
|
-
# during component renders. This will be the default behavior in a future
|
338
|
-
# release.
|
339
|
-
#
|
340
|
-
# ```ruby
|
341
|
-
# config.view_component.use_consistent_rendering_lifecycle = true
|
342
|
-
# ```
|
343
|
-
#
|
344
|
-
# Defaults to `false`
|
345
|
-
#
|
346
|
-
mattr_accessor :use_consistent_rendering_lifecycle, instance_writer: false, default: false
|
347
|
-
|
348
338
|
# Parent class for generated components
|
349
339
|
#
|
350
340
|
# ```ruby
|
@@ -412,7 +402,7 @@ module ViewComponent
|
|
412
402
|
# Find sidecar files for the given extensions.
|
413
403
|
#
|
414
404
|
# The provided array of extensions is expected to contain
|
415
|
-
# strings starting without the
|
405
|
+
# strings starting without the dot, example: `["erb", "haml"]`.
|
416
406
|
#
|
417
407
|
# For example, one might collect sidecar CSS files that need to be compiled.
|
418
408
|
# @param extensions [Array<String>] Extensions of which to return matching sidecar files.
|
@@ -590,7 +580,7 @@ module ViewComponent
|
|
590
580
|
parameter = validate_default ? collection_parameter : provided_collection_parameter
|
591
581
|
|
592
582
|
return unless parameter
|
593
|
-
return if initialize_parameter_names.include?(parameter)
|
583
|
+
return if initialize_parameter_names.include?(parameter) || splatted_keyword_argument_present?
|
594
584
|
|
595
585
|
# If Ruby can't parse the component class, then the initalize
|
596
586
|
# parameters will be empty and ViewComponent will not be able to render
|
@@ -646,6 +636,11 @@ module ViewComponent
|
|
646
636
|
|
647
637
|
private
|
648
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
|
+
|
649
644
|
def initialize_parameter_names
|
650
645
|
return attribute_names.map(&:to_sym) if respond_to?(:attribute_names)
|
651
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
|
-
# ####
|
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
|
#
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails"
|
4
|
-
require "view_component/
|
4
|
+
require "view_component/config"
|
5
5
|
|
6
6
|
module ViewComponent
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
8
|
-
config.view_component = ViewComponent::
|
8
|
+
config.view_component = ViewComponent::Config.defaults
|
9
9
|
|
10
10
|
rake_tasks do
|
11
11
|
load "view_component/rails/tasks/view_component.rake"
|
@@ -14,9 +14,6 @@ module ViewComponent
|
|
14
14
|
initializer "view_component.set_configs" do |app|
|
15
15
|
options = app.config.view_component
|
16
16
|
|
17
|
-
%i[generate preview_controller preview_route show_previews_source].each do |config_option|
|
18
|
-
options[config_option] ||= ViewComponent::Base.public_send(config_option)
|
19
|
-
end
|
20
17
|
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
21
18
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
22
19
|
options.show_previews = (Rails.env.development? || Rails.env.test?) if options.show_previews.nil?
|
@@ -39,6 +36,8 @@ module ViewComponent
|
|
39
36
|
|
40
37
|
initializer "view_component.enable_instrumentation" do |app|
|
41
38
|
ActiveSupport.on_load(:view_component) do
|
39
|
+
Base.config = app.config.view_component
|
40
|
+
|
42
41
|
if app.config.view_component.instrumentation_enabled.present?
|
43
42
|
# :nocov:
|
44
43
|
ViewComponent::Base.prepend(ViewComponent::Instrumentation)
|
@@ -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.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
|
+
date: 2022-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|