Class: GovukPublishingComponents::Presenters::PublicLayoutHelper

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

Constant Summary collapse

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



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

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.



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

def cookie_banner_data
  @cookie_banner_data
end

Returns the value of attribute footer_meta.



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

def footer_meta
  @footer_meta
end

Returns the value of attribute footer_navigation.



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

def footer_navigation
  @footer_navigation
end

Instance Method Details



83
84
85
86
87
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 83

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


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

def footer_navigation_columns
  FOOTER_NAVIGATION_COLUMNS
end


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

def footer_track_actions
  FOOTER_TRACK_ACTIONS
end

#generate_data_attribute(link, track_action) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/govuk_publishing_components/presenters/public_layout_helper.rb', line 72

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


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

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