Class: ActiveAdmin::Views::MenuItem

Inherits:
Component
  • Object
show all
Defined in:
lib/active_admin/views/components/menu_item.rb

Overview

Arbre component used to render ActiveAdmin::MenuItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/active_admin/views/components/menu_item.rb', line 8

def label
  @label
end

#priorityObject (readonly)

Returns the value of attribute priority.



10
11
12
# File 'lib/active_admin/views/components/menu_item.rb', line 10

def priority
  @priority
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/active_admin/views/components/menu_item.rb', line 9

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object

Sorts by priority first, then alphabetically by label if needed.



38
39
40
41
# File 'lib/active_admin/views/components/menu_item.rb', line 38

def <=>(other)
  result = priority <=> other.priority
  result == 0 ? label <=> other.label : result
end

#build(item, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_admin/views/components/menu_item.rb', line 12

def build(item, options = {})
  super(options.merge(id: item.id))
  @label = helpers.render_in_context self, item.label
  @url = helpers.render_in_context self, item.url
  @priority = item.priority
  @submenu = nil

  add_class "current" if item.current? assigns[:current_tab]

  if url
    text_node link_to label, url, **item.html_options
  else
    span label, item.html_options
  end

  if item.items.any?
    add_class "has_nested"
    @submenu = menu(item)
  end
end

#tag_nameObject



33
34
35
# File 'lib/active_admin/views/components/menu_item.rb', line 33

def tag_name
  "li"
end

#to_sObject



47
48
49
# File 'lib/active_admin/views/components/menu_item.rb', line 47

def to_s
  visible? ? super : ""
end

#visible?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_admin/views/components/menu_item.rb', line 43

def visible?
  url.nil? || real_url? || @submenu && @submenu.children.any?
end