view_component 2.42.0 → 2.45.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/CHANGELOG.md +152 -16
- data/lib/rails/generators/stimulus/component_generator.rb +2 -0
- data/lib/view_component/base.rb +15 -23
- data/lib/view_component/compile_cache.rb +1 -1
- data/lib/view_component/compiler.rb +1 -1
- data/lib/view_component/engine.rb +14 -2
- data/lib/view_component/polymorphic_slots.rb +0 -1
- data/lib/view_component/preview.rb +2 -1
- data/lib/view_component/previewable.rb +8 -0
- data/lib/view_component/slot_v2.rb +2 -2
- data/lib/view_component/slotable.rb +4 -4
- data/lib/view_component/slotable_v2.rb +3 -3
- data/lib/view_component/test_helpers.rb +1 -1
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +5 -0
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a209f06f513d226dba5ddcfefe8c08d16f84da6d8664fd9a4f2f70fe1ef48d96
|
|
4
|
+
data.tar.gz: cc11c7e358b6fa3b07474a257202be93b0283c7c6189ce8d939770a805a28ef6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2420eadefc54d1045c432b7b53010281bd923b556b72d4ed924b49a0a88b1841800d6e04f25bb043913f5c648693d19ad56117e441c838e7eb09e0ab5cf21315
|
|
7
|
+
data.tar.gz: 4deb4c925810fcc2e3918e8735dd957003536e5533289d48caf69100dcb5ed58af6bb7af88fdc0cdf3c73e9905bb0222de18d9fd6cba65ca05e6bc3ed1f9964f
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<img src="/docs/logo/
|
|
1
|
+
<img src="/docs/logo/github-readme-logo.svg" alt="ViewComponent logo" width="400">
|
|
2
2
|
|
|
3
3
|
A framework for building reusable, testable & encapsulated view components in Ruby on Rails.
|
|
4
4
|
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,136 @@ title: Changelog
|
|
|
5
5
|
|
|
6
6
|
# Changelog
|
|
7
7
|
|
|
8
|
+
## main
|
|
9
|
+
|
|
10
|
+
## 2.45.0
|
|
11
|
+
|
|
12
|
+
* Remove internal APIs from API documentation, fix link to license.
|
|
13
|
+
|
|
14
|
+
*Joel Hawksley*
|
|
15
|
+
|
|
16
|
+
* Add @yhirano55 to triage team.
|
|
17
|
+
|
|
18
|
+
*Joel Hawksley*
|
|
19
|
+
|
|
20
|
+
* Correct a typo in the sample slots code.
|
|
21
|
+
|
|
22
|
+
*Simon Fish*
|
|
23
|
+
|
|
24
|
+
* Add note about `allowed_queries`.
|
|
25
|
+
|
|
26
|
+
*Joel Hawksley*
|
|
27
|
+
|
|
28
|
+
* Add `vale` content linter.
|
|
29
|
+
|
|
30
|
+
*Joel Hawksley*
|
|
31
|
+
|
|
32
|
+
* Remove `require "rails/generators/test_case"` in generator tests.
|
|
33
|
+
|
|
34
|
+
*Yoshiyuki Hirano*
|
|
35
|
+
|
|
36
|
+
* Suppress zeitwerk warning about circular require.
|
|
37
|
+
|
|
38
|
+
*Yoshiyuki Hirano*
|
|
39
|
+
|
|
40
|
+
* Move `test_unit_generator_test.rb` from `test/view_component/` to `test/generators/`.
|
|
41
|
+
|
|
42
|
+
*Yoshiyuki Hirano*
|
|
43
|
+
|
|
44
|
+
* Unify test code of `TestUnitGeneratorTest` with the other generators tests.
|
|
45
|
+
|
|
46
|
+
*Yoshiyuki Hirano*
|
|
47
|
+
|
|
48
|
+
## 2.44.0
|
|
49
|
+
|
|
50
|
+
* Rename internal accessor to use private naming.
|
|
51
|
+
|
|
52
|
+
*Joel Hawksley*, *Blake Williams*, *Cameron Dutro*
|
|
53
|
+
|
|
54
|
+
* Add Github repo link to docs website header.
|
|
55
|
+
|
|
56
|
+
*Hans Lemuet*
|
|
57
|
+
|
|
58
|
+
* Change logo in README for dark theme readability.
|
|
59
|
+
|
|
60
|
+
*Dylan Smith*
|
|
61
|
+
|
|
62
|
+
* Add Litmus to users list.
|
|
63
|
+
|
|
64
|
+
*Dylan Smith*
|
|
65
|
+
|
|
66
|
+
* Add @dylanatsmith as codeowner of the ViewComponent logo and member of committers team.
|
|
67
|
+
|
|
68
|
+
*Joel Hawksley*
|
|
69
|
+
|
|
70
|
+
* Autoload `CompileCache`, which is optionally called in `engine.rb`.
|
|
71
|
+
|
|
72
|
+
*Gregory Igelmund*
|
|
73
|
+
|
|
74
|
+
* Move frequently asked questions to other pages, add History page.
|
|
75
|
+
|
|
76
|
+
*Joel Hawksley*
|
|
77
|
+
|
|
78
|
+
* Fix typo.
|
|
79
|
+
|
|
80
|
+
*James Hart*
|
|
81
|
+
|
|
82
|
+
* Add `require "method_source"` if it options.show_previews_source is enabled.
|
|
83
|
+
|
|
84
|
+
*Yoshiyuki Hirano*
|
|
85
|
+
|
|
86
|
+
* Move show_previews_source definition to Previewable.
|
|
87
|
+
|
|
88
|
+
*Yoshiyuki Hirano*
|
|
89
|
+
|
|
90
|
+
* Clear cache in MethodSource to apply the change odf preview code without app server restart.
|
|
91
|
+
|
|
92
|
+
*Yoshiyuki Hirano*
|
|
93
|
+
|
|
94
|
+
## 2.43.1
|
|
95
|
+
|
|
96
|
+
* Remove unnecessary call to `ruby2_keywords` for polymorphic slot getters.
|
|
97
|
+
|
|
98
|
+
*Cameron Dutro*
|
|
99
|
+
|
|
100
|
+
## 2.43.0
|
|
101
|
+
|
|
102
|
+
* Add note about tests and instance methods.
|
|
103
|
+
|
|
104
|
+
*Joel Hawksley*
|
|
105
|
+
|
|
106
|
+
* Flesh out `ViewComponents in practice`.
|
|
107
|
+
|
|
108
|
+
*Joel Hawksley*
|
|
109
|
+
|
|
110
|
+
* Add CODEOWNERS entries for feature areas owned by community committers.
|
|
111
|
+
|
|
112
|
+
*Joel Hawksley*
|
|
113
|
+
|
|
114
|
+
* Separate lint and CI workflows.
|
|
115
|
+
|
|
116
|
+
*Blake Williams*
|
|
117
|
+
|
|
118
|
+
* Add support for `image_path` helper in previews.
|
|
119
|
+
|
|
120
|
+
*Tobias Ahlin*, *Joel Hawksley*
|
|
121
|
+
|
|
122
|
+
* Add section to docs listing users of ViewComponent. Please submit a PR to add your team to the list!
|
|
123
|
+
|
|
124
|
+
*Joel Hawksley*
|
|
125
|
+
|
|
126
|
+
* Fix loading issue with Stimulus generator and add specs for Stimulus generator.
|
|
127
|
+
|
|
128
|
+
*Peter Sumskas*
|
|
129
|
+
|
|
130
|
+
* Remove dependency on `ActionDispatch::Static` in Rails middleware stack when enabling statics assets for source code preview.
|
|
131
|
+
|
|
132
|
+
*Gregory Igelmund*
|
|
133
|
+
|
|
134
|
+
* Require `view_component/engine` automatically.
|
|
135
|
+
|
|
136
|
+
*Cameron Dutro*
|
|
137
|
+
|
|
8
138
|
## 2.42.0
|
|
9
139
|
|
|
10
140
|
* Add logo files and page to docs.
|
|
@@ -50,7 +180,7 @@ title: Changelog
|
|
|
50
180
|
|
|
51
181
|
*Matthew Rider*
|
|
52
182
|
|
|
53
|
-
* Fix bug where `with_collection_parameter`
|
|
183
|
+
* Fix bug where `with_collection_parameter` didn't inherit from parent component.
|
|
54
184
|
|
|
55
185
|
*Will Drexler*, *Christian Campoli*
|
|
56
186
|
|
|
@@ -254,7 +384,7 @@ title: Changelog
|
|
|
254
384
|
|
|
255
385
|
*Hans Lemuet*
|
|
256
386
|
|
|
257
|
-
* Fix bug where ViewComponents
|
|
387
|
+
* Fix bug where ViewComponents didn't work in ActionMailers.
|
|
258
388
|
|
|
259
389
|
*dark-panda*
|
|
260
390
|
|
|
@@ -302,7 +432,7 @@ title: Changelog
|
|
|
302
432
|
|
|
303
433
|
## 2.31.0
|
|
304
434
|
|
|
305
|
-
_Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot
|
|
435
|
+
_Note: This release includes an underlying change to Slots that may affect incorrect usage of the API, where Slots were set on a line prefixed by `<%=`. The result of setting a Slot shouldn't be returned. (`<%`)_
|
|
306
436
|
|
|
307
437
|
* Add `#with_content` to allow setting content without a block.
|
|
308
438
|
|
|
@@ -313,7 +443,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
313
443
|
*Mario Schüttel*
|
|
314
444
|
|
|
315
445
|
* Improve feature parity with Rails translations
|
|
316
|
-
* Don't create a translation
|
|
446
|
+
* Don't create a translation back end if the component has no translation file
|
|
317
447
|
* Mark translation keys ending with `html` as HTML-safe
|
|
318
448
|
* Always convert keys to String
|
|
319
449
|
* Support multiple keys
|
|
@@ -355,7 +485,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
355
485
|
|
|
356
486
|
*Alex Robbin, Blake Williams*
|
|
357
487
|
|
|
358
|
-
* Experimental: call `._sidecar_files` to fetch the sidecar files for a given list of extensions,
|
|
488
|
+
* Experimental: call `._sidecar_files` to fetch the sidecar files for a given list of extensions, for example passing `["yml", "yaml"]`.
|
|
359
489
|
|
|
360
490
|
*Elia Schito*
|
|
361
491
|
|
|
@@ -395,11 +525,11 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
395
525
|
|
|
396
526
|
## 2.26.0
|
|
397
527
|
|
|
398
|
-
*
|
|
528
|
+
* Delay evaluating component `content` in `render?`, preventing the `content` block from being evaluated when `render?` returns false.
|
|
399
529
|
|
|
400
530
|
*Blake Williams*
|
|
401
531
|
|
|
402
|
-
*
|
|
532
|
+
* Don't generate template when using `--inline` flag.
|
|
403
533
|
|
|
404
534
|
*Hans Lemuet*
|
|
405
535
|
|
|
@@ -460,7 +590,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
460
590
|
* `with_slot collection: true` becomes `renders_many`.
|
|
461
591
|
* Slot definitions now accept either a component class, component class name, or a lambda instead of a `class_name:` keyword argument.
|
|
462
592
|
* Slots now support positional arguments.
|
|
463
|
-
* Slots no longer use the `content` attribute to render content, instead relying on `to_s`.
|
|
593
|
+
* Slots no longer use the `content` attribute to render content, instead relying on `to_s`. for example `<%= my_slot %>`.
|
|
464
594
|
* Slot values are no longer set via the `slot` method, and instead use the name of the slot.
|
|
465
595
|
|
|
466
596
|
*Blake Williams*
|
|
@@ -523,7 +653,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
523
653
|
|
|
524
654
|
## 2.18.2
|
|
525
655
|
|
|
526
|
-
* Raise an error if controller or view context is accessed during initialize as they
|
|
656
|
+
* Raise an error if controller or view context is accessed during initialize as they're only available in render.
|
|
527
657
|
|
|
528
658
|
*Julian Nadeau*
|
|
529
659
|
|
|
@@ -539,7 +669,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
539
669
|
|
|
540
670
|
## 2.18.0
|
|
541
671
|
|
|
542
|
-
* Fix auto
|
|
672
|
+
* Fix auto loading of previews (changes no longer require a server restart)
|
|
543
673
|
|
|
544
674
|
*Matt Brictson*
|
|
545
675
|
|
|
@@ -632,7 +762,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
632
762
|
|
|
633
763
|
## 2.10.0
|
|
634
764
|
|
|
635
|
-
* Raise an `ArgumentError` with a helpful message when Ruby
|
|
765
|
+
* Raise an `ArgumentError` with a helpful message when Ruby can't parse a component class.
|
|
636
766
|
|
|
637
767
|
*Max Beizer*
|
|
638
768
|
|
|
@@ -724,7 +854,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
724
854
|
|
|
725
855
|
## v2.2.1
|
|
726
856
|
|
|
727
|
-
* Fix bug where template
|
|
857
|
+
* Fix bug where template couldn't be found if `inherited` was redefined.
|
|
728
858
|
|
|
729
859
|
*Joel Hawksley*
|
|
730
860
|
|
|
@@ -740,7 +870,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
740
870
|
|
|
741
871
|
## v2.1.0
|
|
742
872
|
|
|
743
|
-
* Support rendering collections (
|
|
873
|
+
* Support rendering collections (for example, `render(MyComponent.with_collection(@items))`).
|
|
744
874
|
|
|
745
875
|
*Tim Clem*
|
|
746
876
|
|
|
@@ -762,7 +892,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
762
892
|
|
|
763
893
|
*Andrew Mason*
|
|
764
894
|
|
|
765
|
-
* ViewComponent generators
|
|
895
|
+
* ViewComponent generators don't not prompt for content requirement.
|
|
766
896
|
|
|
767
897
|
*Joel Hawksley*
|
|
768
898
|
|
|
@@ -884,7 +1014,7 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
884
1014
|
|
|
885
1015
|
*Jon Palmer*
|
|
886
1016
|
|
|
887
|
-
* Add `#render?` hook to
|
|
1017
|
+
* Add `#render?` hook to allow components to be no-ops.
|
|
888
1018
|
|
|
889
1019
|
*Kyle Fox*
|
|
890
1020
|
|
|
@@ -952,7 +1082,9 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
952
1082
|
|
|
953
1083
|
* Fix edge case issue with extracting variants from less conventional source_locations.
|
|
954
1084
|
|
|
1085
|
+
<!-- vale proselint.GenderBias = NO -->
|
|
955
1086
|
*Ryan Workman*
|
|
1087
|
+
<!-- vale proselint.GenderBias = YES -->
|
|
956
1088
|
|
|
957
1089
|
## v1.6.0
|
|
958
1090
|
|
|
@@ -988,7 +1120,9 @@ _Note: This release includes an underlying change to Slots that may affect incor
|
|
|
988
1120
|
|
|
989
1121
|
* Add support for RSpec to generators.
|
|
990
1122
|
|
|
1123
|
+
<!-- vale proselint.GenderBias = NO -->
|
|
991
1124
|
*Dylan Clark, Ryan Workman*
|
|
1125
|
+
<!-- vale proselint.GenderBias = YES -->
|
|
992
1126
|
|
|
993
1127
|
* Require controllers as part of setting autoload paths.
|
|
994
1128
|
|
|
@@ -1012,7 +1146,9 @@ Note: `actionview-component` is now loaded by requiring `actionview/component`,
|
|
|
1012
1146
|
|
|
1013
1147
|
* Fix issue with generating component method signatures.
|
|
1014
1148
|
|
|
1149
|
+
<!-- vale proselint.GenderBias = NO -->
|
|
1015
1150
|
*Ryan Workman, Dylan Clark*
|
|
1151
|
+
<!-- vale proselint.GenderBias = YES -->
|
|
1016
1152
|
|
|
1017
1153
|
* Create component generator.
|
|
1018
1154
|
|
|
@@ -1084,7 +1220,7 @@ Note: `actionview-component` is now loaded by requiring `actionview/component`,
|
|
|
1084
1220
|
|
|
1085
1221
|
## v1.3.3
|
|
1086
1222
|
|
|
1087
|
-
*
|
|
1223
|
+
* Don't raise error when sidecar files that aren't templates exist.
|
|
1088
1224
|
|
|
1089
1225
|
*Joel Hawksley*
|
|
1090
1226
|
|
data/lib/view_component/base.rb
CHANGED
|
@@ -29,7 +29,7 @@ module ViewComponent
|
|
|
29
29
|
class_attribute :content_areas
|
|
30
30
|
self.content_areas = [] # class_attribute:default doesn't work until Rails 5.2
|
|
31
31
|
|
|
32
|
-
attr_accessor :
|
|
32
|
+
attr_accessor :__vc_original_view_context
|
|
33
33
|
|
|
34
34
|
# EXPERIMENTAL: This API is experimental and may be removed at any time.
|
|
35
35
|
# Hook for allowing components to do work as part of the compilation process.
|
|
@@ -52,7 +52,7 @@ module ViewComponent
|
|
|
52
52
|
self.class.compile(raise_errors: true)
|
|
53
53
|
|
|
54
54
|
@view_context = view_context
|
|
55
|
-
self.
|
|
55
|
+
self.__vc_original_view_context ||= view_context
|
|
56
56
|
|
|
57
57
|
@lookup_context ||= view_context.lookup_context
|
|
58
58
|
|
|
@@ -137,10 +137,10 @@ module ViewComponent
|
|
|
137
137
|
# @private
|
|
138
138
|
def render(options = {}, args = {}, &block)
|
|
139
139
|
if options.is_a? ViewComponent::Base
|
|
140
|
-
options.
|
|
140
|
+
options.__vc_original_view_context = __vc_original_view_context
|
|
141
141
|
super
|
|
142
142
|
else
|
|
143
|
-
|
|
143
|
+
__vc_original_view_context.render(options, args, &block)
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
@@ -152,7 +152,7 @@ module ViewComponent
|
|
|
152
152
|
if view_context.nil?
|
|
153
153
|
raise(
|
|
154
154
|
ViewContextCalledBeforeRenderError,
|
|
155
|
-
"`#controller`
|
|
155
|
+
"`#controller` can't be used during initialization, as it depends " \
|
|
156
156
|
"on the view context that only exists once a ViewComponent is passed to " \
|
|
157
157
|
"the Rails render pipeline.\n\n" \
|
|
158
158
|
"It's sometimes possible to fix this issue by moving code dependent on " \
|
|
@@ -171,7 +171,7 @@ module ViewComponent
|
|
|
171
171
|
if view_context.nil?
|
|
172
172
|
raise(
|
|
173
173
|
ViewContextCalledBeforeRenderError,
|
|
174
|
-
"`#helpers`
|
|
174
|
+
"`#helpers` can't be used during initialization, as it depends " \
|
|
175
175
|
"on the view context that only exists once a ViewComponent is passed to " \
|
|
176
176
|
"the Rails render pipeline.\n\n" \
|
|
177
177
|
"It's sometimes possible to fix this issue by moving code dependent on " \
|
|
@@ -186,7 +186,7 @@ module ViewComponent
|
|
|
186
186
|
#
|
|
187
187
|
# This allows ivars to remain persisted when using the same helper via
|
|
188
188
|
# `helpers` across multiple components and partials.
|
|
189
|
-
@__vc_helpers ||=
|
|
189
|
+
@__vc_helpers ||= __vc_original_view_context || controller.view_context
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
# Exposes .virtual_path as an instance method
|
|
@@ -206,7 +206,7 @@ module ViewComponent
|
|
|
206
206
|
#
|
|
207
207
|
# @private
|
|
208
208
|
def format
|
|
209
|
-
# Ruby 2.6 throws a warning without checking `defined?`, 2.7
|
|
209
|
+
# Ruby 2.6 throws a warning without checking `defined?`, 2.7 doesn't
|
|
210
210
|
if defined?(@__vc_variant)
|
|
211
211
|
@__vc_variant
|
|
212
212
|
end
|
|
@@ -271,14 +271,6 @@ module ViewComponent
|
|
|
271
271
|
#
|
|
272
272
|
mattr_accessor :render_monkey_patch_enabled, instance_writer: false, default: true
|
|
273
273
|
|
|
274
|
-
# Enable or disable source code previews in component previews:
|
|
275
|
-
#
|
|
276
|
-
# config.view_component.show_previews_source = true
|
|
277
|
-
#
|
|
278
|
-
# Defaults to `false`.
|
|
279
|
-
#
|
|
280
|
-
mattr_accessor :show_previews_source, instance_writer: false, default: false
|
|
281
|
-
|
|
282
274
|
# Always generate a Stimulus controller alongside the component:
|
|
283
275
|
#
|
|
284
276
|
# config.view_component.generate_stimulus_controller = true
|
|
@@ -291,7 +283,7 @@ module ViewComponent
|
|
|
291
283
|
#
|
|
292
284
|
# config.view_component.view_component_path = "app/my_components"
|
|
293
285
|
#
|
|
294
|
-
# Defaults to
|
|
286
|
+
# Defaults to `app/components`.
|
|
295
287
|
mattr_accessor :view_component_path, instance_writer: false, default: "app/components"
|
|
296
288
|
|
|
297
289
|
# Parent class for generated components
|
|
@@ -326,7 +318,7 @@ module ViewComponent
|
|
|
326
318
|
|
|
327
319
|
# Add support for nested components defined in the same file.
|
|
328
320
|
#
|
|
329
|
-
#
|
|
321
|
+
# for example
|
|
330
322
|
#
|
|
331
323
|
# class MyComponent < ViewComponent::Base
|
|
332
324
|
# class MyOtherComponent < ViewComponent::Base
|
|
@@ -439,7 +431,7 @@ module ViewComponent
|
|
|
439
431
|
end
|
|
440
432
|
|
|
441
433
|
# Ensure the component initializer accepts the
|
|
442
|
-
# collection parameter. By default, we
|
|
434
|
+
# collection parameter. By default, we don't
|
|
443
435
|
# validate that the default parameter name
|
|
444
436
|
# is accepted, as support for collection
|
|
445
437
|
# rendering is optional.
|
|
@@ -450,7 +442,7 @@ module ViewComponent
|
|
|
450
442
|
return unless parameter
|
|
451
443
|
return if initialize_parameter_names.include?(parameter)
|
|
452
444
|
|
|
453
|
-
# If Ruby
|
|
445
|
+
# If Ruby can't parse the component class, then the initalize
|
|
454
446
|
# parameters will be empty and ViewComponent will not be able to render
|
|
455
447
|
# the component.
|
|
456
448
|
if initialize_parameters.empty?
|
|
@@ -463,14 +455,14 @@ module ViewComponent
|
|
|
463
455
|
end
|
|
464
456
|
|
|
465
457
|
raise ArgumentError.new(
|
|
466
|
-
"The initializer for #{self}
|
|
458
|
+
"The initializer for #{self} doesn't accept the parameter `#{parameter}`, " \
|
|
467
459
|
"which is required in order to render it as a collection.\n\n" \
|
|
468
460
|
"To fix this issue, update the initializer to accept `#{parameter}`.\n\n" \
|
|
469
461
|
"See https://viewcomponent.org/guide/collections.html for more information on rendering collections."
|
|
470
462
|
)
|
|
471
463
|
end
|
|
472
464
|
|
|
473
|
-
# Ensure the component initializer
|
|
465
|
+
# Ensure the component initializer doesn't define
|
|
474
466
|
# invalid parameters that could override the framework's
|
|
475
467
|
# methods.
|
|
476
468
|
# @private TODO: add documentation
|
|
@@ -478,7 +470,7 @@ module ViewComponent
|
|
|
478
470
|
return unless initialize_parameter_names.include?(RESERVED_PARAMETER)
|
|
479
471
|
|
|
480
472
|
raise ViewComponent::ComponentError.new(
|
|
481
|
-
"#{self} initializer
|
|
473
|
+
"#{self} initializer can't accept the parameter `#{RESERVED_PARAMETER}`, as it will override a " \
|
|
482
474
|
"public ViewComponent method. To fix this issue, rename the parameter."
|
|
483
475
|
)
|
|
484
476
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module ViewComponent
|
|
4
4
|
# Keeps track of which templates have already been compiled
|
|
5
|
-
# This
|
|
5
|
+
# This isn't part of the public API
|
|
6
6
|
module CompileCache
|
|
7
7
|
mattr_accessor :cache, instance_reader: false, instance_accessor: false do
|
|
8
8
|
Set.new
|
|
@@ -95,7 +95,7 @@ module ViewComponent
|
|
|
95
95
|
errors = []
|
|
96
96
|
|
|
97
97
|
if (templates + inline_calls).empty?
|
|
98
|
-
errors << "
|
|
98
|
+
errors << "Couldn't find a template file or inline render method for #{component_class}."
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
if templates.count { |template| template[:variant].nil? } > 1
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rails"
|
|
4
|
-
require "view_component"
|
|
5
4
|
|
|
6
5
|
module ViewComponent
|
|
7
6
|
class Engine < Rails::Engine # :nodoc:
|
|
@@ -17,6 +16,7 @@ module ViewComponent
|
|
|
17
16
|
|
|
18
17
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
|
19
18
|
options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
|
|
19
|
+
options.show_previews_source ||= ViewComponent::Base.show_previews_source
|
|
20
20
|
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
|
21
21
|
options.preview_route ||= ViewComponent::Base.preview_route
|
|
22
22
|
options.preview_controller ||= ViewComponent::Base.preview_controller
|
|
@@ -32,6 +32,14 @@ module ViewComponent
|
|
|
32
32
|
)
|
|
33
33
|
options.preview_paths << options.preview_path
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
if options.show_previews_source
|
|
37
|
+
require "method_source"
|
|
38
|
+
|
|
39
|
+
app.config.to_prepare do
|
|
40
|
+
MethodSource.instance_variable_set(:@lines_for_file, {})
|
|
41
|
+
end
|
|
42
|
+
end
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
ActiveSupport.on_load(:view_component) do
|
|
@@ -103,7 +111,7 @@ module ViewComponent
|
|
|
103
111
|
|
|
104
112
|
initializer "static assets" do |app|
|
|
105
113
|
if app.config.view_component.show_previews
|
|
106
|
-
app.middleware.
|
|
114
|
+
app.middleware.use(::ActionDispatch::Static, "#{root}/app/assets/vendor")
|
|
107
115
|
end
|
|
108
116
|
end
|
|
109
117
|
|
|
@@ -136,3 +144,7 @@ module ViewComponent
|
|
|
136
144
|
end
|
|
137
145
|
end
|
|
138
146
|
end
|
|
147
|
+
|
|
148
|
+
# In the case of automatic loading, "view_component" is loaded first,
|
|
149
|
+
# so there is no need to load it.
|
|
150
|
+
require "view_component" unless defined?(ViewComponent::Base)
|
|
@@ -41,7 +41,6 @@ module ViewComponent
|
|
|
41
41
|
define_method(getter_name) do
|
|
42
42
|
get_slot(slot_name)
|
|
43
43
|
end
|
|
44
|
-
ruby2_keywords(getter_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
|
45
44
|
|
|
46
45
|
define_method(setter_name) do |*args, &block|
|
|
47
46
|
set_polymorphic_slot(slot_name, poly_type, *args, &block)
|
|
@@ -5,6 +5,7 @@ require "active_support/descendants_tracker"
|
|
|
5
5
|
module ViewComponent # :nodoc:
|
|
6
6
|
class Preview
|
|
7
7
|
include ActionView::Helpers::TagHelper
|
|
8
|
+
include ActionView::Helpers::AssetTagHelper
|
|
8
9
|
extend ActiveSupport::DescendantsTracker
|
|
9
10
|
|
|
10
11
|
def render(component, **args, &block)
|
|
@@ -79,7 +80,7 @@ module ViewComponent # :nodoc:
|
|
|
79
80
|
if preview_path.nil?
|
|
80
81
|
raise(
|
|
81
82
|
PreviewTemplateError,
|
|
82
|
-
"A preview template for example #{example}
|
|
83
|
+
"A preview template for example #{example} doesn't exist.\n\n" \
|
|
83
84
|
"To fix this issue, create a template for the example."
|
|
84
85
|
)
|
|
85
86
|
end
|
|
@@ -15,6 +15,14 @@ module ViewComponent
|
|
|
15
15
|
#
|
|
16
16
|
mattr_accessor :show_previews, instance_writer: false
|
|
17
17
|
|
|
18
|
+
# Enable or disable source code previews in component previews:
|
|
19
|
+
#
|
|
20
|
+
# config.view_component.show_previews_source = true
|
|
21
|
+
#
|
|
22
|
+
# Defaults to `false`.
|
|
23
|
+
#
|
|
24
|
+
mattr_accessor :show_previews_source, instance_writer: false, default: false
|
|
25
|
+
|
|
18
26
|
# Set a custom default layout used for preview index and individual previews:
|
|
19
27
|
#
|
|
20
28
|
# config.view_component.default_preview_layout = "component_preview"
|
|
@@ -20,7 +20,7 @@ module ViewComponent
|
|
|
20
20
|
# component, or a function that returns a component, we render that
|
|
21
21
|
# component instance, returning the string.
|
|
22
22
|
#
|
|
23
|
-
# If the slot renderable is a function and returns a string, it
|
|
23
|
+
# If the slot renderable is a function and returns a string, it's
|
|
24
24
|
# set as `@__vc_content` and is returned directly.
|
|
25
25
|
#
|
|
26
26
|
# If there is no slot renderable, we evaluate the block passed to
|
|
@@ -69,7 +69,7 @@ module ViewComponent
|
|
|
69
69
|
|
|
70
70
|
# Allow access to public component methods via the wrapper
|
|
71
71
|
#
|
|
72
|
-
#
|
|
72
|
+
# for example
|
|
73
73
|
#
|
|
74
74
|
# calling `header.name` (where `header` is a slot) will call `name`
|
|
75
75
|
# on the `HeaderComponent` instance.
|
|
@@ -29,12 +29,12 @@ module ViewComponent
|
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
slot_names.each do |slot_name|
|
|
32
|
-
# Ensure slot_name
|
|
32
|
+
# Ensure slot_name isn't already declared
|
|
33
33
|
if self.slots.key?(slot_name)
|
|
34
34
|
raise ArgumentError.new("#{slot_name} slot declared multiple times")
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
# Ensure slot name
|
|
37
|
+
# Ensure slot name isn't :content
|
|
38
38
|
if slot_name == :content
|
|
39
39
|
raise ArgumentError.new ":content is a reserved slot name. Please use another name, such as ':body'"
|
|
40
40
|
end
|
|
@@ -105,7 +105,7 @@ module ViewComponent
|
|
|
105
105
|
# <% end %>
|
|
106
106
|
#
|
|
107
107
|
def slot(slot_name, **args, &block)
|
|
108
|
-
# Raise ArgumentError if `slot`
|
|
108
|
+
# Raise ArgumentError if `slot` doesn't exist
|
|
109
109
|
unless slots.keys.include?(slot_name)
|
|
110
110
|
raise ArgumentError.new "Unknown slot '#{slot_name}' - expected one of '#{slots.keys}'"
|
|
111
111
|
end
|
|
@@ -140,7 +140,7 @@ module ViewComponent
|
|
|
140
140
|
instance_variable_set(slot[:instance_variable_name], slot_instance)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
# Return nil, as this method
|
|
143
|
+
# Return nil, as this method shouldn't output anything to the view itself.
|
|
144
144
|
nil
|
|
145
145
|
end
|
|
146
146
|
end
|
|
@@ -121,7 +121,7 @@ module ViewComponent
|
|
|
121
121
|
singular_name = ActiveSupport::Inflector.singularize(slot_name)
|
|
122
122
|
|
|
123
123
|
# Define setter for singular names
|
|
124
|
-
#
|
|
124
|
+
# for example `renders_many :items` allows fetching all tabs with
|
|
125
125
|
# `component.tabs` and setting a tab with `component.tab`
|
|
126
126
|
define_method singular_name do |*args, &block|
|
|
127
127
|
set_slot(slot_name, nil, *args, &block)
|
|
@@ -181,7 +181,7 @@ module ViewComponent
|
|
|
181
181
|
# If callable is a string, we assume it's referencing an internal class
|
|
182
182
|
slot[:renderable_class_name] = callable
|
|
183
183
|
elsif callable.respond_to?(:call)
|
|
184
|
-
# If slot
|
|
184
|
+
# If slot doesn't respond to `render_in`, we assume it's a proc,
|
|
185
185
|
# define a method, and save a reference to it to call when setting
|
|
186
186
|
method_name = :"_call_#{slot_name}"
|
|
187
187
|
define_method method_name, &callable
|
|
@@ -256,7 +256,7 @@ module ViewComponent
|
|
|
256
256
|
# 1. If this is a `content_area` style sub-component, we will render the
|
|
257
257
|
# block via the `slot`
|
|
258
258
|
#
|
|
259
|
-
# 2. Since we
|
|
259
|
+
# 2. Since we've to pass block content to components when calling
|
|
260
260
|
# `render`, evaluating the block here would require us to call
|
|
261
261
|
# `view_context.capture` twice, which is slower
|
|
262
262
|
slot.__vc_content_block = block if block_given?
|
|
@@ -103,7 +103,7 @@ module ViewComponent
|
|
|
103
103
|
@controller = old_controller
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
# Set the URL
|
|
106
|
+
# Set the URL of the current request (such as when using request-dependent path helpers):
|
|
107
107
|
#
|
|
108
108
|
# ```ruby
|
|
109
109
|
# with_request_url("/users/42") do
|
data/lib/view_component.rb
CHANGED
|
@@ -8,6 +8,7 @@ module ViewComponent
|
|
|
8
8
|
|
|
9
9
|
autoload :Base
|
|
10
10
|
autoload :Compiler
|
|
11
|
+
autoload :CompileCache
|
|
11
12
|
autoload :ComponentError
|
|
12
13
|
autoload :Instrumentation
|
|
13
14
|
autoload :Preview
|
|
@@ -17,3 +18,7 @@ module ViewComponent
|
|
|
17
18
|
autoload :TemplateError
|
|
18
19
|
autoload :Translatable
|
|
19
20
|
end
|
|
21
|
+
|
|
22
|
+
# In the case of manually loading, "view_component/engine" is loaded first,
|
|
23
|
+
# so there is no need to load it.
|
|
24
|
+
require "view_component/engine" if defined?(Rails::Engine) && !defined?(ViewComponent::Engine)
|
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.45.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitHub Open Source
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -76,16 +76,16 @@ dependencies:
|
|
|
76
76
|
name: bundler
|
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
|
79
|
-
- - "
|
|
79
|
+
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version:
|
|
81
|
+
version: 1.15.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:
|
|
88
|
+
version: 1.15.0
|
|
89
89
|
- !ruby/object:Gem::Dependency
|
|
90
90
|
name: erb_lint
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -268,7 +268,7 @@ dependencies:
|
|
|
268
268
|
- - ">="
|
|
269
269
|
- !ruby/object:Gem::Version
|
|
270
270
|
version: '0'
|
|
271
|
-
description:
|
|
271
|
+
description:
|
|
272
272
|
email:
|
|
273
273
|
- opensource+view_component@github.com
|
|
274
274
|
executables: []
|
|
@@ -341,7 +341,7 @@ licenses:
|
|
|
341
341
|
- MIT
|
|
342
342
|
metadata:
|
|
343
343
|
allowed_push_host: https://rubygems.org
|
|
344
|
-
post_install_message:
|
|
344
|
+
post_install_message:
|
|
345
345
|
rdoc_options: []
|
|
346
346
|
require_paths:
|
|
347
347
|
- lib
|
|
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
357
357
|
version: '0'
|
|
358
358
|
requirements: []
|
|
359
359
|
rubygems_version: 3.1.2
|
|
360
|
-
signing_key:
|
|
360
|
+
signing_key:
|
|
361
361
|
specification_version: 4
|
|
362
362
|
summary: View components for Rails
|
|
363
363
|
test_files: []
|