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

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/footer.rb,
lib/ccs/components/govuk/footer/link.rb,
lib/ccs/components/govuk/footer/meta.rb,
lib/ccs/components/govuk/footer/navigation.rb

Overview

GOV.UK Footer

This is used to generate the footer component from the GDS - Components - Footer

Defined Under Namespace

Classes: Link, Meta, Navigation

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the breadcrumbs

{ class: 'govuk-footer' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(navigation: nil, meta: nil, **options) ⇒ Footer

Returns a new instance of Footer.

Parameters:

  • navigation (Array<Hash>) (defaults to: nil)

    an array of sections for the footer navigation. See Navigation#initialize for details of the items in the array.

  • meta (Hash) (defaults to: nil)

    ptions for the meta section of the footer. See Meta#initialize for details of the options.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the footer HTML

  • :container_class (String)

    classes that can be added to the inner container

  • :content_licence (ActiveSupport::SafeBuffer, String)

    The content licence information, see footer_content_licence for default

  • :copyright (ActiveSupport::SafeBuffer, String)

    The copyright information, (default: ‘© Crown copyright’)

  • :attributes (Hash)

    additional attributes that will added as part of the HTML



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

def initialize(navigation: nil, meta: nil, **options)
  super(**options)

  @options[:copyright] ||= '© Crown copyright'

  @navigation = navigation&.map { |navigation_item| Navigation.new(context: @context, **navigation_item) }
  @meta = Meta.new(context: @context, **meta) if meta
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Footer component

Returns:

  • (ActiveSupport::SafeBuffer)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ccs/components/govuk/footer.rb', line 52

def render
  tag.footer(**options[:attributes]) do
    tag.div(class: "govuk-width-container #{options[:container_classes]}".rstrip) do
      if navigation.present?
        concat(tag.div(class: 'govuk-footer__navigation') do
          navigation.each { |navigation_item| concat(navigation_item.render) }
        end)
        concat(tag.hr(class: 'govuk-footer__section-break'))
      end
      concat(tag.div(class: 'govuk-footer__meta') do
        concat(tag.div(class: 'govuk-footer__meta-item govuk-footer__meta-item--grow') do
          concat(meta.render) if meta
          concat()
          concat(footer_content_licence)
        end)
        concat(footer_copyright)
      end)
    end
  end
end