Class: ViewComponent::Storybook::Collections::LayoutCollection

Inherits:
Object
  • Object
show all
Includes:
ValidForStoryConcern
Defined in:
lib/view_component/storybook/collections/layout_collection.rb

Instance Method Summary collapse

Methods included from ValidForStoryConcern

#valid_for_story?

Constructor Details

#initializeLayoutCollection

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