Class: ActiveAdmin::MenuItem
- Inherits:
-
Object
- Object
- ActiveAdmin::MenuItem
- Includes:
- ActiveAdmin::Menu::MenuNode, MethodOrProcHelper
- Defined in:
- lib/active_admin/menu_item.rb
Instance Attribute Summary collapse
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Attributes included from ActiveAdmin::Menu::MenuNode
Instance Method Summary collapse
-
#ancestors ⇒ Object
Returns an array of the ancestory of this menu item.
-
#display?(context = nil) ⇒ Boolean
Don’t display if the :if option passed says so Don’t display if the link isn’t real, we have children, and none of the children are being displayed.
- #id ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ MenuItem
constructor
Builds a new menu item.
- #label(context = nil) ⇒ Object
- #url(context = nil) ⇒ Object
Methods included from MethodOrProcHelper
#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on
Methods included from ActiveAdmin::Menu::MenuNode
#[], #[]=, #add, #current?, #include?, #items
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ MenuItem
Builds a new menu item
NOTE: for :label, :url, and :if These options are evaluated in the view context at render time. Symbols are called as methods on self, and Procs are exec’d within self. Here are some examples of what you can do:
if: :admin?
url: :new_book_path
url: :awesome_helper_you_defined
label: ->{ User.some_method }
label: ->{ I18n.t 'menus.user' }
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_admin/menu_item.rb', line 49 def initialize( = {}) super() # MenuNode @label = [:label] @dirty_id = [:id] || [:label] @url = [:url] || '#' @priority = [:priority] || 10 @html_options = [:html_options] || {} @should_display = [:if] || proc{true} @parent = [:parent] yield(self) if block_given? # Builder style syntax end |
Instance Attribute Details
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
8 9 10 |
# File 'lib/active_admin/menu_item.rb', line 8 def @html_options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/active_admin/menu_item.rb', line 8 def parent @parent end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
8 9 10 |
# File 'lib/active_admin/menu_item.rb', line 8 def priority @priority end |
Instance Method Details
#ancestors ⇒ Object
Returns an array of the ancestory of this menu item. The first item is the immediate parent of the item.
84 85 86 |
# File 'lib/active_admin/menu_item.rb', line 84 def ancestors parent ? [parent, parent.ancestors].flatten : [] end |
#display?(context = nil) ⇒ Boolean
Don’t display if the :if option passed says so Don’t display if the link isn’t real, we have children, and none of the children are being displayed.
76 77 78 79 80 |
# File 'lib/active_admin/menu_item.rb', line 76 def display?(context = nil) return false unless render_in_context(context, @should_display) return false if !real_url?(context) && @children.any? && !items(context).any? true end |
#id ⇒ Object
62 63 64 |
# File 'lib/active_admin/menu_item.rb', line 62 def id @id ||= normalize_id @dirty_id end |
#label(context = nil) ⇒ Object
66 67 68 |
# File 'lib/active_admin/menu_item.rb', line 66 def label(context = nil) render_in_context context, @label end |
#url(context = nil) ⇒ Object
70 71 72 |
# File 'lib/active_admin/menu_item.rb', line 70 def url(context = nil) render_in_context context, @url end |