view_component 2.62.0 → 2.65.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.

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: e57d7d7eece678a577cf5f89f4b506fbe1026c79cc8b28d269e6984a01de29c7
4
- data.tar.gz: e8fd167897e4bbcfaf0b4d657605acf26a5e1c6dc72e6fd5a868e0e0e76d232b
3
+ metadata.gz: db3da8b9e69982d34a963e91a36a872b8c09a83526b142e51c0cf9548c0d704e
4
+ data.tar.gz: 305ea910ad67535dd4769d3c570bb11a3ef37aea09118174b0861ec7089ee234
5
5
  SHA512:
6
- metadata.gz: a6bae85903899c93cb78e11a49082c4e6c2393605c9b3e94cca98ecff1e790a97dd7acda4c5e13b11ad4e4591384d0d30e62d86831998577531b595378f9fcb7
7
- data.tar.gz: 814913871cc0d5b4865a6864a0585f06d6c26088cdbab888e4c4d33787f7ab2e74c9dafffd52fe726999d03b9a453186b3f495afc1c0c9da5207b5edb3a89480
6
+ metadata.gz: 842babf3fd5a9c1e15c803e2605e6e4891b08c0766948f1e5a0e72bdaaf0b129a8b26959684adb8be257d295681ef241e3c828651a72e1badda342382cfca662
7
+ data.tar.gz: 920553b0b73da80802fb940821fb454cf7587063d7df89630f4fb9425c123b38cfc5e3e49b912022a556a8207f6ca8e6e47662d86056dbf603c548eb9197dee2
data/docs/CHANGELOG.md CHANGED
@@ -9,6 +9,59 @@ title: Changelog
9
9
 
10
10
  ## main
11
11
 
