Module: CoreMenuHelper
- Defined in:
- app/helpers/core_menu_helper.rb
Overview
Helpful methods for menu bar on the side
Instance Method Summary collapse
- #expandable_menu_item(name, classes: [], icon_name: '', badge_count: 0, &block) ⇒ Object
- #main_menu(&block) ⇒ Object
- #menu_count_badge(name, badge_count) ⇒ Object abstract
- #menu_css(names, read_only: false, enabled: true, visible: true) ⇒ Object abstract
-
#menu_item(name, action_path, classes: [], icon_name: '', badge_count: 0) ⇒ Object
abstract
-
icon_name - name of the icon to add to the link * classes - css styles to apply to the navigational link * new_count_badge - Content for badge.
-
- #menu_link(name, action_path, classes: [], badge_count: 0, icon_name: '') ⇒ Object
- #menu_name(name) ⇒ Object
Instance Method Details
#expandable_menu_item(name, classes: [], icon_name: '', badge_count: 0, &block) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/core_menu_helper.rb', line 56 def (name, classes: [], icon_name: '', badge_count: 0, &block) classes << 'menu-item' classes << 'open' if classes.include?('active') content_tag(:li, class: classes.join(' ')) do classes << 'menu-toggle' concat((name, '#', classes: ['menu-toggle'], badge_count: badge_count, icon_name: icon_name)) concat(content_tag(:ul, class: 'menu-sub') { yield block }) end end |
#main_menu(&block) ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/helpers/core_menu_helper.rb', line 66 def (&block) content_tag(:div, id: 'main-menu') do concat(content_tag(:ul, class: 'menu-inner py-1') do yield block end) end end |
#menu_count_badge(name, badge_count) ⇒ Object
This method is abstract.
Add a badge to the current element
75 76 77 78 79 |
# File 'app/helpers/core_menu_helper.rb', line 75 def (name, badge_count) content_tag(:span, class: 'badge badge-center bg-white text-primary rounded-pill ms-1', title: "#{badge_count} New #{name.to_s.pluralize}") { badge_count.to_s } end |
#menu_css(names, read_only: false, enabled: true, visible: true) ⇒ Object
This method is abstract.
Determines which css attributes should be assigned to the current menu, options are
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/core_menu_helper.rb', line 14 def (names, read_only: false, enabled: true, visible: true) states = [] states << 'read-only' if read_only states << 'locked' unless enabled states << 'd-none' unless visible case names when String states << 'active' if names.eql?(controller.controller_name) when Array states << 'active' if names.include?(controller.controller_name) else states << 'active' if names.to_s.eql?(controller.controller_name) end states end |
#menu_item(name, action_path, classes: [], icon_name: '', badge_count: 0) ⇒ Object
This method is abstract.
Produce a new navigational link The name and action path are required, additional options are
-
icon_name - name of the icon to add to the link
-
classes - css styles to apply to the navigational link
-
new_count_badge - Content for badge
49 50 51 52 53 54 |
# File 'app/helpers/core_menu_helper.rb', line 49 def (name, action_path, classes: [], icon_name: '', badge_count: 0) classes << 'menu-item' content_tag(:li, class: classes.join(' ')) do (name, action_path, badge_count: badge_count, icon_name: icon_name) end end |
#menu_link(name, action_path, classes: [], badge_count: 0, icon_name: '') ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'app/helpers/core_menu_helper.rb', line 34 def (name, action_path, classes: [], badge_count: 0, icon_name: '') classes << 'menu-link' content_tag(:a, href: action_path, class: classes.join(' ')) do concat((icon_name)) if icon_name.present? concat((name)) concat((name, badge_count)) if badge_count.positive? end end |
#menu_name(name) ⇒ Object
30 31 32 |
# File 'app/helpers/core_menu_helper.rb', line 30 def (name) content_tag(:div, data: { i18n: name }) { name } end |