Class: GovukPublishingComponents::Presenters::PublicLayoutHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/public_layout_helper.rb

Constant Summary collapse

BLUE_BAR_BACKGROUND_COLOURS =
%w[browse].freeze
[2, 1].freeze
%w[topicsLink governmentactivityLink].freeze
{
  items: [
    {
      href: "/help",
      text: "Help",
    },
    {
      href: "/help/privacy-notice",
      text: "Privacy",
    },
    {
      href: "/help/cookies",
      text: "Cookies",
    },
    {
      href: "/help/accessibility-statement",
      text: "Accessibility statement",
    },
    {
      href: "/contact",
      text: "Contact",
    },
    {
      href: "/help/terms-conditions",
      text: "Terms and conditions",
    },
    {
      href: "/cymraeg",
      text: "Rhestr o Wasanaethau Cymraeg",
      attributes: {
        lang: "cy",
      },
    },
    {
      href: "/government/organisations/government-digital-service",
      text: "Government Digital Service",
    },
  ],
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_assigns) ⇒ PublicLayoutHelper

Returns a new instance of PublicLayoutHelper.



49
50
51
52
53
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 49

def initialize(local_assigns)
  @footer_navigation = local_assigns[:footer_navigation] || navigation_link_generation_from_locale(I18n.t("components.layout_footer.navigation_links"))
  @footer_meta = local_assigns[:footer_meta] || { items: add_data_attributes_to_links(FOOTER_META[:items], "supportLink") }
  @cookie_banner_data = local_assigns[:cookie_banner_data] || {}
end

Instance Attribute Details

Returns the value of attribute cookie_banner_data.



47
48
49
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 47

def cookie_banner_data
  @cookie_banner_data
end

Returns the value of attribute footer_meta.



47
48
49
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 47

def footer_meta
  @footer_meta
end

Returns the value of attribute footer_navigation.



47
48
49
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 47

def footer_navigation
  @footer_navigation
end

Instance Method Details



88
89
90
91
92
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 88

def add_data_attributes_to_links(items, track_action)
  items.map do |item|
    item.deep_merge({ attributes: { data: generate_data_attribute(item, track_action) } })
  end
end

#blue_bar_background_coloursObject



73
74
75
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 73

def blue_bar_background_colours
  BLUE_BAR_BACKGROUND_COLOURS
end


65
66
67
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 65

def footer_navigation_columns
  FOOTER_NAVIGATION_COLUMNS
end


69
70
71
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 69

def footer_track_actions
  FOOTER_TRACK_ACTIONS
end

#generate_data_attribute(link, track_action) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 77

def generate_data_attribute(link, track_action)
  {
    track_category: "footerClicked",
    track_action:,
    track_label: link[:href],
    track_options: {
      dimension29: link[:text],
    },
  }
end


55
56
57
58
59
60
61
62
63
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 55

def navigation_link_generation_from_locale(links)
  links.each_with_index.map do |menu, i|
    {
      title: menu[:title],
      columns: footer_navigation_columns[i],
      items: add_data_attributes_to_links(menu[:menu_contents], footer_track_actions[i]),
    }
  end
end