Skip to content

Commit

Permalink
Fix up documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakeWilliams committed Oct 16, 2020
1 parent 8066beb commit c9a3656
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lib/view_component/slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

module ViewComponent
class Slot
# Necessary for Slots v1
attr_accessor :content

def _view_component_internal_content=(content)
@_view_component_internal_content = content
end
Expand Down
57 changes: 43 additions & 14 deletions lib/view_component/slotable_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ module V2
#
# = Example
#
# with_slot(
# :item,
# collection: true
# ) do
# def initialize(name:)
# renders_one :header do
# def initialize(classes:)
# @name = name
# end
# end
Expand All @@ -40,9 +37,7 @@ module V2
# is a collection).
#
# <h1>
# <%= items.each do |item| %>
# <%= item.content %>
# <% end %>
# <%= header %>
# </h1>
#
# = Setting slot content
Expand All @@ -53,12 +48,8 @@ module V2
# slot.
#
# <%= render_inline(MyComponent.new) do |component| %>
# <%= component.item(name: "Foo") do %>
# <p>One</p>
# <% end %>
#
# <%= component.item(name: "Bar") do %>
# <p>two</p>
# <%= component.header(classes: "Foo") do %>
# <p>Bar</p>
# <% end %>
# <% end %>
def renders_one(slot_name, &block)
Expand All @@ -75,6 +66,44 @@ def renders_one(slot_name, &block)
register_slot(slot_name, collection: false, &block)
end

##
# Registers a collection slot on the component.
#
# = Example
#
# render_many :items do
# def initialize(name:)
# @name = name
# end
# end
#
# = Rendering slot content
#
# The component's sidecar template can access the slot by calling a
# helper method with the same name as the slot (pluralized if the slot
# is a collection).
#
# <h1>
# <%= items.each do |item| %>
# <%= item %>
# <% end %>
# </h1>
#
# = Setting slot content
#
# Renderers of the component can set the content of a slot by calling a
# helper method with the same name as the slot. The method can be
# called multiple times to append to the slot.
#
# <%= render_inline(MyComponent.new) do |component| %>
# <%= component.item(name: "Foo") do %>
# <p>One</p>
# <% end %>
#
# <%= component.item(name: "Bar") do %>
# <p>two</p>
# <% end %>
# <% end %>
def renders_many(slot_name, &block)
validate_slot_name(slot_name)

Expand Down

0 comments on commit c9a3656

Please sign in to comment.