Class: ActiveAdmin::MenuItem
- Inherits:
-
Object
- Object
- ActiveAdmin::MenuItem
- Defined in:
- lib/active_admin/menu_item.rb
Instance Attribute Summary (collapse)
-
- (Object) children
Returns the value of attribute children.
-
- (Object) display_if_block
Returns the display if block.
-
- (Object) id
Returns the value of attribute id.
-
- (Object) label
Returns the value of attribute label.
-
- (Object) parent
Returns the value of attribute parent.
-
- (Object) priority
Returns the value of attribute priority.
-
- (Object) url
Returns the value of attribute url.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) <=>(other)
-
- (Object) [](id)
Returns the child item with the name passed in.
- - (Object) add(*menu_items)
-
- (Object) ancestors
Returns an array of the ancestory of this menu item The first item is the immediate parent fo the item.
- - (Object) dom_id
-
- (MenuItem) initialize(options = {}) {|_self| ... }
constructor
Build a new menu item.
- - (Boolean) parent?
Constructor Details
- (MenuItem) initialize(options = {}) {|_self| ... }
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
- (Object) children
Returns the value of attribute children
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def children @children end |
- (Object) display_if_block
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 |
- (Object) id
Returns the value of attribute id
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def id @id end |
- (Object) label
Returns the value of attribute label
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def label @label end |
- (Object) parent
Returns the value of attribute parent
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def parent @parent end |
- (Object) priority
Returns the value of attribute priority
5 6 7 |
# File 'lib/active_admin/menu_item.rb', line 5 def priority @priority end |
- (Object) url
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
+ (Object) generate_item_id(id)
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
- (Object) <=>(other)
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 |
- (Object) [](id)
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 |
- (Object) add(*menu_items)
62 63 64 65 66 67 |
# File 'lib/active_admin/menu_item.rb', line 62 def add(*) .each do || .parent = self @children << end end |
- (Object) ancestors
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 |
- (Object) dom_id
77 78 79 |
# File 'lib/active_admin/menu_item.rb', line 77 def dom_id id.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' ) end |
- (Boolean) parent?
73 74 75 |
# File 'lib/active_admin/menu_item.rb', line 73 def parent? !parent.nil? end |