From 677c2167c8e1f72a95ce769cbcba859f83fb4db5 Mon Sep 17 00:00:00 2001 From: stephann <3025661+stephannv@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:21:17 -0300 Subject: [PATCH] Rename 'many' option to 'collection' (#6) --- benchmark/main.rb | 2 +- lib/phlex/slotable.rb | 22 +++++++++---------- .../phlex/test_multi_polymorphic_slot copy.rb | 4 ++-- test/phlex/test_multi_slot.rb | 2 +- test/phlex/test_multi_slot_with_component.rb | 2 +- test/phlex/test_multi_slot_with_lambda.rb | 4 ++-- test/phlex/test_multi_slot_with_string.rb | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/benchmark/main.rb b/benchmark/main.rb index 4440325..b850c85 100644 --- a/benchmark/main.rb +++ b/benchmark/main.rb @@ -34,7 +34,7 @@ class SlotableList < Phlex::HTML include Phlex::Slotable slot :header - slot :item, many: true + slot :item, collection: true def template if header_slot diff --git a/lib/phlex/slotable.rb b/lib/phlex/slotable.rb index 272384c..9320346 100644 --- a/lib/phlex/slotable.rb +++ b/lib/phlex/slotable.rb @@ -9,26 +9,26 @@ def self.included(base) end module ClassMethods - def slot(slot_name, callable = nil, types: nil, many: false) + def slot(slot_name, callable = nil, types: nil, collection: false) include Phlex::DeferredRender if types types.each do |type, callable| - define_setter_method(slot_name, callable, many: many, type: type) + define_setter_method(slot_name, callable, collection: collection, type: type) end else - define_setter_method(slot_name, callable, many: many) + define_setter_method(slot_name, callable, collection: collection) end - define_predicate_method(slot_name, many: many) - define_getter_method(slot_name, many: many) + define_predicate_method(slot_name, collection: collection) + define_getter_method(slot_name, collection: collection) end private - def define_setter_method(slot_name, callable, many:, type: nil) + def define_setter_method(slot_name, callable, collection:, type: nil) slot_name_with_type = type ? "#{type}_#{slot_name}" : slot_name - setter_method = if many + setter_method = if collection <<-RUBY def with_#{slot_name_with_type}(*args, **kwargs, &block) @#{slot_name}_slots ||= [] @@ -52,8 +52,8 @@ def define_lambda_method(slot_name, callable) private :"__call_#{slot_name}__" end - def define_getter_method(slot_name, many:) - getter_method = if many + def define_getter_method(slot_name, collection:) + getter_method = if collection <<-RUBY def #{slot_name}_slots @#{slot_name}_slots ||= [] @@ -72,8 +72,8 @@ def #{slot_name}_slot class_eval(getter_method, __FILE__, __LINE__ + 1) end - def define_predicate_method(slot_name, many:) - predicate_method = if many + def define_predicate_method(slot_name, collection:) + predicate_method = if collection <<-RUBY def #{slot_name}_slots? #{slot_name}_slots.any? diff --git a/test/phlex/test_multi_polymorphic_slot copy.rb b/test/phlex/test_multi_polymorphic_slot copy.rb index ebef10d..41ccd7b 100644 --- a/test/phlex/test_multi_polymorphic_slot copy.rb +++ b/test/phlex/test_multi_polymorphic_slot copy.rb @@ -16,13 +16,13 @@ def template class UsersList < Phlex::HTML include Phlex::Slotable - slot :avatar, types: { + slot :avatar, collection: true, types: { image: ImageComponent, icon: "IconComponent", text: ->(size:, &content) do span(class: "text-#{size}", &content) end - }, many: true + } def template if avatar_slots? diff --git a/test/phlex/test_multi_slot.rb b/test/phlex/test_multi_slot.rb index 95258cb..0287493 100644 --- a/test/phlex/test_multi_slot.rb +++ b/test/phlex/test_multi_slot.rb @@ -6,7 +6,7 @@ class Phlex::TestMultiSlot < Minitest::Test class Blog < Phlex::HTML include Phlex::Slotable - slot :post, many: true + slot :post, collection: true def template if post_slots? diff --git a/test/phlex/test_multi_slot_with_component.rb b/test/phlex/test_multi_slot_with_component.rb index 63a2757..a4eaa18 100644 --- a/test/phlex/test_multi_slot_with_component.rb +++ b/test/phlex/test_multi_slot_with_component.rb @@ -16,7 +16,7 @@ def template(&content) class Blog < Phlex::HTML include Phlex::Slotable - slot :post, PostComponent, many: true + slot :post, PostComponent, collection: true def template if post_slots? diff --git a/test/phlex/test_multi_slot_with_lambda.rb b/test/phlex/test_multi_slot_with_lambda.rb index d58f843..0957023 100644 --- a/test/phlex/test_multi_slot_with_lambda.rb +++ b/test/phlex/test_multi_slot_with_lambda.rb @@ -25,10 +25,10 @@ def template class Blog < Phlex::HTML include Phlex::Slotable - slot :post, ->(featured: false, &content) { p(class: featured ? "featured" : nil, &content) }, many: true + slot :post, ->(featured: false, &content) { p(class: featured ? "featured" : nil, &content) }, collection: true slot :headline, ->(size:, &content) do render HeadlineComponent.new(size: size, bg_color: @headline_bg_color), &content - end, many: true + end, collection: true def initialize(headline_bg_color: nil) @headline_bg_color = headline_bg_color diff --git a/test/phlex/test_multi_slot_with_string.rb b/test/phlex/test_multi_slot_with_string.rb index 0e863a1..c798349 100644 --- a/test/phlex/test_multi_slot_with_string.rb +++ b/test/phlex/test_multi_slot_with_string.rb @@ -6,7 +6,7 @@ class Phlex::TestMultiSlotWithString < Minitest::Test class Blog < Phlex::HTML include Phlex::Slotable - slot :post, "PostComponent", many: true + slot :post, "PostComponent", collection: true def template if post_slots?