diff --git a/lib/view_component/slot.rb b/lib/view_component/slot.rb index 993555f620..df48a6e32a 100644 --- a/lib/view_component/slot.rb +++ b/lib/view_component/slot.rb @@ -2,6 +2,12 @@ module ViewComponent class Slot - attr_accessor :content + def _view_component_internal_content=(content) + @_view_component_internal_content = content + end + + def to_s + @_view_component_internal_content + end end end diff --git a/lib/view_component/slotable_v2.rb b/lib/view_component/slotable_v2.rb index e728521ed7..3afa692edc 100644 --- a/lib/view_component/slotable_v2.rb +++ b/lib/view_component/slotable_v2.rb @@ -132,11 +132,6 @@ def validate_slot_name(slot_name) if self.registered_slots.key?(slot_name) raise ArgumentError.new("#{slot_name} slot declared multiple times") end - - # Ensure slot name is not :content - if slot_name == :content - raise ArgumentError.new ":content is a reserved slot name. Please use another name, such as ':body'" - end end end @@ -175,7 +170,7 @@ def set_slot(slot_name, *args, **kwargs, &block) end if block_given? - slot_instance.content = view_context.capture(&block) + slot_instance._view_component_internal_content = view_context.capture(&block) end if slot[:collection] diff --git a/test/app/components/slots_v2_component.html.erb b/test/app/components/slots_v2_component.html.erb index 90a1c192bd..7f88e24b28 100644 --- a/test/app/components/slots_v2_component.html.erb +++ b/test/app/components/slots_v2_component.html.erb @@ -1,16 +1,16 @@
- <%= title.content %> + <%= title %>
- <%= subtitle.content %> + <%= subtitle %>
diff --git a/test/app/components/slots_v2_with_pos_arg_component.html.erb b/test/app/components/slots_v2_with_pos_arg_component.html.erb index a9b4018b95..2272d06bc2 100644 --- a/test/app/components/slots_v2_with_pos_arg_component.html.erb +++ b/test/app/components/slots_v2_with_pos_arg_component.html.erb @@ -3,7 +3,7 @@

<%= item.title %>

- <%= item.content %> + <%= item %>
<% end %> diff --git a/test/view_component/slotable_v2_test.rb b/test/view_component/slotable_v2_test.rb index d6bf1293d9..20297d1c92 100644 --- a/test/view_component/slotable_v2_test.rb +++ b/test/view_component/slotable_v2_test.rb @@ -86,14 +86,6 @@ def test_with_slot_raise_with_duplicate_slot_name assert_includes exception.message, "title slot declared multiple times" end - def test_with_slot_raise_with_content_keyword - exception = assert_raises ArgumentError do - SlotsV2Component.renders_one :content - end - - assert_includes exception.message, ":content is a reserved slot name" - end - def test_with_slot_with_positional_args render_inline(SlotsV2WithPosArgComponent.new(class_names: "mt-4")) do |component| component.item("my item", class_names: "hello") { "My rad item" }