12
+ ## 2.65.0
13
+
14
+ * Raise `ArgumentError` when conflicting Slots are defined.
15
+
16
+ Before this change it was possible to define Slots with conflicting names, for example:
17
+
18
+ ```ruby
19
+ class MyComponent < ViewComponent::Base
20
+ renders_one :item
21
+ renders_many :items
22
+ end
23
+ ```
24
+
25
+ *Joel Hawksley*
26
+
27
+ ## 2.64.0
28
+
29
+ * Add `warn_on_deprecated_slot_setter` flag to opt-in to deprecation warning.
30
+
31
+ In [v2.54.0](https://viewcomponent.org/CHANGELOG.html#2540), the Slots API was updated to require the `with_*` prefix for setting Slots. The non-`with_*` setters will be deprecated in a coming version and removed in `v3.0`.
32
+
33
+ To enable the coming deprecation warning, add `warn_on_deprecated_slot_setter`:
34
+
35
+ ```ruby
36
+ class DeprecatedSlotsSetterComponent < ViewComponent::Base
37
+ warn_on_deprecated_slot_setter
38
+ end
39
+ ```
40
+
41
+ *Joel Hawksley*
42
+
43
+ * Add [`m`](https://rubygems.org/gems/m) to development environment.
44
+
45
+ *Joel Hawksley*
46
+
47
+ * Fix potential deadlock scenario in the compiler's development mode.
48
+
49
+ *Blake Williams*
50
+
51
+ ## 2.63.0
52
+
53
+ * Fixed typo in `renders_many` documentation.
54
+
55
+ *Graham Rogers*
56
+
57
+ * Add documentation about working with `turbo-rails`.
58
+
59
+ *Matheus Poli Camilo*
60
+
61
+ * Fix issue causing helper methods to not be available in nested components when the render monkey patch is disabled and `render_component` is used.
62
+
63
+ *Daniel Scheffknecht*
64
+
12
65
  ## 2.62.0
13
66
 
14
67
  * Remove the experimental global output buffer feature.
@@ -25,6 +78,10 @@ title: Changelog
25
78
 
26
79
  *Josh Clayton*
27
80
 
81
+ * Add predicate method support to polymorphic slots.
82
+
83
+ *Graham Rogers*
84
+
28
85
  ## 2.61.1
29
86
 
30
87
  * Revert `Expose Capybara DSL methods directly inside tests.` This change unintentionally broke other Capybara methods and thus introduced a regression. We aren't confident that we can fail forward so we have decided to revert this change.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "concurrent-ruby"
4
+
3
5
  module ViewComponent
4
6
  class Compiler
5
7
  # Lock required to be obtained before compiling the component
@@ -16,7 +18,7 @@ module ViewComponent
16
18
 
17
19
  def initialize(component_class)
18
20
  @component_class = component_class
19
- @__vc_compiler_lock = Monitor.new
21
+ @__vc_compiler_lock = Concurrent::ReadWriteLock.new
20
22
  end
21
23
 
22
24
  def compiled?
@@ -33,7 +35,7 @@ module ViewComponent
33
35
 
34
36
  component_class.superclass.compile(raise_errors: raise_errors) if should_compile_superclass?
35
37
 
36
- with_lock do
38
+ with_write_lock do
37
39
  CompileCache.invalidate_class!(component_class)
38
40
 
39
41
  subclass_instance_methods = component_class.instance_methods(false)
@@ -90,14 +92,18 @@ module ViewComponent
90
92
  end
91
93
  end
92
94
 
93
- def with_lock(&block)
95
+ def with_write_lock(&block)
94
96
  if development?
95
- __vc_compiler_lock.synchronize(&block)
97
+ __vc_compiler_lock.with_write_lock(&block)
96
98
  else
97
99
  block.call
98
100
  end
99
101
  end
100
102
 
103
+ def with_read_lock(&block)
104
+ __vc_compiler_lock.with_read_lock(&block)
105
+ end
106
+
101
107
  private
102
108
 
103
109
  attr_reader :component_class
@@ -123,7 +129,7 @@ module ViewComponent
123
129
  if development?
124
130
  component_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
125
131
  def render_template_for(variant = nil)
126
- self.class.compiler.with_lock do
132
+ self.class.compiler.with_read_lock do
127
133
  #{body}
128
134
  end
129
135
  end
@@ -42,6 +42,10 @@ module ViewComponent
42
42
  define_method(getter_name) do
43
43
  get_slot(slot_name)
44
44
  end
45
+
46
+ define_method("#{getter_name}?") do
47
+ get_slot(slot_name).present?
48
+ end
45
49
  end
46
50
 
47
51
  renderable_hash = types.each_with_object({}) do |(poly_type, poly_callable), memo|
@@ -57,10 +61,12 @@ module ViewComponent
57
61
  end
58
62
 
59
63
  define_method(setter_name) do |*args, &block|
60
- ViewComponent::Deprecation.warn(
61
- "polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in " \
62
- "ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
63
- )
64
+ if _warn_on_deprecated_slot_setter
65
+ ViewComponent::Deprecation.warn(
66
+ "polymorphic slot setters like `#{setter_name}` are deprecated and will be removed in " \
67
+ "ViewComponent v3.0.0.\n\nUse `with_#{setter_name}` instead."
68
+ )
69
+ end
64
70
 
65
71
  set_polymorphic_slot(slot_name, poly_type, *args, &block)
66
72
  end
@@ -3,6 +3,7 @@
3
3
  module ViewComponent
4
4
  module RenderComponentHelper # :nodoc:
5
5
  def render_component(component, &block)
6
+ component.set_original_view_context(__vc_original_view_context) if is_a?(ViewComponent::Base)
6
7
  component.render_in(self, &block)
7
8
  end
8
9
  end
@@ -17,9 +17,19 @@ 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
20
23
  end
21
24
 
22
25
  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
+
23
33
  ##
24
34
  # Registers a sub-component
25
35
  #
@@ -70,6 +80,7 @@ module ViewComponent
70
80
  # <% end %>
71
81
  def renders_one(slot_name, callable = nil)
72
82
  validate_singular_slot_name(slot_name)
83
+ validate_plural_slot_name(ActiveSupport::Inflector.pluralize(slot_name).to_sym)
73
84
 
74
85
  define_method :"with_#{slot_name}" do |*args, &block|
75
86
  set_slot(slot_name, nil, *args, &block)
@@ -80,7 +91,13 @@ module ViewComponent
80
91
  if args.empty? && block.nil?
81
92
  get_slot(slot_name)
82
93
  else
83
- # Deprecated: Will remove in 3.0
94
+ if _warn_on_deprecated_slot_setter
95
+ ViewComponent::Deprecation.warn(
96
+ "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
97
+ "Use `#with_#{slot_name}` to set the slot instead."
98
+ )
99
+ end
100
+
84
101
  set_slot(slot_name, nil, *args, &block)
85
102
  end
86
103
  end
@@ -98,11 +115,11 @@ module ViewComponent
98
115
  #
99
116
  # = Example
100
117
  #
101
- # render_many :items, -> (name:) { ItemComponent.new(name: name }
118
+ # renders_many :items, -> (name:) { ItemComponent.new(name: name }
102
119
  #
103
120
  # # OR
104
121
  #
105
- # render_many :items, ItemComponent
122
+ # renders_many :items, ItemComponent
106
123
  #
107
124
  # = Rendering sub-components
108
125
  #
@@ -131,16 +148,22 @@ module ViewComponent
131
148
  # <% end %>
132
149
  # <% end %>
133
150
  def renders_many(slot_name, callable = nil)
134
- validate_plural_slot_name(slot_name)
135
-
136
151
  singular_name = ActiveSupport::Inflector.singularize(slot_name)
152
+ validate_plural_slot_name(slot_name)
153
+ validate_singular_slot_name(ActiveSupport::Inflector.singularize(slot_name).to_sym)
137
154
 
138
155
  # Define setter for singular names
139
156
  # for example `renders_many :items` allows fetching all tabs with
140
157
  # `component.tabs` and setting a tab with `component.tab`
141
- #
142
- # Deprecated: Will remove in 3.0
158
+
143
159
  define_method singular_name do |*args, &block|
160
+ if _warn_on_deprecated_slot_setter
161
+ ViewComponent::Deprecation.warn(
162
+ "Setting a slot with `##{singular_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
163
+ "Use `#with_#{singular_name}` to set the slot instead."
164
+ )
165
+ end
166
+
144
167
  set_slot(slot_name, nil, *args, &block)
145
168
  end
146
169
  ruby2_keywords(singular_name.to_sym) if respond_to?(:ruby2_keywords, true)
@@ -162,7 +185,13 @@ module ViewComponent
162
185
  if collection_args.nil? && block.nil?
163
186
  get_slot(slot_name)
164
187
  else
165
- # Deprecated: Will remove in 3.0
188
+ if _warn_on_deprecated_slot_setter
189
+ ViewComponent::Deprecation.warn(
190
+ "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
191
+ "Use `#with_#{slot_name}` to set the slot instead."
192
+ )
193
+ end
194
+
166
195
  collection_args.map do |args|
167
196
  set_slot(slot_name, nil, **args, &block)
168
197
  end
@@ -3,7 +3,7 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 62
6
+ MINOR = 65
7
7
  PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
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.62.0
4
+ version: 2.65.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-25 00:00:00.000000000 Z
11
+ date: 2022-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: concurrent-ruby
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: appraisal
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +156,20 @@ dependencies:
142
156
  - - "~>"
143
157
  - !ruby/object:Gem::Version
144
158
  version: '2'
159
+ - !ruby/object:Gem::Dependency
160
+ name: m
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '1'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '1'
145
173
  - !ruby/object:Gem::Dependency
146
174
  name: minitest
147
175
  requirement: !ruby/object:Gem::Requirement