Module: Collavre::NavigationHelper
- Defined in:
- app/helpers/collavre/navigation_helper.rb
Instance Method Summary collapse
-
#navigation_item_visible?(item, desktop: true) ⇒ Boolean
Check if a navigation item should be visible.
-
#navigation_items_for(section, desktop: true) ⇒ Object
Get visible navigation items for a section.
-
#render_navigation_item(item, mobile: false) ⇒ Object
Render a single navigation item.
- #render_navigation_item_with_children(item, mobile: false) ⇒ Object
- #resolve_nav_value(value) ⇒ Object
Instance Method Details
#navigation_item_visible?(item, desktop: true) ⇒ Boolean
Check if a navigation item should be visible
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/collavre/navigation_helper.rb', line 13 def (item, desktop: true) return false if desktop && !item[:desktop] return false if !desktop && !item[:mobile] return false if item[:requires_auth] && !authenticated? return false if item[:requires_user] && Current.user.nil? if item[:visible].is_a?(Proc) return false unless resolve_nav_value(item[:visible]) end true end |
#navigation_items_for(section, desktop: true) ⇒ Object
Get visible navigation items for a section
6 7 8 9 10 |
# File 'app/helpers/collavre/navigation_helper.rb', line 6 def (section, desktop: true) Navigation::Registry.instance .items_for_section(section) .select { |item| (item, desktop: desktop) } end |
#render_navigation_item(item, mobile: false) ⇒ Object
Render a single navigation item
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/collavre/navigation_helper.rb', line 27 def (item, mobile: false) return unless (item, desktop: !mobile) case item[:type] when :button (item) when :link render_nav_link(item) when :component render_nav_component(item) when :partial render_nav_partial(item) when :divider render_nav_divider(item) when :raw render_nav_raw(item) when :popup render_nav_dropdown(item, mobile: mobile) else raise ArgumentError, "Unknown navigation item type: #{item[:type]}" end end |
#render_navigation_item_with_children(item, mobile: false) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/collavre/navigation_helper.rb', line 50 def (item, mobile: false) return unless (item, desktop: !mobile) if item[:children].present? render_nav_dropdown(item, mobile: mobile) else (item, mobile: mobile) end end |
#resolve_nav_value(value) ⇒ Object
60 61 62 |
# File 'app/helpers/collavre/navigation_helper.rb', line 60 def resolve_nav_value(value) value.is_a?(Proc) ? instance_exec(&value) : value end |