Module: PureAdmin::MenuHelper
- Defined in:
- app/helpers/pure_admin/menu_helper.rb
Overview
Helper methods to assist in building the Pure Admin menu.
Instance Method Summary collapse
-
#current_menu_item?(url) ⇒ Boolean
Check if the menu item is currently active.
-
#current_parent?(url) ⇒ Boolean
Check if the menu item is currently active.
-
#menu(options = {}) { ... } ⇒ Object
Renders a pure menu wrapper to the view.
-
#menu_item(options = {}, &block) ⇒ Object
Renders a “menu item” to the view.
-
#menu_item_and_link(name = nil, url = nil, options = nil, &block) ⇒ Object
Renders a “menu item” and “menu link” to the view.
-
#menu_link(name = nil, url = nil, options = nil, &block) ⇒ Object
Renders a “menu link” to the view.
-
#sub_menu(options = {}) { ... } ⇒ Object
Renders a pure sub-menu to the view.
Instance Method Details
#current_menu_item?(url) ⇒ Boolean
Check if the menu item is currently active
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 88 def (url) return false unless url begin = URI.parse(url).try(:path) rescue = nil end return false unless # only match roots on exact match return request.original_fullpath == end |
#current_parent?(url) ⇒ Boolean
Check if the menu item is currently active. Is active if it is parent or current.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 106 def current_parent?(url) return false unless url begin = URI.parse(url).try(:path) rescue = nil end return false unless # match all other items to start of original_fullpath return request.original_fullpath =~ /^#{Regexp.escape()}(\/|$)/ end |
#menu(options = {}) { ... } ⇒ Object
Renders a pure menu wrapper to the view.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 11 def ( = {}, &block) = .delete(:menu_html) || {} [:class] = merge_html_classes('pure-menu', [:class]) list_html = .delete(:list_html) || {} list_html[:class] = merge_html_classes('pure-menu-list', list_html[:class]) content_tag(:nav, ) do content_tag(:ul, '', list_html, &block) end end |
#menu_item(options = {}, &block) ⇒ Object
Renders a “menu item” to the view.
51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 51 def ( = {}, &block) [:class] = merge_html_classes('pure-menu-item', [:class]) [:class] << 'current' if .delete(:current) condition = .key?(:if) ? .delete(:if) : true condition = !.delete(:unless) if .key?(:unless) content_tag(:li, capture(&block), ) if condition end |
#menu_item_and_link(name = nil, url = nil, options = nil, &block) ⇒ Object
Renders a “menu item” and “menu link” to the view.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 68 def (name = nil, url = nil, = nil, &block) , url, name = url, name, capture(&block) if block_given? ||= {} item_html = .delete(:item_html) || {} item_html[:class] = merge_html_classes('pure-menu-item', item_html[:class]) item_html[:if] = [:if] if .key?(:if) item_html[:unless] = [:unless] if .key?(:unless) item_html[:current] = true if (url) link_html = .delete(:link_html) || {} (item_html) do (name, url, link_html) end end |
#menu_link(name = nil, url = nil, options = nil, &block) ⇒ Object
Renders a “menu link” to the view.
37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 37 def (name = nil, url = nil, = nil, &block) , url, name = url, name, capture(&block) if block_given? ||= {} name = name.to_s.titleize unless block_given? || name.respond_to?(:titleize) [:class] = merge_html_classes('pure-menu-link', [:class]) url.present? ? link_to(name, url, ) : content_tag(:span, name, ) end |
#sub_menu(options = {}) { ... } ⇒ Object
Renders a pure sub-menu to the view.
27 28 29 30 |
# File 'app/helpers/pure_admin/menu_helper.rb', line 27 def ( = {}, &block) [:class] = merge_html_classes('pure-menu-list sub-menu', [:class]) content_tag(:ul, '', , &block) end |