Skip to content

Commit

Permalink
standardize utility navigation creation
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley committed Nov 26, 2013
1 parent acebc09 commit 1757daa
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/active_admin/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,35 @@ def build_menu(name = DEFAULT_MENU, &block)
end
end

# Add the default logout button to the menu, using the ActiveAdmin configuration settings
# The default logout menu item
#
# @param [ActiveAdmin::MenuItem] menu The menu to add the logout link to
# @param [Fixnum] priority Override the default priority of 100 to position the logout button where you want
# @param [Fixnum] priority The numeric priority for the order in which it appears
# @param [Hash] html_options An options hash to pass along to link_to
#
# @returns [void]
def add_logout_button_to_menu(menu, priority=100, html_options={})
def add_logout_button_to_menu(menu, priority = 20, html_options = {})
if logout_link_path
logout_method = logout_link_method || :get
menu.add :id => 'logout',
:priority => priority,
:label => proc{ I18n.t('active_admin.logout') },
:html_options => html_options.reverse_merge(:method => logout_method),
:url => proc{ render_or_call_method_or_proc_on self, active_admin_namespace.logout_link_path },
:if => proc{ current_active_admin_user? }
html_options = html_options.reverse_merge(method: logout_link_method || :get)
menu.add id: 'logout', priority: priority, html_options: html_options,
label: ->{ I18n.t 'active_admin.logout' },
url: ->{ render_or_call_method_or_proc_on self, active_admin_namespace.logout_link_path },
if: :current_active_admin_user?
end
end

def add_current_user_to_menu(menu)
menu.add label: proc{ display_name current_active_admin_user },
url: proc{ url_for [active_admin_namespace.name, current_active_admin_user] rescue '#' },
id: 'current_user',
if: proc{ current_active_admin_user? }
# The default user session menu item
#
# @param [ActiveAdmin::MenuItem] menu The menu to add the logout link to
# @param [Fixnum] priority The numeric priority for the order in which it appears
# @param [Hash] html_options An options hash to pass along to link_to
#
def add_current_user_to_menu(menu, priority = 10, html_options = {})
if current_user_method
menu.add id: 'current_user', priority: priority, html_options: html_options,
label: ->{ display_name current_active_admin_user },
url: ->{ url_for [active_admin_namespace.name, current_active_admin_user] rescue '#' },
if: :current_active_admin_user?
end
end

protected
Expand Down

0 comments on commit 1757daa

Please sign in to comment.