Class: Nav::Component

Inherits:
Lookbook::BaseComponent
  • Object
show all
Defined in:
app/components/lookbook/nav/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree:, id: nil, **attrs) ⇒ Component

Returns a new instance of Component.



8
9
10
11
12
# File 'app/components/lookbook/nav/component.rb', line 8

def initialize(tree:, id: nil, **attrs)
  @id = id
  @tree = tree
  super(**attrs, id: id)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'app/components/lookbook/nav/component.rb', line 6

def id
  @id
end

#treeObject (readonly)

Returns the value of attribute tree.



6
7
8
# File 'app/components/lookbook/nav/component.rb', line 6

def tree
  @tree
end

Instance Method Details

#itemsObject



14
15
16
17
18
19
# File 'app/components/lookbook/nav/component.rb', line 14

def items
  @items ||= tree.map do |node|
    item_class = (node.type == :directory) ? Nav::Directory::Component : Nav::Entity::Component
    lookbook_render item_class.new node, nav_id: id
  end
end