view_component 4.0.0.alpha3 → 4.0.0.alpha4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d926054ff51767aa08c688eef809327cbbda35e8b403a574af8baa642aefe7ed
4
- data.tar.gz: ed0a01b7b1fe98080c4c7210c7bdde4b474d08f4b0c5ab0a36c39e9e6631f185
3
+ metadata.gz: 70feada9d7f9456623bfed2a6c76a9546f8fe5596f81e0f47ed7059808b1a68d
4
+ data.tar.gz: 77d8002e2a0fdb344c3647972b9051ce1c3ac3bc299e49442c8631921a6b5437
5
5
  SHA512:
6
- metadata.gz: 54aa90e88b7fb9f0773842f0737739c15cfaff4609f62fe733badd14ab8676ec21532c5d00915947ce183aca678f7ed79573f15e8dec06f873067a9585a277ab
7
- data.tar.gz: 3c4187ccc4f70942964fedd232fb387314e5f7cfa47624df5def3006ff9478947d4de9380c0baf29b5102e20217de0eb77a9bfe8a21240a79065cb719d02bf94
6
+ metadata.gz: c3aeae640580d7d5c9192836fbc8ab26932a9527117438f4fa808fed36cd2c4393194fd66e5d01ddbc56bd0f0d5042b1707ee25b94760969b06a9d34a1700f85
7
+ data.tar.gz: cb4ee57d927b7b9a27436ec1d736675ee59fe2dfc7aa281e8c6a1b9be87fa517849bc3443a6057a01f1a3e1b97320e8d566681dc989c452fa8c45ff261e058c9
data/docs/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@ nav_order: 6
10
10
 
11
11
  ## main
12
12
 
13
+ ## 4.0.0.alpha4
14
+
15
+ * BREAKING: Remove default initializer from `ViewComponent::Base`. Previously, `ViewComponent::Base` defined a catch-all initializer that allowed components without an initializer defined to be passed arbitrary arguments.
16
+
17
+ *Joel Hawksley*
18
+
19
+ * Graduate `SlotableDefault` to be included by default.
20
+
21
+ *Joel Hawksley*
22
+
23
+ * Fix bug in `SlotableDefault` where default couldn't be overridden when content was passed as a block.
24
+
25
+ *Bill Watts*, *Joel Hawksley*
26
+
13
27
  ## 4.0.0.alpha3
14
28
 
15
29
  * BREAKING: Remove dependency on `ActionView::Base`, eliminating the need for capture compatibility patch.
@@ -12,7 +12,6 @@ require "view_component/inline_template"
12
12
  require "view_component/preview"
13
13
  require "view_component/request_details"
14
14
  require "view_component/slotable"
15
- require "view_component/slotable_default"
16
15
  require "view_component/template"
17
16
  require "view_component/translatable"
18
17
  require "view_component/with_content_helper"
@@ -216,12 +215,6 @@ module ViewComponent
216
215
  true
217
216
  end
218
217
 
219
- # Override the ActionView::Base initializer so that components
220
- # do not need to define their own initializers.
221
- # @private
222
- def initialize(*)
223
- end
224
-
225
218
  # Re-use original view_context if we're not rendering a component.
226
219
  #
227
220
  # This prevents an exception when rendering a partial inside of a component that has also been rendered outside
@@ -274,7 +267,7 @@ module ViewComponent
274
267
  raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.respond_to?(method_name)
275
268
  #{e.message}
276
269
 
277
- You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}'?
270
+ You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}`?
278
271
  MESSAGE
279
272
 
280
273
  raise
@@ -351,16 +351,26 @@ module ViewComponent
351
351
  end
352
352
 
353
353
  def get_slot(slot_name)
354
+ @__vc_set_slots ||= {}
354
355
  content unless content_evaluated? # ensure content is loaded so slots will be defined
355
356
 
356
- slot = self.class.registered_slots[slot_name]
357
- @__vc_set_slots ||= {}
357
+ # If the slot is set, return it
358
+ return @__vc_set_slots[slot_name] if @__vc_set_slots[slot_name]
358
359
 
359
- if @__vc_set_slots[slot_name]
360
- return @__vc_set_slots[slot_name]
361
- end
360
+ # If there is a default method for the slot, call it
361
+ if (default_method = registered_slots[slot_name][:default_method])
362
+ renderable_value = send(default_method)
363
+ slot = Slot.new(self)
364
+
365
+ if renderable_value.respond_to?(:render_in)
366
+ slot.__vc_component_instance = renderable_value
367
+ else
368
+ slot.__vc_content = renderable_value
369
+ end
362
370
 
363
- if slot[:collection]
371
+ slot
372
+ elsif self.class.registered_slots[slot_name][:collection]
373
+ # If empty slot is a collection, return an empty array
364
374
  []
365
375
  end
366
376
  end
@@ -5,7 +5,7 @@ module ViewComponent
5
5
  MAJOR = 4
6
6
  MINOR = 0
7
7
  PATCH = 0
8
- PRE = "alpha3"
8
+ PRE = "alpha4"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha3
4
+ version: 4.0.0.alpha4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ViewComponent Team
@@ -481,7 +481,6 @@ files:
481
481
  - lib/view_component/request_details.rb
482
482
  - lib/view_component/slot.rb
483
483
  - lib/view_component/slotable.rb
484
- - lib/view_component/slotable_default.rb
485
484
  - lib/view_component/system_test_case.rb
486
485
  - lib/view_component/system_test_helpers.rb
487
486
  - lib/view_component/template.rb
@@ -1,20 +0,0 @@
1
- module ViewComponent
2
- module SlotableDefault
3
- def get_slot(slot_name)
4
- @__vc_set_slots ||= {}
5
-
6
- return super unless !@__vc_set_slots[slot_name] && (default_method = registered_slots[slot_name][:default_method])
7
-
8
- renderable_value = send(default_method)
9
- slot = Slot.new(self)
10
-
11
- if renderable_value.respond_to?(:render_in)
12
- slot.__vc_component_instance = renderable_value
13
- else
14
- slot.__vc_content = renderable_value
15
- end
16
-
17
- slot
18
- end
19
- end
20
- end