Module: Postnhost::NavigationHelper

Defined in:
app/helpers/postnhost/navigation_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_navigation_locale_keyObject



32
33
34
# File 'app/helpers/postnhost/navigation_helper.rb', line 32

def default_navigation_locale_key
  @default_navigation_locale_key ||= @default_language&.html_lang || I18n.default_locale.to_s
end


15
16
17
18
19
20
21
22
23
# File 'app/helpers/postnhost/navigation_helper.rb', line 15

def navigation_href(item)
  return if item.blank? || item.kind != "link"

  @navigation_href_cache ||= {}
  cache_key = navigation_item_cache_key(item)
  return @navigation_href_cache[cache_key] if @navigation_href_cache.key?(cache_key)

  @navigation_href_cache[cache_key] = resolve_navigation_href(item)
end


3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/postnhost/navigation_helper.rb', line 3

def navigation_label(item)
  return if item.blank?

  @navigation_label_cache ||= {}
  cache_key = navigation_item_cache_key(item)
  return @navigation_label_cache[cache_key] if @navigation_label_cache.key?(cache_key)

  @navigation_label_cache[cache_key] =
    item.label_for(locale_key: @current_language&.html_lang, default_locale_key: default_navigation_locale_key).presence ||
    navigation_target_label(item)
end


25
26
27
28
29
30
# File 'app/helpers/postnhost/navigation_helper.rb', line 25

def navigation_link_options(item)
  return {} unless item.target_kind == "external"

  rel_value = item.nofollow ? "noopener noreferrer nofollow" : "noopener noreferrer"
  { target: "_blank", rel: rel_value }
end