view_component 2.83.0 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of view_component might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +51 -3
- data/lib/view_component/base.rb +2 -83
- data/lib/view_component/collection.rb +1 -1
- data/lib/view_component/compiler.rb +0 -12
- data/lib/view_component/config.rb +0 -12
- data/lib/view_component/deprecation.rb +1 -1
- data/lib/view_component/engine.rb +0 -17
- data/lib/view_component/polymorphic_slots.rb +0 -12
- data/lib/view_component/slotable.rb +0 -65
- data/lib/view_component/slotable_v2.rb +2 -57
- data/lib/view_component/test_helpers.rb +0 -9
- data/lib/view_component/version.rb +4 -3
- data/lib/view_component.rb +1 -10
- metadata +6 -8
- data/lib/view_component/content_areas.rb +0 -56
- data/lib/view_component/slot.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18fc4d884af4512c13d7b1f4184c59e57859a8d797451ec0b2063ff425a7d357
|
4
|
+
data.tar.gz: 8da2e96b470f354b1d09f1b461506e64cca4345522f2b9ddfa4143ee5bf0627c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9750449d8d23a150a099e8c3fa6620eb7ba03adecfeefaa9e4f0c3ce463353d9918f1212971ae214557675eae367232ccd96308e89f11831259efa1000b8fa22
|
7
|
+
data.tar.gz: 7b1a6852d060bea82ab51e69f3328d95dd6491d11fb2f88b84fa8b235fb17a83670a05764c8df116127017332fd3a6f9d76d9205fd5bcc31d925ec9e39a573b8
|
data/docs/CHANGELOG.md
CHANGED
@@ -10,11 +10,59 @@ nav_order: 5
|
|
10
10
|
|
11
11
|
## main
|
12
12
|
|
13
|
-
##
|
13
|
+
## 3.0.0.rc1
|
14
14
|
|
15
|
-
|
15
|
+
1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
|
16
16
|
|
17
|
-
|
17
|
+
We're so grateful for all of the work of community members to get us to this release. Whether it’s filing bug reports, designing APIs in long-winded discussion threads, or writing code itself, ViewComponent is built by the community, for the community. We couldn’t be more proud of what we’re building together :heart:
|
18
|
+
|
19
|
+
This release makes the following breaking changes, many of which have long been deprecated:
|
20
|
+
|
21
|
+
* BREAKING: Remove deprecated slots setter methods. Use `with_SLOT_NAME` instead.
|
22
|
+
|
23
|
+
*Joel Hawksley*
|
24
|
+
|
25
|
+
* BREAKING: Remove deprecated SlotsV1 in favor of current SlotsV2.
|
26
|
+
|
27
|
+
*Joel Hawksley*
|
28
|
+
|
29
|
+
* BREAKING: Remove deprecated `content_areas` feature. Use Slots instead.
|
30
|
+
|
31
|
+
*Joel Hawksley*
|
32
|
+
|
33
|
+
* BREAKING: Remove deprecated support for loading ViewComponent engine manually. Make sure `require "view_component/engine"` is removed from `Gemfile`.
|
34
|
+
|
35
|
+
*Joel Hawksley*
|
36
|
+
|
37
|
+
* BREAKING: Remove deprecated `generate_*` methods. Use `generate.*` instead.
|
38
|
+
|
39
|
+
*Joel Hawksley*
|
40
|
+
|
41
|
+
* BREAKING: Remove deprecated `with_variant` method.
|
42
|
+
|
43
|
+
*Joel Hawksley*
|
44
|
+
|
45
|
+
* BREAKING: Remove deprecated `rendered_component` in favor of `rendered_content`.
|
46
|
+
|
47
|
+
*Joel Hawksley*
|
48
|
+
|
49
|
+
* BREAKING: Remove deprecated `config.preview_path` in favor of `config.preview_paths`.
|
50
|
+
|
51
|
+
*Joel Hawksley*
|
52
|
+
|
53
|
+
* BREAKING: Support Ruby 2.7+ instead of 2.4+
|
54
|
+
|
55
|
+
*Joel Hawksley*
|
56
|
+
|
57
|
+
* BREAKING: Remove deprecated `before_render_check`.
|
58
|
+
|
59
|
+
*Joel Hawksley*
|
60
|
+
|
61
|
+
* BREAKING: Change counter variable to start iterating from `0` instead of `1`.
|
62
|
+
|
63
|
+
*Frank S*
|
64
|
+
|
65
|
+
Run into an issue with this release? [Let us know](https://github.com/ViewComponent/view_component/issues/1629).
|
18
66
|
|
19
67
|
## 2.82.0
|
20
68
|
|
data/lib/view_component/base.rb
CHANGED
@@ -6,10 +6,8 @@ require "view_component/collection"
|
|
6
6
|
require "view_component/compile_cache"
|
7
7
|
require "view_component/compiler"
|
8
8
|
require "view_component/config"
|
9
|
-
require "view_component/content_areas"
|
10
9
|
require "view_component/polymorphic_slots"
|
11
10
|
require "view_component/preview"
|
12
|
-
require "view_component/slotable"
|
13
11
|
require "view_component/slotable_v2"
|
14
12
|
require "view_component/translatable"
|
15
13
|
require "view_component/with_content_helper"
|
@@ -31,7 +29,6 @@ module ViewComponent
|
|
31
29
|
attr_writer :config
|
32
30
|
end
|
33
31
|
|
34
|
-
include ViewComponent::ContentAreas
|
35
32
|
include ViewComponent::PolymorphicSlots
|
36
33
|
include ViewComponent::SlotableV2
|
37
34
|
include ViewComponent::Translatable
|
@@ -44,9 +41,6 @@ module ViewComponent
|
|
44
41
|
# For CSRF authenticity tokens in forms
|
45
42
|
delegate :form_authenticity_token, :protect_against_forgery?, :config, to: :helpers
|
46
43
|
|
47
|
-
class_attribute :content_areas
|
48
|
-
self.content_areas = [] # class_attribute:default doesn't work until Rails 5.2
|
49
|
-
|
50
44
|
# Config option that strips trailing whitespace in templates before compiling them.
|
51
45
|
class_attribute :__vc_strip_trailing_whitespace, instance_accessor: false, instance_predicate: false
|
52
46
|
self.__vc_strip_trailing_whitespace = false # class_attribute:default doesn't work until Rails 5.2
|
@@ -66,23 +60,6 @@ module ViewComponent
|
|
66
60
|
self.__vc_original_view_context = view_context
|
67
61
|
end
|
68
62
|
|
69
|
-
# @!macro [attach] deprecated_generate_mattr_accessor
|
70
|
-
# @method generate_$1
|
71
|
-
# @deprecated Use `#generate.$1` instead. Will be removed in v3.0.0.
|
72
|
-
def self._deprecated_generate_mattr_accessor(name)
|
73
|
-
define_singleton_method("generate_#{name}".to_sym) do
|
74
|
-
generate.public_send(name)
|
75
|
-
end
|
76
|
-
define_singleton_method("generate_#{name}=".to_sym) do |value|
|
77
|
-
generate.public_send("#{name}=".to_sym, value)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
_deprecated_generate_mattr_accessor :distinct_locale_files
|
82
|
-
_deprecated_generate_mattr_accessor :locale
|
83
|
-
_deprecated_generate_mattr_accessor :sidecar
|
84
|
-
_deprecated_generate_mattr_accessor :stimulus_controller
|
85
|
-
|
86
63
|
# Entrypoint for rendering components.
|
87
64
|
#
|
88
65
|
# - `view_context`: ActionView context from calling view
|
@@ -130,12 +107,7 @@ module ViewComponent
|
|
130
107
|
before_render
|
131
108
|
|
132
109
|
if render?
|
133
|
-
|
134
|
-
if output_postamble.blank?
|
135
|
-
safe_render_template_for(@__vc_variant).to_s
|
136
|
-
else
|
137
|
-
safe_render_template_for(@__vc_variant).to_s + safe_output_postamble
|
138
|
-
end
|
110
|
+
render_template_for(@__vc_variant).to_s + output_postamble
|
139
111
|
else
|
140
112
|
""
|
141
113
|
end
|
@@ -162,7 +134,7 @@ module ViewComponent
|
|
162
134
|
#
|
163
135
|
# @return [String]
|
164
136
|
def output_postamble
|
165
|
-
|
137
|
+
""
|
166
138
|
end
|
167
139
|
|
168
140
|
# Called before rendering the component. Override to perform operations that
|
@@ -170,14 +142,6 @@ module ViewComponent
|
|
170
142
|
#
|
171
143
|
# @return [void]
|
172
144
|
def before_render
|
173
|
-
before_render_check
|
174
|
-
end
|
175
|
-
|
176
|
-
# Called after rendering the component.
|
177
|
-
#
|
178
|
-
# @deprecated Use `#before_render` instead. Will be removed in v3.0.0.
|
179
|
-
# @return [void]
|
180
|
-
def before_render_check
|
181
145
|
# noop
|
182
146
|
end
|
183
147
|
|
@@ -270,22 +234,9 @@ module ViewComponent
|
|
270
234
|
#
|
271
235
|
# @private
|
272
236
|
def format
|
273
|
-
# Ruby 2.6 throws a warning without checking `defined?`, 2.7 doesn't
|
274
237
|
@__vc_variant if defined?(@__vc_variant)
|
275
238
|
end
|
276
239
|
|
277
|
-
# Use the provided variant instead of the one determined by the current request.
|
278
|
-
#
|
279
|
-
# @deprecated Will be removed in v3.0.0.
|
280
|
-
# @param variant [Symbol] The variant to be used by the component.
|
281
|
-
# @return [self]
|
282
|
-
def with_variant(variant)
|
283
|
-
@__vc_variant = variant
|
284
|
-
|
285
|
-
self
|
286
|
-
end
|
287
|
-
deprecate :with_variant, deprecator: ViewComponent::Deprecation
|
288
|
-
|
289
240
|
# The current request. Use sparingly as doing so introduces coupling that
|
290
241
|
# inhibits encapsulation & reuse, often making testing difficult.
|
291
242
|
#
|
@@ -314,38 +265,6 @@ module ViewComponent
|
|
314
265
|
@__vc_content_evaluated
|
315
266
|
end
|
316
267
|
|
317
|
-
def maybe_escape_html(text)
|
318
|
-
return text if request && !request.format.html?
|
319
|
-
return text if text.blank?
|
320
|
-
|
321
|
-
if text.html_safe?
|
322
|
-
text
|
323
|
-
else
|
324
|
-
yield
|
325
|
-
html_escape(text)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
def safe_render_template_for(variant)
|
330
|
-
if compiler.renders_template_for_variant?(variant)
|
331
|
-
render_template_for(variant)
|
332
|
-
else
|
333
|
-
maybe_escape_html(render_template_for(variant)) do
|
334
|
-
Kernel.warn("WARNING: The #{self.class} component rendered HTML-unsafe output. The output will be automatically escaped, but you may want to investigate.")
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
def safe_output_postamble
|
340
|
-
maybe_escape_html(output_postamble) do
|
341
|
-
Kernel.warn("WARNING: The #{self.class} component was provided an HTML-unsafe postamble. The postamble will be automatically escaped, but you may want to investigate.")
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
def compiler
|
346
|
-
@compiler ||= self.class.compiler
|
347
|
-
end
|
348
|
-
|
349
268
|
# Set the controller used for testing components:
|
350
269
|
#
|
351
270
|
# ```ruby
|
@@ -62,7 +62,7 @@ module ViewComponent
|
|
62
62
|
|
63
63
|
def component_options(item, iterator)
|
64
64
|
item_options = {component.collection_parameter => item}
|
65
|
-
item_options[component.collection_counter_parameter] = iterator.index
|
65
|
+
item_options[component.collection_counter_parameter] = iterator.index if component.counter_argument_present?
|
66
66
|
item_options[component.collection_iteration_parameter] = iterator.dup if component.iteration_argument_present?
|
67
67
|
|
68
68
|
@options.merge(item_options)
|
@@ -16,7 +16,6 @@ module ViewComponent
|
|
16
16
|
def initialize(component_class)
|
17
17
|
@component_class = component_class
|
18
18
|
@redefinition_lock = Mutex.new
|
19
|
-
@variants_rendering_templates = Set.new
|
20
19
|
end
|
21
20
|
|
22
21
|
def compiled?
|
@@ -47,12 +46,6 @@ module ViewComponent
|
|
47
46
|
return false
|
48
47
|
end
|
49
48
|
|
50
|
-
if subclass_instance_methods.include?(:before_render_check)
|
51
|
-
ViewComponent::Deprecation.deprecation_warning(
|
52
|
-
"`before_render_check`", :"`before_render`"
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
49
|
if raise_errors
|
57
50
|
component_class.validate_initialization_parameters!
|
58
51
|
component_class.validate_collection_parameter!
|
@@ -62,7 +55,6 @@ module ViewComponent
|
|
62
55
|
# Remove existing compiled template methods,
|
63
56
|
# as Ruby warns when redefining a method.
|
64
57
|
method_name = call_method_name(template[:variant])
|
65
|
-
@variants_rendering_templates << template[:variant]
|
66
58
|
|
67
59
|
redefinition_lock.synchronize do
|
68
60
|
component_class.silence_redefinition_of_method(method_name)
|
@@ -83,10 +75,6 @@ module ViewComponent
|
|
83
75
|
CompileCache.register(component_class)
|
84
76
|
end
|
85
77
|
|
86
|
-
def renders_template_for_variant?(variant)
|
87
|
-
@variants_rendering_templates.include?(variant)
|
88
|
-
end
|
89
|
-
|
90
78
|
private
|
91
79
|
|
92
80
|
attr_reader :component_class, :redefinition_lock
|
@@ -126,9 +126,6 @@ module ViewComponent
|
|
126
126
|
# The locations in which component previews will be looked up.
|
127
127
|
# Defaults to `['test/component/previews']` relative to your Rails root.
|
128
128
|
|
129
|
-
# @!attribute preview_path
|
130
|
-
# @deprecated Use #preview_paths instead. Will be removed in v3.0.0.
|
131
|
-
|
132
129
|
# @!attribute test_controller
|
133
130
|
# @return [String]
|
134
131
|
# The controller used for testing components.
|
@@ -158,15 +155,6 @@ module ViewComponent
|
|
158
155
|
@config = self.class.defaults
|
159
156
|
end
|
160
157
|
|
161
|
-
def preview_path
|
162
|
-
preview_paths
|
163
|
-
end
|
164
|
-
|
165
|
-
def preview_path=(new_value)
|
166
|
-
ViewComponent::Deprecation.deprecation_warning("`preview_path`", :"`preview_paths`")
|
167
|
-
self.preview_paths = Array.wrap(new_value)
|
168
|
-
end
|
169
|
-
|
170
158
|
delegate_missing_to :config
|
171
159
|
|
172
160
|
private
|
@@ -143,20 +143,3 @@ module ViewComponent
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
146
|
-
|
147
|
-
if RUBY_VERSION < "2.7.0"
|
148
|
-
ViewComponent::Deprecation.deprecation_warning("Support for Ruby versions < 2.7.0")
|
149
|
-
end
|
150
|
-
|
151
|
-
# :nocov:
|
152
|
-
unless defined?(ViewComponent::Base)
|
153
|
-
require "view_component/deprecation"
|
154
|
-
|
155
|
-
ViewComponent::Deprecation.deprecation_warning(
|
156
|
-
"Manually loading the engine",
|
157
|
-
"remove `require \"view_component/engine\"`"
|
158
|
-
)
|
159
|
-
|
160
|
-
require "view_component"
|
161
|
-
end
|
162
|
-
# :nocov:
|
@@ -60,18 +60,6 @@ module ViewComponent
|
|
60
60
|
"#{slot_name}_#{poly_type}"
|
61
61
|
end
|
62
62
|
|
63
|
-
define_method(setter_name) do |*args, &block|
|
64
|
-
if _warn_on_deprecated_slot_setter
|
65
|
-
ViewComponent::Deprecation.deprecation_warning(
|
66
|
-
"Using polymorphic slot setters like `#{setter_name}`",
|
67
|
-
:"`with_#{setter_name}`"
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
set_polymorphic_slot(slot_name, poly_type, *args, &block)
|
72
|
-
end
|
73
|
-
ruby2_keywords(setter_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
74
|
-
|
75
63
|
define_method("with_#{setter_name}") do |*args, &block|
|
76
64
|
set_polymorphic_slot(slot_name, poly_type, *args, &block)
|
77
65
|
end
|
@@ -15,71 +15,6 @@ module ViewComponent
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class_methods do
|
18
|
-
# support initializing slots as:
|
19
|
-
#
|
20
|
-
# with_slot(
|
21
|
-
# :header,
|
22
|
-
# collection: true|false,
|
23
|
-
# class_name: "Header" # class name string, used to instantiate Slot
|
24
|
-
# )
|
25
|
-
def with_slot(*slot_names, collection: false, class_name: nil)
|
26
|
-
ViewComponent::Deprecation.deprecation_warning(
|
27
|
-
"`with_slot`", "use the new slots API (https://viewcomponent.org/guide/slots.html) instead"
|
28
|
-
)
|
29
|
-
|
30
|
-
slot_names.each do |slot_name|
|
31
|
-
# Ensure slot_name isn't already declared
|
32
|
-
if slots.key?(slot_name)
|
33
|
-
raise ArgumentError.new("#{slot_name} slot declared multiple times")
|
34
|
-
end
|
35
|
-
|
36
|
-
# Ensure slot name isn't :content
|
37
|
-
if slot_name == :content
|
38
|
-
raise ArgumentError.new ":content is a reserved slot name. Please use another name, such as ':body'"
|
39
|
-
end
|
40
|
-
|
41
|
-
# Set the name of the method used to access the Slot(s)
|
42
|
-
accessor_name =
|
43
|
-
if collection
|
44
|
-
# If Slot is a collection, set the accessor
|
45
|
-
# name to the pluralized form of the slot name
|
46
|
-
# For example: :tab => :tabs
|
47
|
-
ActiveSupport::Inflector.pluralize(slot_name)
|
48
|
-
else
|
49
|
-
slot_name
|
50
|
-
end
|
51
|
-
|
52
|
-
instance_variable_name = "@#{accessor_name}"
|
53
|
-
|
54
|
-
# If the slot is a collection, define an accesor that defaults to an empty array
|
55
|
-
if collection
|
56
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
57
|
-
def #{accessor_name}
|
58
|
-
content unless content_evaluated? # ensure content is loaded so slots will be defined
|
59
|
-
#{instance_variable_name} ||= []
|
60
|
-
end
|
61
|
-
RUBY
|
62
|
-
else
|
63
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
64
|
-
def #{accessor_name}
|
65
|
-
content unless content_evaluated? # ensure content is loaded so slots will be defined
|
66
|
-
#{instance_variable_name} if defined?(#{instance_variable_name})
|
67
|
-
end
|
68
|
-
RUBY
|
69
|
-
end
|
70
|
-
|
71
|
-
# Default class_name to ViewComponent::Slot
|
72
|
-
class_name = "ViewComponent::Slot" unless class_name.present?
|
73
|
-
|
74
|
-
# Register the slot on the component
|
75
|
-
slots[slot_name] = {
|
76
|
-
class_name: class_name,
|
77
|
-
instance_variable_name: instance_variable_name,
|
78
|
-
collection: collection
|
79
|
-
}
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
18
|
def inherited(child)
|
84
19
|
# Clone slot configuration into child class
|
85
20
|
# see #test_slots_pollution
|
@@ -17,19 +17,9 @@ module ViewComponent
|
|
17
17
|
# Hash of registered Slots
|
18
18
|
class_attribute :registered_slots
|
19
19
|
self.registered_slots = {}
|
20
|
-
|
21
|
-
class_attribute :_warn_on_deprecated_slot_setter
|
22
|
-
self._warn_on_deprecated_slot_setter = false
|
23
20
|
end
|
24
21
|
|
25
22
|
class_methods do
|
26
|
-
##
|
27
|
-
# Enables deprecations coming to the Slots API in ViewComponent v3
|
28
|
-
#
|
29
|
-
def warn_on_deprecated_slot_setter
|
30
|
-
self._warn_on_deprecated_slot_setter = true
|
31
|
-
end
|
32
|
-
|
33
23
|
##
|
34
24
|
# Registers a sub-component
|
35
25
|
#
|
@@ -88,21 +78,7 @@ module ViewComponent
|
|
88
78
|
ruby2_keywords(:"with_#{slot_name}") if respond_to?(:ruby2_keywords, true)
|
89
79
|
|
90
80
|
define_method slot_name do |*args, &block|
|
91
|
-
|
92
|
-
get_slot(slot_name)
|
93
|
-
else
|
94
|
-
if _warn_on_deprecated_slot_setter
|
95
|
-
stack = caller_locations(3)
|
96
|
-
|
97
|
-
ViewComponent::Deprecation.deprecation_warning(
|
98
|
-
"Setting a slot with `##{slot_name}`",
|
99
|
-
"use `#with_#{slot_name}` to set the slot instead",
|
100
|
-
stack
|
101
|
-
)
|
102
|
-
end
|
103
|
-
|
104
|
-
set_slot(slot_name, nil, *args, &block)
|
105
|
-
end
|
81
|
+
get_slot(slot_name)
|
106
82
|
end
|
107
83
|
ruby2_keywords(slot_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
108
84
|
|
@@ -155,22 +131,6 @@ module ViewComponent
|
|
155
131
|
validate_plural_slot_name(slot_name)
|
156
132
|
validate_singular_slot_name(ActiveSupport::Inflector.singularize(slot_name).to_sym)
|
157
133
|
|
158
|
-
# Define setter for singular names
|
159
|
-
# for example `renders_many :items` allows fetching all tabs with
|
160
|
-
# `component.tabs` and setting a tab with `component.tab`
|
161
|
-
|
162
|
-
define_method singular_name do |*args, &block|
|
163
|
-
if _warn_on_deprecated_slot_setter
|
164
|
-
ViewComponent::Deprecation.deprecation_warning(
|
165
|
-
"Setting a slot with `##{singular_name}`",
|
166
|
-
"use `#with_#{singular_name}` to set the slot instead"
|
167
|
-
)
|
168
|
-
end
|
169
|
-
|
170
|
-
set_slot(slot_name, nil, *args, &block)
|
171
|
-
end
|
172
|
-
ruby2_keywords(singular_name.to_sym) if respond_to?(:ruby2_keywords, true)
|
173
|
-
|
174
134
|
define_method :"with_#{singular_name}" do |*args, &block|
|
175
135
|
set_slot(slot_name, nil, *args, &block)
|
176
136
|
end
|
@@ -182,23 +142,8 @@ module ViewComponent
|
|
182
142
|
end
|
183
143
|
end
|
184
144
|
|
185
|
-
# Instantiates and and adds multiple slots forwarding the first
|
186
|
-
# argument to each slot constructor
|
187
145
|
define_method slot_name do |collection_args = nil, &block|
|
188
|
-
|
189
|
-
get_slot(slot_name)
|
190
|
-
else
|
191
|
-
if _warn_on_deprecated_slot_setter
|
192
|
-
ViewComponent::Deprecation.deprecation_warning(
|
193
|
-
"Setting a slot with `##{slot_name}`",
|
194
|
-
"use `#with_#{slot_name}` to set the slot instead"
|
195
|
-
)
|
196
|
-
end
|
197
|
-
|
198
|
-
collection_args.map do |args|
|
199
|
-
set_slot(slot_name, nil, **args, &block)
|
200
|
-
end
|
201
|
-
end
|
146
|
+
get_slot(slot_name)
|
202
147
|
end
|
203
148
|
|
204
149
|
define_method "#{slot_name}?" do
|
@@ -31,15 +31,6 @@ module ViewComponent
|
|
31
31
|
# @private
|
32
32
|
attr_reader :rendered_content
|
33
33
|
|
34
|
-
# Returns the result of a render_inline call.
|
35
|
-
#
|
36
|
-
# @return [String]
|
37
|
-
def rendered_component
|
38
|
-
ViewComponent::Deprecation.deprecation_warning("`rendered_component`", :"`page`")
|
39
|
-
|
40
|
-
rendered_content
|
41
|
-
end
|
42
|
-
|
43
34
|
# Render a component inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
44
35
|
# allowing for Capybara assertions to be used:
|
45
36
|
#
|
data/lib/view_component.rb
CHANGED
@@ -23,13 +23,4 @@ module ViewComponent
|
|
23
23
|
autoload :Translatable
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
if defined?(ViewComponent::Engine)
|
28
|
-
ViewComponent::Deprecation.deprecation_warning(
|
29
|
-
"Manually loading the engine",
|
30
|
-
"remove `require \"view_component/engine\"`"
|
31
|
-
)
|
32
|
-
elsif defined?(Rails::Engine)
|
33
|
-
require "view_component/engine"
|
34
|
-
end
|
35
|
-
# :nocov:
|
26
|
+
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:
|
4
|
+
version: 3.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ViewComponent Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -358,7 +358,6 @@ files:
|
|
358
358
|
- lib/view_component/compiler.rb
|
359
359
|
- lib/view_component/component_error.rb
|
360
360
|
- lib/view_component/config.rb
|
361
|
-
- lib/view_component/content_areas.rb
|
362
361
|
- lib/view_component/deprecation.rb
|
363
362
|
- lib/view_component/docs_builder_component.html.erb
|
364
363
|
- lib/view_component/docs_builder_component.rb
|
@@ -374,7 +373,6 @@ files:
|
|
374
373
|
- lib/view_component/render_to_string_monkey_patch.rb
|
375
374
|
- lib/view_component/rendering_component_helper.rb
|
376
375
|
- lib/view_component/rendering_monkey_patch.rb
|
377
|
-
- lib/view_component/slot.rb
|
378
376
|
- lib/view_component/slot_v2.rb
|
379
377
|
- lib/view_component/slotable.rb
|
380
378
|
- lib/view_component/slotable_v2.rb
|
@@ -402,14 +400,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
402
400
|
requirements:
|
403
401
|
- - ">="
|
404
402
|
- !ruby/object:Gem::Version
|
405
|
-
version: 2.
|
403
|
+
version: 2.7.0
|
406
404
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
407
405
|
requirements:
|
408
|
-
- - "
|
406
|
+
- - ">"
|
409
407
|
- !ruby/object:Gem::Version
|
410
|
-
version:
|
408
|
+
version: 1.3.1
|
411
409
|
requirements: []
|
412
|
-
rubygems_version: 3.
|
410
|
+
rubygems_version: 3.2.32
|
413
411
|
signing_key:
|
414
412
|
specification_version: 4
|
415
413
|
summary: A framework for building reusable, testable & encapsulated view components
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "active_support/concern"
|
4
|
-
|
5
|
-
require "view_component/slot"
|
6
|
-
|
7
|
-
# DEPRECATED - ContentAreas is deprecated and will be removed in v3.0.0
|
8
|
-
module ViewComponent
|
9
|
-
module ContentAreas
|
10
|
-
extend ActiveSupport::Concern
|
11
|
-
|
12
|
-
# Assign the provided content to the content area accessor
|
13
|
-
#
|
14
|
-
# @private
|
15
|
-
def with(area, content = nil, &block)
|
16
|
-
unless content_areas.include?(area)
|
17
|
-
raise ArgumentError.new(
|
18
|
-
"Unknown content_area '#{area}' for #{self} - expected one of '#{content_areas}'.\n\n" \
|
19
|
-
"To fix this issue, add `with_content_area :#{area}` to #{self} or reference " \
|
20
|
-
"a valid content area."
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
if block
|
25
|
-
content = view_context.capture(&block)
|
26
|
-
end
|
27
|
-
|
28
|
-
instance_variable_set("@#{area}".to_sym, content)
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
|
-
class_methods do
|
33
|
-
def with_content_areas(*areas)
|
34
|
-
ViewComponent::Deprecation.deprecation_warning(
|
35
|
-
"`with_content_areas`", "use slots (https://viewcomponent.org/guide/slots.html) instead"
|
36
|
-
)
|
37
|
-
|
38
|
-
if areas.include?(:content)
|
39
|
-
raise ArgumentError.new(
|
40
|
-
"#{self} defines a content area called :content, which is a reserved name. \n\n" \
|
41
|
-
"To fix this issue, use another name, such as `:body`."
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
areas.each do |area|
|
46
|
-
define_method area.to_sym do
|
47
|
-
content unless content_evaluated? # ensure content is loaded so content_areas will be defined
|
48
|
-
instance_variable_get(:"@#{area}") if instance_variable_defined?(:"@#{area}")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
self.content_areas = areas
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|