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

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
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
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