Module: Workarea::Storefront::NavigationHelper
- Defined in:
- app/helpers/workarea/storefront/navigation_helper.rb
Instance Method Summary collapse
- #left_navigation ⇒ Object
- #link_selected?(taxon) ⇒ Boolean
- #link_to_menu(menu) ⇒ Object
- #mobile_nav_return_path ⇒ Object
- #navigation_menu_item_data_attribute(menu) ⇒ Object
- #navigation_menus ⇒ Object
- #storefront_path_for(taxon) ⇒ Object
- #storefront_url_for(taxon) ⇒ Object
-
#taxon_cache_key(taxon, section = nil, selected: nil) ⇒ Array
Generate a cache key for a taxon’s left navigation.
Instance Method Details
#left_navigation ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 33 def return '' unless @breadcrumbs.present? taxon = @breadcrumbs[-2] || @breadcrumbs.last return '' unless taxon.present? if taxon.has_children? selected_child_taxon = taxon.children.detect do |child| link_selected?(child) end render 'workarea/storefront/shared/left_navigation', taxon: taxon, selected_child_taxon: selected_child_taxon else '' end end |
#link_selected?(taxon) ⇒ Boolean
29 30 31 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 29 def link_selected?(taxon) !!@breadcrumbs.try(:selected?, taxon) end |
#link_to_menu(menu) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 51 def () styles = 'primary-nav__link' styles << ' primary-nav__link--selected' if link_selected?(.taxon) = { class: styles, data: { analytics: (.taxon).to_json } } if .taxon.placeholder? content_tag :span, .name, else link_to .name, storefront_path_for(.taxon), end end |
#mobile_nav_return_path ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 19 def mobile_nav_return_path uri = URI.parse( params[:return_to].presence || request.referer.presence || root_url ) uri.path end |
#navigation_menu_item_data_attribute(menu) ⇒ Object
12 13 14 15 16 17 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 12 def () return if .content.blank? return if ContentViewModel.new(.content).content_blocks.blank? { primary_nav_content: .id } end |
#navigation_menus ⇒ Object
4 5 6 7 8 9 10 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 4 def @navigation_menus ||= Navigation::Menu .all .includes(:content) .sort_by(&:position) .select(&:active?) end |
#storefront_path_for(taxon) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 68 def storefront_path_for(taxon) if taxon.url? taxon.url elsif taxon.root? respond_to?(:storefront) ? storefront.root_path : root_path elsif taxon.search_results? search_path(taxon.navigable.params) elsif taxon.navigable? send("#{taxon.resource_name}_path", taxon.navigable_slug) end end |
#storefront_url_for(taxon) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 80 def storefront_url_for(taxon) path = storefront_path_for(taxon) return if path.blank? protocol = Rails.application.config.force_ssl ? 'https' : 'http' "#{protocol}://#{Workarea.config.host}/#{path.sub(/^\//, '')}" end |
#taxon_cache_key(taxon, section = nil, selected: nil) ⇒ Array
Generate a cache key for a taxon’s left navigation. Uses the ‘:selected` taxon in the cache key if a given node is selected, otherwise just appends the `section` argument onto the `taxon`’s cache key.
expand.
99 100 101 102 103 104 |
# File 'app/helpers/workarea/storefront/navigation_helper.rb', line 99 def taxon_cache_key(taxon, section = nil, selected: nil) selected_cache_key = "selected:#{selected.cache_key}" if selected.present? fragment = section&.to_s [taxon.cache_key, selected_cache_key, fragment] end |