Class: ActiveAdmin::MenuItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, priority = 10, options = {}) {|_self| ... } ⇒ MenuItem

Returns a new instance of MenuItem.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
16
17
# File 'lib/active_admin/menu_item.rb', line 9

def initialize(name, url, priority = 10, options = {})
  @name, @url, @priority = name, url, priority
  @children = []
  @cached_url = {} # Stores the cached url in a hash to allow us to change it and still cache it

  @display_if_block = options.delete(:if)
  
  yield(self) if block_given? # Builder style syntax
end

Instance Attribute Details

#display_if_blockObject

Returns the display if block. If the block was not explicitly defined a default block always returning true will be returned.



68
69
70
# File 'lib/active_admin/menu_item.rb', line 68

def display_if_block
  @display_if_block
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#priorityObject

Returns the value of attribute priority.



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

def priority
  @priority
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object



60
61
62
63
64
# File 'lib/active_admin/menu_item.rb', line 60

def <=>(other)
  result = priority <=> other.priority
  result = name <=> other.name if result == 0
  result
end

#[](name) ⇒ Object

Returns the child item with the name passed in

@blog_menu["Create New"] => <#MenuItem @name="Create New" >


56
57
58
# File 'lib/active_admin/menu_item.rb', line 56

def [](name)
  @children.find{ |i| i.name == name }
end

#add(name, url, priority = 10, options = {}, &block) ⇒ Object



19
20
21
22
23
# File 'lib/active_admin/menu_item.rb', line 19

def add(name, url, priority=10, options = {}, &block)
  item = MenuItem.new(name, url, priority, options, &block)
  item.parent = self
  @children << item
end

#ancestorsObject

Returns an array of the ancestory of this menu item The first item is the immediate parent fo the item



49
50
51
52
# File 'lib/active_admin/menu_item.rb', line 49

def ancestors
  return [] unless parent?
  [parent, parent.ancestors].flatten
end

#childrenObject



25
26
27
# File 'lib/active_admin/menu_item.rb', line 25

def children
  @children.sort
end

#dom_idObject



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

def dom_id
  name.downcase.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' )
end

#parent?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/active_admin/menu_item.rb', line 29

def parent?
  !parent.nil?
end