class GovukPublishingComponents::Presenters::RelatedNavigationHelper
@private Only used by the related_navigation
component
Constants
- DEFINED_SECTIONS
- MAX_SECTION_LENGTH
- WORLD_LOCATION_SPECIAL_CASES
Public Class Methods
new(options = {})
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 19 def initialize(options = {}) @content_item = options.fetch(:content_item) { raise ArgumentError, "missing argument: content_item" } @context = options.fetch(:context, nil) end
Public Instance Methods
calculate_section_link_limit(links)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 88 def calculate_section_link_limit(links) links.length == MAX_SECTION_LENGTH + 1 ? MAX_SECTION_LENGTH + 1 : MAX_SECTION_LENGTH end
construct_section_heading(section_title)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 56 def construct_section_heading(section_title) unless section_title == "related_items" I18n.t( "components.related_#{@context}_navigation." + section_title, default: [ I18n.t("components.related_navigation.#{section_title}"), section_title.tr("_", " "), ], ) end end
remaining_link_count(links)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 92 def remaining_link_count(links) links.length - MAX_SECTION_LENGTH end
section_css_class(css_class, section_title, link: {}, link_is_inline: false)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 68 def section_css_class(css_class, section_title, link: {}, link_is_inline: false) css_classes = [css_class] css_classes << "#{css_class}--#{@context}" unless @context.nil? css_classes << "#{css_class}--inline" if link_is_inline unless DEFINED_SECTIONS.include?(section_title) || link.fetch(:finder, false) css_classes << " #{css_class}--other" end css_classes.join(" ") end
section_data_track_count(section_title)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 80 def section_data_track_count(section_title) String(@context || "sidebar") + String(section_title).camelcase end
section_heading_level()
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 84 def section_heading_level @context == :footer ? "h2" : "h3" end
Private Instance Methods
content_item_details_for(key)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 182 def content_item_details_for(key) Array(@content_item.dig("details", key)) .map { |link| { path: link["url"], text: link["title"], rel: "external" } } end
content_item_links_for(key, only: nil)
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 187 def content_item_links_for(key, only: nil) links = Array(@content_item.dig("links", key)) if key == "taxons" links = links.find_all { |link| link["phase"] == "live" } end if only.present? links = links.find_all { |link| link["document_type"] == only } end links.map do |link| { path: link["base_path"], text: link["title"], locale: link["locale"], } end end
detailed_guide?()
click to toggle source
# File lib/govuk_publishing_components/presenters/related_navigation_helper.rb, line 178 def detailed_guide? @content_item["document_type"] == "detailed_guide" end