Class: CCS::Components::GovUK::Breadcrumbs::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/breadcrumbs/link.rb

Overview

GOV.UK Breadcrumbs Link

The individual list item for the breadcrumbs

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(text:, href: nil, **options) ⇒ Link

Returns a new instance of Link.

Parameters:

  • text (String)

    the text for the breadcrumb link

  • href (String) (defaults to: nil)

    the href for the breadcrumb link. If blank it is assumed that this item relates to current page

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML. If the link is blank then it defaults to { aria: { current: ‘page’ } }



31
32
33
34
35
36
# File 'lib/ccs/components/govuk/breadcrumbs/link.rb', line 31

def initialize(text:, href: nil, **options)
  super(**options)

  @text = text
  @href = href
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Breadcrumbs link

Returns:

  • (ActiveSupport::SafeBuffer)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ccs/components/govuk/breadcrumbs/link.rb', line 42

def render
  if href.present?
    options[:attributes][:class] = 'govuk-breadcrumbs__link'

    tag.li(class: 'govuk-breadcrumbs__list-item') do
      link_to(text, href, **options[:attributes])
    end
  else
    tag.li(text, class: 'govuk-breadcrumbs__list-item', aria: { current: 'page' })
  end
end