Module: CoreNavBarHelper
- Defined in:
- app/helpers/core_nav_bar_helper.rb
Overview
Helpful methods for navigation bar on the side
Instance Method Summary collapse
-
#nav_bar_css(names, read_only: false, enabled: true, visible: true) ⇒ Object
abstract
Array - a collection of css parameters based on current controllers.
-
#nav_css(names, read_only = false, feature_enabled = true, feature_visible = true) ⇒ Object
Determines which css attributes should be assigned to the current menu, options are <ul> <li>read-only - the menu is greyed out and disabled</li> <li>locked - a lock icon appears</li> <li>active - if the current controller matches either the name or names</li> </ul>.
- #nav_item_group(name, classes: [], badge_count: 0, &block) ⇒ Object
- #nav_item_link(name, action_path, badge_count: 0, classes: []) ⇒ Object
- #nav_link(name, action_path, badge_count: 0, classes: []) ⇒ Object
- #nav_localized(type, name) ⇒ Object
- #nav_menu_title(name) ⇒ Object
- #new_count_badge(name, options = {}) ⇒ Object abstract
Instance Method Details
#nav_bar_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
Returns Array - a collection of css parameters based on current controllers.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/core_nav_bar_helper.rb', line 38 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 |
#nav_css(names, read_only = false, feature_enabled = true, feature_visible = true) ⇒ Object
Determines which css attributes should be assigned to the current menu, options are <ul>
<li>read-only - the menu is greyed out and disabled</li>
<li>locked - a lock icon appears</li>
<li>active - if the current controller matches either the name or names</li>
</ul>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/core_nav_bar_helper.rb', line 16 def nav_css(names, read_only = false, feature_enabled = true, feature_visible = true) states = [] states << 'read-only' if read_only states << 'locked' unless feature_enabled states << 'hidden' unless feature_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.join(' ') end |
#nav_item_group(name, classes: [], badge_count: 0, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/core_nav_bar_helper.rb', line 82 def nav_item_group(name, classes: [], badge_count: 0, &block) lic = [classes, 'nav-item'].flatten.compact.join(' ') ac = [classes, 'nav-link'].flatten.compact.join(' ') open_close = 'false' nav_css = %w[nav nav-vertical collapse] if classes.include?('active') open_close = 'true' nav_css << 'show' end content_tag(:div, class: lic) do concat(content_tag(:a, class: ac, data: { bs_toggle: :collapse }, role: :button, href: "##{name}", aria: { expanded: open_close, controls: :nav_group_settings }) do concat(content_tag(:span, class: 'nav-link-icon d-md-none d-lg-inline-block') { svg_icon(name) }) concat(content_tag(:span, class: 'nav-link-title') { (name) }) concat(tag(:span, class: 'nav-link-toggle')) end) concat(content_tag(:div, class: nav_css.join(' '), id: name.to_s, &block)) end end |
#nav_item_link(name, action_path, badge_count: 0, classes: []) ⇒ Object
75 76 77 78 79 80 |
# File 'app/helpers/core_nav_bar_helper.rb', line 75 def nav_item_link(name, action_path, badge_count: 0, classes: []) lic = [classes, 'nav-item',].compact.join(' ') content_tag(:div, class: lic) do concat(nav_link(name, action_path, badge_count: badge_count)) end end |
#nav_link(name, action_path, badge_count: 0, classes: []) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/helpers/core_nav_bar_helper.rb', line 66 def nav_link(name, action_path, badge_count: 0, classes: []) ac = [classes, 'truncate', 'nav-link'].compact.join(' ') content_tag(:a, href: action_path, class: ac) do concat(content_tag(:span, class: 'nav-link-icon d-md-none d-lg-inline-block') { svg_icon(name) }) concat(content_tag(:span, class: 'nav-link-title') { (name) }) concat(new_count_badge(name, badge_count: badge_count)) end end |
#nav_localized(type, name) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/core_nav_bar_helper.rb', line 105 def nav_localized(type, name) if I18n.exists?("nav.#{type}.#{name}") I18n.t("nav.#{type}.#{name}") else name.to_s.titleize end rescue StandardError name end |
#nav_menu_title(name) ⇒ Object
101 102 103 |
# File 'app/helpers/core_nav_bar_helper.rb', line 101 def (name) nav_localized(:titles, name) end |
#new_count_badge(name, options = {}) ⇒ Object
This method is abstract.
Add a badge to the current element
57 58 59 60 61 62 63 64 |
# File 'app/helpers/core_nav_bar_helper.rb', line 57 def new_count_badge(name, = {}) return if .blank? badge_count = [:new_badge_count] return if badge_count.blank? || badge_count <= 0 content_tag(:span, class: 'badge', title: "#{badge_count} New #{name.pluralize}") { badge_count.to_s } end |