Class: Nav::Entity::Component

Inherits:
Item::Component
  • Object
show all
Defined in:
app/components/lookbook/nav/entity/component.rb

Constant Summary collapse

ICONS =
{
  page: :file,
  preview: :layers,
  scenario: :eye,
  scenario_group: :eye
}.freeze

Instance Method Summary collapse

Instance Method Details

#childrenObject



22
23
24
# File 'app/components/lookbook/nav/entity/component.rb', line 22

def children
  collapsed? ? [] : super
end

#collapsed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/components/lookbook/nav/entity/component.rb', line 30

def collapsed?
  node.type == :preview && node.children.one?
end

#hrefObject



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

def href
  if collapsed?
    node.first.url_path
  elsif type != :preview
    node.url_path
  end
end


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

def nav_icon
  ICONS[collapsed? ? :preview : node.type] || :file
end

#search_termsObject



34
35
36
37
38
39
40
41
# File 'app/components/lookbook/nav/entity/component.rb', line 34

def search_terms
  matchers = if collapsed?
    node.first.search_terms
  else
    node.respond_to?(:search_terms) ? Array(node.search_terms) : []
  end
  matchers.flatten.map { |m| m.gsub(/\s/, "").downcase }
end

#typeObject



26
27
28
# File 'app/components/lookbook/nav/entity/component.rb', line 26

def type
  collapsed? ? :scenario : node.type
end