Class: GovukPublishingComponents::Presenters::RelatedNavigationHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::RelatedNavigationHelper
- Defined in:
- lib/govuk_publishing_components/presenters/related_navigation_helper.rb
Overview
Only used by the related_navigation component
Constant Summary collapse
- MAX_SECTION_LENGTH =
5
- DEFINED_SECTIONS =
%w[ related_guides topics collections topical_events world_locations statistical_data_sets ].freeze
- WORLD_LOCATION_SPECIAL_CASES =
{ "UK Mission to the European Union" => "uk-mission-to-the-eu", }.freeze
Instance Method Summary collapse
- #calculate_section_link_limit(links) ⇒ Object
- #construct_section_heading(section_title) ⇒ Object
-
#initialize(options = {}) ⇒ RelatedNavigationHelper
constructor
A new instance of RelatedNavigationHelper.
- #related_navigation ⇒ Object
- #related_navigation? ⇒ Boolean
- #remaining_link_count(links) ⇒ Object
- #section_css_class(css_class, section_title, link: {}, link_is_inline: false) ⇒ Object
- #section_data_track_count(section_title) ⇒ Object
- #section_heading_level ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RelatedNavigationHelper
Returns a new instance of RelatedNavigationHelper.
19 20 21 22 |
# File 'lib/govuk_publishing_components/presenters/related_navigation_helper.rb', line 19 def initialize( = {}) @content_item = .fetch(:content_item) { raise ArgumentError, "missing argument: content_item" } @context = .fetch(:context, nil) end |
Instance Method Details
#calculate_section_link_limit(links) ⇒ Object
88 89 90 |
# 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) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# 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 |
#related_navigation ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/govuk_publishing_components/presenters/related_navigation_helper.rb', line 24 def case @context.try(:to_sym) when :sidebar { "related_items" => , "related_guides" => , "collections" => , } when :footer { "topics" => , "topical_events" => , "world_locations" => , "statistical_data_sets" => , "related_external_links" => , "related_contacts" => , } else { "related_items" => , "related_guides" => , "collections" => , "topics" => , "topical_events" => , "world_locations" => , "statistical_data_sets" => , "related_external_links" => , "related_contacts" => , } end end |
#related_navigation? ⇒ Boolean
96 97 98 |
# File 'lib/govuk_publishing_components/presenters/related_navigation_helper.rb', line 96 def .flat_map(&:last).any? end |
#remaining_link_count(links) ⇒ Object
92 93 94 |
# 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) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# 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) ⇒ Object
80 81 82 |
# 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 ⇒ Object
84 85 86 |
# File 'lib/govuk_publishing_components/presenters/related_navigation_helper.rb', line 84 def section_heading_level @context == :footer ? "h2" : "h3" end |