view_component 2.41.0 → 2.44.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/README.md +1 -1
- data/docs/CHANGELOG.md +117 -1
- data/lib/rails/generators/stimulus/component_generator.rb +13 -0
- data/lib/rails/generators/stimulus/templates/component_controller.js.tt +1 -1
- data/lib/view_component/base.rb +15 -10
- data/lib/view_component/engine.rb +10 -1
- data/lib/view_component/polymorphic_slots.rb +73 -0
- data/lib/view_component/preview.rb +1 -0
- data/lib/view_component/previewable.rb +8 -0
- data/lib/view_component/slot_v2.rb +3 -8
- data/lib/view_component/slotable_v2.rb +32 -20
- data/lib/view_component/version.rb +1 -1
- data/lib/view_component.rb +3 -0
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2542c18f4fbd3071c18fb27d8edb563021ad201fa5cc4d0c02fb8190918b6920
|
4
|
+
data.tar.gz: 7c7fb2ef2a79ed3816655cd8f27a52248fe0181957487a9b0297968914034c9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e43d3b7398bd838b25e87a566ce82229e82343f64a9f70230b90d4eb2b0afdc8e0ffda355acd032877d0751082e3e4342ecd53955011de89ea1ce341c6b7a80
|
7
|
+
data.tar.gz: 3d90591c1d4d3cbff9d8e4c7dd1f94015ddce95e62f8284586dda63da99311609c3558fd353f0cf3c6b8c58f4c9a0b18f0fa91e60aa2275e57284cb2e10bff4a
|
data/README.md
CHANGED
data/docs/CHANGELOG.md
CHANGED
@@ -7,6 +7,122 @@ title: Changelog
|
|
7
7
|
|
8
8
|
## main
|
9
9
|
|
10
|
+
## 2.44.0
|
11
|
+
|
12
|
+
* Rename internal accessor to use private naming.
|
13
|
+
|
14
|
+
*Joel Hawksley*, *Blake Williams*, *Cameron Dutro*
|
15
|
+
|
16
|
+
* Add Github repo link to docs website header.
|
17
|
+
|
18
|
+
*Hans Lemuet*
|
19
|
+
|
20
|
+
* Change logo in README for dark theme readability.
|
21
|
+
|
22
|
+
*Dylan Smith*
|
23
|
+
|
24
|
+
* Add Litmus to users list.
|
25
|
+
|
26
|
+
*Dylan Smith*
|
27
|
+
|
28
|
+
* Add @dylanatsmith as codeowner of the ViewComponent logo and member of committers team.
|
29
|
+
|
30
|
+
*Joel Hawksley*
|
31
|
+
|
32
|
+
* Autoload `CompileCache`, which is optionally called in `engine.rb`.
|
33
|
+
|
34
|
+
*Gregory Igelmund*
|
35
|
+
|
36
|
+
* Move frequently asked questions to other pages, add History page.
|
37
|
+
|
38
|
+
*Joel Hawksley*
|
39
|
+
|
40
|
+
* Fix typo.
|
41
|
+
|
42
|
+
*James Hart*
|
43
|
+
|
44
|
+
* Add `require "method_source"` if it options.show_previews_source is enabled.
|
45
|
+
|
46
|
+
*Yoshiyuki Hirano*
|
47
|
+
|
48
|
+
* Move show_previews_source definition to Previewable.
|
49
|
+
|
50
|
+
*Yoshiyuki Hirano*
|
51
|
+
|
52
|
+
* Clear cache in MethodSource to apply the change odf preview code without app server restart.
|
53
|
+
|
54
|
+
*Yoshiyuki Hirano*
|
55
|
+
|
56
|
+
## 2.43.1
|
57
|
+
|
58
|
+
* Remove unnecessary call to `ruby2_keywords` for polymorphic slot getters.
|
59
|
+
|
60
|
+
*Cameron Dutro*
|
61
|
+
|
62
|
+
## 2.43.0
|
63
|
+
|
64
|
+
* Add note about tests and instance methods.
|
65
|
+
|
66
|
+
*Joel Hawksley*
|
67
|
+
|
68
|
+
* Flesh out `ViewComponents in practice`.
|
69
|
+
|
70
|
+
*Joel Hawksley*
|
71
|
+
|
72
|
+
* Add CODEOWNERS entries for feature areas owned by community committers.
|
73
|
+
|
74
|
+
*Joel Hawksley*
|
75
|
+
|
76
|
+
* Separate lint and CI workflows.
|
77
|
+
|
78
|
+
*Blake Williams*
|
79
|
+
|
80
|
+
* Add support for `image_path` helper in previews.
|
81
|
+
|
82
|
+
*Tobias Ahlin*, *Joel Hawksley*
|
83
|
+
|
84
|
+
* Add section to docs listing users of ViewComponent. Please submit a PR to add your team to the list!
|
85
|
+
|
86
|
+
*Joel Hawksley*
|
87
|
+
|
88
|
+
* Fix loading issue with Stimulus generator and add specs for Stimulus generator.
|
89
|
+
|
90
|
+
*Peter Sumskas*
|
91
|
+
|
92
|
+
* Remove dependency on `ActionDispatch::Static` in Rails middleware stack when enabling statics assets for source code preview.
|
93
|
+
|
94
|
+
*Gregory Igelmund*
|
95
|
+
|
96
|
+
* Require `view_component/engine` automatically.
|
97
|
+
|
98
|
+
*Cameron Dutro*
|
99
|
+
|
100
|
+
## 2.42.0
|
101
|
+
|
102
|
+
* Add logo files and page to docs.
|
103
|
+
|
104
|
+
*Dylan Smith*
|
105
|
+
|
106
|
+
* Add `ViewComponents in practice` documentation.
|
107
|
+
|
108
|
+
*Joel Hawksley*
|
109
|
+
|
110
|
+
* Fix bug where calling lambda slots without arguments would break in Ruby < 2.7.
|
111
|
+
|
112
|
+
*Manuel Puyol*
|
113
|
+
|
114
|
+
* Improve Stimulus controller template to import from `stimulus` or `@hotwired/stimulus`.
|
115
|
+
|
116
|
+
*Mario Schüttel*
|
117
|
+
|
118
|
+
* Fix bug where `helpers` would instantiate and use a new `view_context` in each component.
|
119
|
+
|
120
|
+
*Blake Williams*, *Ian C. Anderson*
|
121
|
+
|
122
|
+
* Implement polymorphic slots as experimental feature. See the Slots documentation to learn more.
|
123
|
+
|
124
|
+
*Cameron Dutro*
|
125
|
+
|
10
126
|
## 2.41.0
|
11
127
|
|
12
128
|
* Add `sprockets-rails` development dependency to fix test suite failures when using rails@main.
|
@@ -42,7 +158,7 @@ title: Changelog
|
|
42
158
|
|
43
159
|
*Hans Lemuet*
|
44
160
|
|
45
|
-
* Forward keyword arguments from slot wrapper to component instance.
|
161
|
+
* Forward keyword arguments from slot wrapper to component instance using ruby2_keywords.
|
46
162
|
|
47
163
|
*Cameron Dutro*
|
48
164
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "rails/generators/abstract_generator"
|
4
|
+
|
3
5
|
module Stimulus
|
4
6
|
module Generators
|
5
7
|
class ComponentGenerator < ::Rails::Generators::NamedBase
|
@@ -12,6 +14,12 @@ module Stimulus
|
|
12
14
|
template "component_controller.js", destination
|
13
15
|
end
|
14
16
|
|
17
|
+
def stimulus_module
|
18
|
+
return "stimulus" if legacy_stimulus?
|
19
|
+
|
20
|
+
"@hotwired/stimulus"
|
21
|
+
end
|
22
|
+
|
15
23
|
private
|
16
24
|
|
17
25
|
def destination
|
@@ -21,6 +29,11 @@ module Stimulus
|
|
21
29
|
File.join(component_path, class_path, "#{file_name}_component_controller.js")
|
22
30
|
end
|
23
31
|
end
|
32
|
+
|
33
|
+
def legacy_stimulus?
|
34
|
+
package_json_pathname = Rails.root.join("package.json")
|
35
|
+
package_json_pathname.exist? && JSON.parse(package_json_pathname.read).dig("dependencies", "stimulus").present?
|
36
|
+
end
|
24
37
|
end
|
25
38
|
end
|
26
39
|
end
|
data/lib/view_component/base.rb
CHANGED
@@ -5,6 +5,7 @@ require "active_support/configurable"
|
|
5
5
|
require "view_component/collection"
|
6
6
|
require "view_component/compile_cache"
|
7
7
|
require "view_component/content_areas"
|
8
|
+
require "view_component/polymorphic_slots"
|
8
9
|
require "view_component/previewable"
|
9
10
|
require "view_component/slotable"
|
10
11
|
require "view_component/slotable_v2"
|
@@ -28,6 +29,8 @@ module ViewComponent
|
|
28
29
|
class_attribute :content_areas
|
29
30
|
self.content_areas = [] # class_attribute:default doesn't work until Rails 5.2
|
30
31
|
|
32
|
+
attr_accessor :__vc_original_view_context
|
33
|
+
|
31
34
|
# EXPERIMENTAL: This API is experimental and may be removed at any time.
|
32
35
|
# Hook for allowing components to do work as part of the compilation process.
|
33
36
|
#
|
@@ -49,6 +52,8 @@ module ViewComponent
|
|
49
52
|
self.class.compile(raise_errors: true)
|
50
53
|
|
51
54
|
@view_context = view_context
|
55
|
+
self.__vc_original_view_context ||= view_context
|
56
|
+
|
52
57
|
@lookup_context ||= view_context.lookup_context
|
53
58
|
|
54
59
|
# required for path helpers in older Rails versions
|
@@ -132,9 +137,10 @@ module ViewComponent
|
|
132
137
|
# @private
|
133
138
|
def render(options = {}, args = {}, &block)
|
134
139
|
if options.is_a? ViewComponent::Base
|
140
|
+
options.__vc_original_view_context = __vc_original_view_context
|
135
141
|
super
|
136
142
|
else
|
137
|
-
|
143
|
+
__vc_original_view_context.render(options, args, &block)
|
138
144
|
end
|
139
145
|
end
|
140
146
|
|
@@ -173,7 +179,14 @@ module ViewComponent
|
|
173
179
|
)
|
174
180
|
end
|
175
181
|
|
176
|
-
|
182
|
+
# Attempt to re-use the original view_context passed to the first
|
183
|
+
# component rendered in the rendering pipeline. This prevents the
|
184
|
+
# instantiation of a new view_context via `controller.view_context` which
|
185
|
+
# always returns a new instance of the view context class.
|
186
|
+
#
|
187
|
+
# This allows ivars to remain persisted when using the same helper via
|
188
|
+
# `helpers` across multiple components and partials.
|
189
|
+
@__vc_helpers ||= __vc_original_view_context || controller.view_context
|
177
190
|
end
|
178
191
|
|
179
192
|
# Exposes .virtual_path as an instance method
|
@@ -258,14 +271,6 @@ module ViewComponent
|
|
258
271
|
#
|
259
272
|
mattr_accessor :render_monkey_patch_enabled, instance_writer: false, default: true
|
260
273
|
|
261
|
-
# Enable or disable source code previews in component previews:
|
262
|
-
#
|
263
|
-
# config.view_component.show_previews_source = true
|
264
|
-
#
|
265
|
-
# Defaults to `false`.
|
266
|
-
#
|
267
|
-
mattr_accessor :show_previews_source, instance_writer: false, default: false
|
268
|
-
|
269
274
|
# Always generate a Stimulus controller alongside the component:
|
270
275
|
#
|
271
276
|
# config.view_component.generate_stimulus_controller = true
|
@@ -17,6 +17,7 @@ module ViewComponent
|
|
17
17
|
|
18
18
|
options.render_monkey_patch_enabled = true if options.render_monkey_patch_enabled.nil?
|
19
19
|
options.show_previews = Rails.env.development? || Rails.env.test? if options.show_previews.nil?
|
20
|
+
options.show_previews_source ||= ViewComponent::Base.show_previews_source
|
20
21
|
options.instrumentation_enabled = false if options.instrumentation_enabled.nil?
|
21
22
|
options.preview_route ||= ViewComponent::Base.preview_route
|
22
23
|
options.preview_controller ||= ViewComponent::Base.preview_controller
|
@@ -32,6 +33,14 @@ module ViewComponent
|
|
32
33
|
)
|
33
34
|
options.preview_paths << options.preview_path
|
34
35
|
end
|
36
|
+
|
37
|
+
if options.show_previews_source
|
38
|
+
require "method_source"
|
39
|
+
|
40
|
+
app.config.to_prepare do
|
41
|
+
MethodSource.instance_variable_set(:@lines_for_file, {})
|
42
|
+
end
|
43
|
+
end
|
35
44
|
end
|
36
45
|
|
37
46
|
ActiveSupport.on_load(:view_component) do
|
@@ -103,7 +112,7 @@ module ViewComponent
|
|
103
112
|
|
104
113
|
initializer "static assets" do |app|
|
105
114
|
if app.config.view_component.show_previews
|
106
|
-
app.middleware.
|
115
|
+
app.middleware.use(::ActionDispatch::Static, "#{root}/app/assets/vendor")
|
107
116
|
end
|
108
117
|
end
|
109
118
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ViewComponent
|
4
|
+
module PolymorphicSlots
|
5
|
+
# In older rails versions, using a concern isn't a good idea here because they appear to not work with
|
6
|
+
# Module#prepend and class methods.
|
7
|
+
def self.included(base)
|
8
|
+
base.singleton_class.prepend(ClassMethods)
|
9
|
+
base.include(InstanceMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def renders_one(slot_name, callable = nil)
|
14
|
+
return super unless callable.is_a?(Hash) && callable.key?(:types)
|
15
|
+
|
16
|
+
validate_singular_slot_name(slot_name)
|
17
|
+
register_polymorphic_slot(slot_name, callable[:types], collection: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def renders_many(slot_name, callable = nil)
|
21
|
+
return super unless callable.is_a?(Hash) && callable.key?(:types)
|
22
|
+
|
23
|
+
validate_plural_slot_name(slot_name)
|
24
|
+
register_polymorphic_slot(slot_name, callable[:types], collection: true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def register_polymorphic_slot(slot_name, types, collection:)
|
28
|
+
renderable_hash = types.each_with_object({}) do |(poly_type, poly_callable), memo|
|
29
|
+
memo[poly_type] = define_slot(
|
30
|
+
"#{slot_name}_#{poly_type}", collection: collection, callable: poly_callable
|
31
|
+
)
|
32
|
+
|
33
|
+
getter_name = slot_name
|
34
|
+
setter_name =
|
35
|
+
if collection
|
36
|
+
"#{ActiveSupport::Inflector.singularize(slot_name)}_#{poly_type}"
|
37
|
+
else
|
38
|
+
"#{slot_name}_#{poly_type}"
|
39
|
+
end
|
40
|
+
|
41
|
+
define_method(getter_name) do
|
42
|
+
get_slot(slot_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
define_method(setter_name) do |*args, &block|
|
46
|
+
set_polymorphic_slot(slot_name, poly_type, *args, &block)
|
47
|
+
end
|
48
|
+
ruby2_keywords(setter_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
49
|
+
end
|
50
|
+
|
51
|
+
self.registered_slots[slot_name] = {
|
52
|
+
collection: collection,
|
53
|
+
renderable_hash: renderable_hash
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module InstanceMethods
|
59
|
+
def set_polymorphic_slot(slot_name, poly_type = nil, *args, &block)
|
60
|
+
slot_definition = self.class.registered_slots[slot_name]
|
61
|
+
|
62
|
+
if !slot_definition[:collection] && get_slot(slot_name)
|
63
|
+
raise ArgumentError, "content for slot '#{slot_name}' has already been provided"
|
64
|
+
end
|
65
|
+
|
66
|
+
poly_def = slot_definition[:renderable_hash][poly_type]
|
67
|
+
|
68
|
+
set_slot(slot_name, poly_def, *args, &block)
|
69
|
+
end
|
70
|
+
ruby2_keywords(:set_polymorphic_slot) if respond_to?(:ruby2_keywords, true)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
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"
|
@@ -86,15 +86,10 @@ module ViewComponent
|
|
86
86
|
# end
|
87
87
|
# end
|
88
88
|
#
|
89
|
-
|
90
|
-
|
91
|
-
@__vc_component_instance.public_send(symbol, *args, **kwargs, &block)
|
92
|
-
end
|
93
|
-
else
|
94
|
-
def method_missing(symbol, *args, &block)
|
95
|
-
@__vc_component_instance.public_send(symbol, *args, &block)
|
96
|
-
end
|
89
|
+
def method_missing(symbol, *args, &block)
|
90
|
+
@__vc_component_instance.public_send(symbol, *args, &block)
|
97
91
|
end
|
92
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
98
93
|
|
99
94
|
def html_safe?
|
100
95
|
to_s.html_safe?
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
|
-
|
5
4
|
require "view_component/slot_v2"
|
6
5
|
|
7
6
|
module ViewComponent
|
@@ -67,13 +66,14 @@ module ViewComponent
|
|
67
66
|
def renders_one(slot_name, callable = nil)
|
68
67
|
validate_singular_slot_name(slot_name)
|
69
68
|
|
70
|
-
define_method slot_name do |*args,
|
71
|
-
if args.empty? &&
|
69
|
+
define_method slot_name do |*args, &block|
|
70
|
+
if args.empty? && block.nil?
|
72
71
|
get_slot(slot_name)
|
73
72
|
else
|
74
|
-
set_slot(slot_name, *args,
|
73
|
+
set_slot(slot_name, nil, *args, &block)
|
75
74
|
end
|
76
75
|
end
|
76
|
+
ruby2_keywords(slot_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
77
77
|
|
78
78
|
register_slot(slot_name, collection: false, callable: callable)
|
79
79
|
end
|
@@ -123,9 +123,10 @@ module ViewComponent
|
|
123
123
|
# Define setter for singular names
|
124
124
|
# e.g. `renders_many :items` allows fetching all tabs with
|
125
125
|
# `component.tabs` and setting a tab with `component.tab`
|
126
|
-
define_method singular_name do |*args,
|
127
|
-
set_slot(slot_name, *args,
|
126
|
+
define_method singular_name do |*args, &block|
|
127
|
+
set_slot(slot_name, nil, *args, &block)
|
128
128
|
end
|
129
|
+
ruby2_keywords(singular_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
129
130
|
|
130
131
|
# Instantiates and and adds multiple slots forwarding the first
|
131
132
|
# argument to each slot constructor
|
@@ -134,7 +135,7 @@ module ViewComponent
|
|
134
135
|
get_slot(slot_name)
|
135
136
|
else
|
136
137
|
collection_args.map do |args|
|
137
|
-
set_slot(slot_name, **args, &block)
|
138
|
+
set_slot(slot_name, nil, **args, &block)
|
138
139
|
end
|
139
140
|
end
|
140
141
|
end
|
@@ -162,27 +163,37 @@ module ViewComponent
|
|
162
163
|
|
163
164
|
private
|
164
165
|
|
165
|
-
def register_slot(slot_name,
|
166
|
+
def register_slot(slot_name, **kwargs)
|
167
|
+
self.registered_slots[slot_name] = define_slot(slot_name, **kwargs)
|
168
|
+
end
|
169
|
+
|
170
|
+
def define_slot(slot_name, collection:, callable:)
|
166
171
|
# Setup basic slot data
|
167
172
|
slot = {
|
168
173
|
collection: collection,
|
169
174
|
}
|
175
|
+
return slot unless callable
|
176
|
+
|
170
177
|
# If callable responds to `render_in`, we set it on the slot as a renderable
|
171
|
-
if callable
|
178
|
+
if callable.respond_to?(:method_defined?) && callable.method_defined?(:render_in)
|
172
179
|
slot[:renderable] = callable
|
173
180
|
elsif callable.is_a?(String)
|
174
181
|
# If callable is a string, we assume it's referencing an internal class
|
175
182
|
slot[:renderable_class_name] = callable
|
176
|
-
elsif callable
|
183
|
+
elsif callable.respond_to?(:call)
|
177
184
|
# If slot does not respond to `render_in`, we assume it's a proc,
|
178
185
|
# define a method, and save a reference to it to call when setting
|
179
186
|
method_name = :"_call_#{slot_name}"
|
180
187
|
define_method method_name, &callable
|
181
188
|
slot[:renderable_function] = instance_method(method_name)
|
189
|
+
else
|
190
|
+
raise(
|
191
|
+
ArgumentError,
|
192
|
+
"invalid slot definition. Please pass a class, string, or callable (i.e. proc, lambda, etc)"
|
193
|
+
)
|
182
194
|
end
|
183
195
|
|
184
|
-
|
185
|
-
self.registered_slots[slot_name] = slot
|
196
|
+
slot
|
186
197
|
end
|
187
198
|
|
188
199
|
def validate_plural_slot_name(slot_name)
|
@@ -235,9 +246,8 @@ module ViewComponent
|
|
235
246
|
end
|
236
247
|
end
|
237
248
|
|
238
|
-
def set_slot(slot_name, *args,
|
239
|
-
slot_definition
|
240
|
-
|
249
|
+
def set_slot(slot_name, slot_definition = nil, *args, &block)
|
250
|
+
slot_definition ||= self.class.registered_slots[slot_name]
|
241
251
|
slot = SlotV2.new(self)
|
242
252
|
|
243
253
|
# Passing the block to the sub-component wrapper like this has two
|
@@ -253,23 +263,24 @@ module ViewComponent
|
|
253
263
|
|
254
264
|
# If class
|
255
265
|
if slot_definition[:renderable]
|
256
|
-
slot.__vc_component_instance = slot_definition[:renderable].new(*args
|
266
|
+
slot.__vc_component_instance = slot_definition[:renderable].new(*args)
|
257
267
|
# If class name as a string
|
258
268
|
elsif slot_definition[:renderable_class_name]
|
259
269
|
slot.__vc_component_instance =
|
260
|
-
self.class.const_get(slot_definition[:renderable_class_name]).new(*args
|
270
|
+
self.class.const_get(slot_definition[:renderable_class_name]).new(*args)
|
261
271
|
# If passed a lambda
|
262
272
|
elsif slot_definition[:renderable_function]
|
263
273
|
# Use `bind(self)` to ensure lambda is executed in the context of the
|
264
274
|
# current component. This is necessary to allow the lambda to access helper
|
265
275
|
# methods like `content_tag` as well as parent component state.
|
276
|
+
renderable_function = slot_definition[:renderable_function].bind(self)
|
266
277
|
renderable_value =
|
267
278
|
if block_given?
|
268
|
-
|
269
|
-
view_context.capture(*args,
|
279
|
+
renderable_function.call(*args) do |*args|
|
280
|
+
view_context.capture(*args, &block)
|
270
281
|
end
|
271
282
|
else
|
272
|
-
|
283
|
+
renderable_function.call(*args)
|
273
284
|
end
|
274
285
|
|
275
286
|
# Function calls can return components, so if it's a component handle it specially
|
@@ -291,5 +302,6 @@ module ViewComponent
|
|
291
302
|
|
292
303
|
slot
|
293
304
|
end
|
305
|
+
ruby2_keywords(:set_slot) if respond_to?(:ruby2_keywords, true)
|
294
306
|
end
|
295
307
|
end
|
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,5 @@ module ViewComponent
|
|
17
18
|
autoload :TemplateError
|
18
19
|
autoload :Translatable
|
19
20
|
end
|
21
|
+
|
22
|
+
require "view_component/engine" if defined?(Rails::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.44.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-18 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: []
|
@@ -314,6 +314,7 @@ files:
|
|
314
314
|
- lib/view_component/content_areas.rb
|
315
315
|
- lib/view_component/engine.rb
|
316
316
|
- lib/view_component/instrumentation.rb
|
317
|
+
- lib/view_component/polymorphic_slots.rb
|
317
318
|
- lib/view_component/preview.rb
|
318
319
|
- lib/view_component/preview_template_error.rb
|
319
320
|
- lib/view_component/previewable.rb
|
@@ -340,7 +341,7 @@ licenses:
|
|
340
341
|
- MIT
|
341
342
|
metadata:
|
342
343
|
allowed_push_host: https://rubygems.org
|
343
|
-
post_install_message:
|
344
|
+
post_install_message:
|
344
345
|
rdoc_options: []
|
345
346
|
require_paths:
|
346
347
|
- lib
|
@@ -355,8 +356,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
356
|
- !ruby/object:Gem::Version
|
356
357
|
version: '0'
|
357
358
|
requirements: []
|
358
|
-
rubygems_version: 3.1.
|
359
|
-
signing_key:
|
359
|
+
rubygems_version: 3.1.2
|
360
|
+
signing_key:
|
360
361
|
specification_version: 4
|
361
362
|
summary: View components for Rails
|
362
363
|
test_files: []
|