Class: ViewComponent::Storybook::Collections::LayoutCollection
- Inherits:
-
Object
- Object
- ViewComponent::Storybook::Collections::LayoutCollection
- Includes:
- ValidForStoryConcern
- Defined in:
- lib/view_component/storybook/collections/layout_collection.rb
Instance Method Summary collapse
- #add(layout, only: nil, except: nil) ⇒ Object
-
#for_story(story_name) ⇒ Object
Parameters set for the story method.
-
#initialize ⇒ LayoutCollection
constructor
A new instance of LayoutCollection.
Methods included from ValidForStoryConcern
Constructor Details
#initialize ⇒ LayoutCollection
Returns a new instance of LayoutCollection.
9 10 11 12 |
# File 'lib/view_component/storybook/collections/layout_collection.rb', line 9 def initialize @default = nil @layouts = [] end |
Instance Method Details
#add(layout, only: nil, except: nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/view_component/storybook/collections/layout_collection.rb', line 14 def add(layout, only: nil, except: nil) if only.nil? && except.nil? @default = layout else layouts << { layout: layout, only: only, except: except } end end |
#for_story(story_name) ⇒ Object
Parameters set for the story method
23 24 25 26 27 28 29 |
# File 'lib/view_component/storybook/collections/layout_collection.rb', line 23 def for_story(story_name) story_layout = default layouts.each do |opts| story_layout = opts[:layout] if valid_for_story?(story_name, **opts.slice(:only, :except)) end story_layout end |