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.



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

def label
  @label
end

#priorityObject (readonly)

Returns the value of attribute priority.



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

def priority
  @priority
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object

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



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

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

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



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

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



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

def tag_name
  'li'
end

#to_sObject



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

def to_s
  visible? ? super : ''
end

#visible?Boolean

Returns:

  • (Boolean)


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

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