view_component 2.82.0 → 3.0.0.rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bb20706245c43b9c5fa4d11087a2e98332bda53d659f7065874a3c0b8545547
4
- data.tar.gz: 13821a1e91da8a8dce8270962b99aa3b84fddb9731f99c2e2acfd143ad017836
3
+ metadata.gz: 18fc4d884af4512c13d7b1f4184c59e57859a8d797451ec0b2063ff425a7d357
4
+ data.tar.gz: 8da2e96b470f354b1d09f1b461506e64cca4345522f2b9ddfa4143ee5bf0627c
5
5
  SHA512:
6
- metadata.gz: 5b0ebf7ac54fc2c82374b29f9cceadfe55af73516ad2e4c65dad69cd65a7c63de3e00ef9cdba8b359c1061309f9a0d2f90344374feec2b37211fbfb36282c96b
7
- data.tar.gz: 48e156dcc5fa1ac9a6cff64e4cb585d528103452938a515d1e3598b505b03188e89362c393c86c0a05437f9a8c28f22e937e3d706f3da17ae03a7c1371728505
6
+ metadata.gz: 9750449d8d23a150a099e8c3fa6620eb7ba03adecfeefaa9e4f0c3ce463353d9918f1212971ae214557675eae367232ccd96308e89f11831259efa1000b8fa22
7
+ data.tar.gz: 7b1a6852d060bea82ab51e69f3328d95dd6491d11fb2f88b84fa8b235fb17a83670a05764c8df116127017332fd3a6f9d76d9205fd5bcc31d925ec9e39a573b8
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,60 @@ nav_order: 5
10
10
 
11
11
  ## main
12
12
 
13
+ ## 3.0.0.rc1
14
+
15
+ 1,000+ days and 100+ releases later, the 200+ contributors to ViewComponent are proud to ship v3.0.0!
16
+
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).
66
+
13
67
  ## 2.82.0
14
68
 
15
69
  * Revert "Avoid loading ActionView::Base during initialization (#1528)"
@@ -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
@@ -165,14 +142,6 @@ module ViewComponent
165
142
  #
166
143
  # @return [void]
167
144
  def before_render
168
- before_render_check
169
- end
170
-
171
- # Called after rendering the component.
172
- #
173
- # @deprecated Use `#before_render` instead. Will be removed in v3.0.0.
174
- # @return [void]
175
- def before_render_check
176
145
  # noop
177
146
  end
178
147
 
@@ -265,22 +234,9 @@ module ViewComponent
265
234
  #
266
235
  # @private
267
236
  def format
268
- # Ruby 2.6 throws a warning without checking `defined?`, 2.7 doesn't
269
237
  @__vc_variant if defined?(@__vc_variant)
270
238
  end
271
239
 
272
- # Use the provided variant instead of the one determined by the current request.
273
- #
274
- # @deprecated Will be removed in v3.0.0.
275
- # @param variant [Symbol] The variant to be used by the component.
276
- # @return [self]
277
- def with_variant(variant)
278
- @__vc_variant = variant
279
-
280
- self
281
- end
282
- deprecate :with_variant, deprecator: ViewComponent::Deprecation
283
-
284
240
  # The current request. Use sparingly as doing so introduces coupling that
285
241
  # inhibits encapsulation & reuse, often making testing difficult.
286
242
  #
@@ -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 + 1 if component.counter_argument_present?
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)
@@ -46,12 +46,6 @@ module ViewComponent
46
46
  return false
47
47
  end
48
48
 
49
- if subclass_instance_methods.include?(:before_render_check)
50
- ViewComponent::Deprecation.deprecation_warning(
51
- "`before_render_check`", :"`before_render`"
52
- )
53
- end
54
-
55
49
  if raise_errors
56
50
  component_class.validate_initialization_parameters!
57
51
  component_class.validate_collection_parameter!
@@ -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
@@ -3,6 +3,6 @@
3
3
  require "active_support/deprecation"
4
4
 
5
5
  module ViewComponent
6
- DEPRECATION_HORIZON = "3.0.0"
6
+ DEPRECATION_HORIZON = "4.0.0"
7
7
  Deprecation = ActiveSupport::Deprecation.new(DEPRECATION_HORIZON, "ViewComponent")
8
8
  end
@@ -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
- if args.empty? && block.nil?
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
- if collection_args.nil? && block.nil?
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
  #
@@ -2,11 +2,12 @@
2
2
 
3
3
  module ViewComponent
4
4
  module VERSION
5
- MAJOR = 2
6
- MINOR = 82
5
+ MAJOR = 3
6
+ MINOR = 0
7
7
  PATCH = 0
8
+ PRE = "rc1"
8
9
 
9
- STRING = [MAJOR, MINOR, PATCH].join(".")
10
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
10
11
  end
11
12
  end
12
13
 
@@ -23,13 +23,4 @@ module ViewComponent
23
23
  autoload :Translatable
24
24
  end
25
25
 
26
- # :nocov:
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: 2.82.0
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: 2023-01-11 00:00:00.000000000 Z
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,12 +400,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
402
400
  requirements:
403
401
  - - ">="
404
402
  - !ruby/object:Gem::Version
405
- version: 2.4.0
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: '0'
408
+ version: 1.3.1
411
409
  requirements: []
412
410
  rubygems_version: 3.2.32
413
411
  signing_key:
@@ -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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ViewComponent
4
- class Slot
5
- attr_accessor :content
6
- end
7
- end