Class: ActiveAdmin::MenuItem
- Inherits:
-
Object
- Object
- ActiveAdmin::MenuItem
- Defined in:
- lib/active_admin/menu_item.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#display_if_block ⇒ Object
Returns the display if block.
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#[](id) ⇒ Object
Returns the child item with the name passed in @blog_menu[“Create New”] => <#MenuItem @name=“Create New” >.
- #add(*menu_items) ⇒ Object
-
#ancestors ⇒ Object
Returns an array of the ancestory of this menu item The first item is the immediate parent fo the item.
- #dom_id ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ MenuItem
constructor
Build a new menu item.
- #parent? ⇒ Boolean
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ MenuItem
Build a new menu item
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_admin/menu_item.rb', line 36 def initialize( = {}) @label = [:label] @id = MenuItem.generate_item_id([:id] || label) @url = [:url] @priority = [:priority] || 10 @children = Menu::ItemCollection.new @parent = [:parent] @display_if_block = [:if] yield(self) if block_given? # Builder style syntax end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def children @children end |
#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.
102 103 104 |
# File 'lib/active_admin/menu_item.rb', line 102 def display_if_block @display_if_block end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def label @label end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def parent @parent end |
#priority ⇒ Object
Returns the value of attribute priority.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def priority @priority end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def url @url end |
Class Method Details
.generate_item_id(id) ⇒ Object
49 50 51 |
# File 'lib/active_admin/menu_item.rb', line 49 def self.generate_item_id(id) id.to_s.downcase.gsub(" ", "_") end |
Instance Method Details
#<=>(other) ⇒ Object
94 95 96 97 98 |
# File 'lib/active_admin/menu_item.rb', line 94 def <=>(other) result = priority <=> other.priority result = label <=> other.label if result == 0 result end |
#[](id) ⇒ Object
Returns the child item with the name passed in
@blog_menu["Create New"] => <#MenuItem @name="Create New" >
90 91 92 |
# File 'lib/active_admin/menu_item.rb', line 90 def [](id) @children.find_by_id(id) end |
#add(*menu_items) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/active_admin/menu_item.rb', line 62 def add(*) .each do || .parent = self @children << end end |
#ancestors ⇒ Object
Returns an array of the ancestory of this menu item The first item is the immediate parent fo the item
83 84 85 86 |
# File 'lib/active_admin/menu_item.rb', line 83 def ancestors return [] unless parent? [parent, parent.ancestors].flatten end |
#dom_id ⇒ Object
77 78 79 |
# File 'lib/active_admin/menu_item.rb', line 77 def dom_id id.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' ) end |
#parent? ⇒ Boolean
73 74 75 |
# File 'lib/active_admin/menu_item.rb', line 73 def parent? !parent.nil? end |