Class: ActiveAdmin::MenuItem
Instance Attribute Summary collapse
-
#display_if_block ⇒ Object
Returns the display if block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#[](name) ⇒ Object
Returns the child item with the name passed in @blog_menu[“Create New”] => <#MenuItem @name=“Create New” >.
- #add(name, url, priority = 10, options = {}, &block) ⇒ Object
-
#ancestors ⇒ Object
Returns an array of the ancestory of this menu item The first item is the immediate parent fo the item.
- #children ⇒ Object
- #dom_id ⇒ Object
-
#initialize(name, url, priority = 10, options = {}) {|_self| ... } ⇒ MenuItem
constructor
A new instance of MenuItem.
- #parent? ⇒ Boolean
Constructor Details
#initialize(name, url, priority = 10, options = {}) {|_self| ... } ⇒ MenuItem
Returns a new instance of MenuItem.
9 10 11 12 13 14 15 16 17 |
# File 'lib/active_admin/menu_item.rb', line 9 def initialize(name, url, priority = 10, = {}) @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 = .delete(:if) yield(self) if block_given? # Builder style syntax end |
Instance Attribute Details
#display_if_block ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/active_admin/menu_item.rb', line 7 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/active_admin/menu_item.rb', line 7 def parent @parent end |
#priority ⇒ Object
Returns the value of attribute priority.
7 8 9 |
# File 'lib/active_admin/menu_item.rb', line 7 def priority @priority end |
#url ⇒ Object
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, = {}, &block) item = MenuItem.new(name, url, priority, , &block) item.parent = self @children << item end |
#ancestors ⇒ Object
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 |
#children ⇒ Object
25 26 27 |
# File 'lib/active_admin/menu_item.rb', line 25 def children @children.sort end |
#dom_id ⇒ Object
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
29 30 31 |
# File 'lib/active_admin/menu_item.rb', line 29 def parent? !parent.nil? end |