Class: CCS::Components::GovUK::Footer::Navigation

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/ccs/components/govuk/footer/navigation.rb

Overview

GOV.UK Footer Navigation

The individual footer navigation item

Instance Method Summary collapse

Constructor Details

#initialize(title:, items:, context:, width: nil, columns: nil) ⇒ Navigation

Returns a new instance of Navigation.

Parameters:

  • title (String)

    the title for the navigation section

  • items (Array<Hash>)

    an array of links for the navigation section. See Link#initialize for details of the items in the array.

  • width (String) (defaults to: nil)

    (‘full’) width of each navigation section in the footer

  • columns (Integer) (defaults to: nil)

    (nil) number of columns to display the links

  • context (ActionView::Base)

    the view context



37
38
39
40
41
42
# File 'lib/ccs/components/govuk/footer/navigation.rb', line 37

def initialize(title:, items:, context:, width: nil, columns: nil)
  @title = title
  @navigation_links = items.map { |navigation_link| Link.new(li_class: 'govuk-footer__list-item', context: context, **navigation_link) }
  @width = width || 'full'
  @columns = columns
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Footer Navigation sections

Returns:

  • (ActiveSupport::SafeBuffer)


48
49
50
51
52
53
54
55
# File 'lib/ccs/components/govuk/footer/navigation.rb', line 48

def render
  tag.div(class: "govuk-footer__section govuk-grid-column-#{width}") do
    concat(tag.h2(title, class: 'govuk-footer__heading govuk-heading-m'))
    concat(tag.ul(class: "govuk-footer__list #{"govuk-footer__list--columns-#{columns}" if columns}".rstrip) do
      navigation_links.each { |navigation_link| concat(navigation_link.render) }
    end)
  end
end