Class: ActiveAdmin::MenuItem
- Inherits:
-
Object
- Object
- ActiveAdmin::MenuItem
- Defined in:
- lib/active_admin/menu_item.rb
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.
Class Method Summary collapse
-
.generate_url(named_route) ⇒ Object
Generates a route using the rails application url helpers.
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.
16 17 18 19 20 21 22 23 24 |
# File 'lib/active_admin/menu_item.rb', line 16 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.
75 76 77 |
# File 'lib/active_admin/menu_item.rb', line 75 def display_if_block @display_if_block end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/active_admin/menu_item.rb', line 14 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
14 15 16 |
# File 'lib/active_admin/menu_item.rb', line 14 def parent @parent end |
#priority ⇒ Object
Returns the value of attribute priority.
14 15 16 |
# File 'lib/active_admin/menu_item.rb', line 14 def priority @priority end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/active_admin/menu_item.rb', line 14 def url @url end |
Class Method Details
.generate_url(named_route) ⇒ Object
Generates a route using the rails application url helpers
10 11 12 |
# File 'lib/active_admin/menu_item.rb', line 10 def self.generate_url(named_route) Rails.application.routes.url_helpers.send(named_route) end |
Instance Method Details
#<=>(other) ⇒ Object
67 68 69 70 71 |
# File 'lib/active_admin/menu_item.rb', line 67 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" >
63 64 65 |
# File 'lib/active_admin/menu_item.rb', line 63 def [](name) @children.find{ |i| i.name == name } end |
#add(name, url, priority = 10, options = {}, &block) ⇒ Object
26 27 28 29 30 |
# File 'lib/active_admin/menu_item.rb', line 26 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
56 57 58 59 |
# File 'lib/active_admin/menu_item.rb', line 56 def ancestors return [] unless parent? [parent, parent.ancestors].flatten end |
#children ⇒ Object
32 33 34 |
# File 'lib/active_admin/menu_item.rb', line 32 def children @children.sort end |
#dom_id ⇒ Object
40 41 42 |
# File 'lib/active_admin/menu_item.rb', line 40 def dom_id name.downcase.gsub( " ", '_' ).gsub( /[^a-z0-9_]/, '' ) end |
#parent? ⇒ Boolean
36 37 38 |
# File 'lib/active_admin/menu_item.rb', line 36 def parent? !parent.nil? end |