Sha256: 53e815ff2a72e0e095bd9790cd638a7514c1361c9c3ba87ad8010d702e74a54d

Contents?: true

Size: 1.73 KB

Versions: 20

Compression:

Stored size: 1.73 KB

Contents

require_relative '../../base'

module CCS
  module Components
    module GovUK
      class Breadcrumbs < Base
        # = GOV.UK Breadcrumbs Link
        #
        # The individual list item for the breadcrumbs
        #
        # @!attribute [r] text
        #   @return [String] Text for the breadcrumb link
        # @!attribute [r] href
        #   @return [String] The href for the breadcrumb link

        class Link < Base
          private

          attr_reader :text, :href

          public

          # @param text [String] the text for the breadcrumb link
          # @param href [String] the href for the breadcrumb link.
          #                      If blank it is assumed that this item relates to current page
          # @param options [Hash] options that will be used in customising the HTML
          #
          # @option options [Hash] :attributes any additional attributes that will added as part of the HTML.
          #                                    If the link is blank then it defaults to +{ aria: { current: 'page' } }+

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

            @text = text
            @href = href
          end

          # Generates the HTML for the GOV.UK Breadcrumbs link
          #
          # @return [ActiveSupport::SafeBuffer]

          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
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/breadcrumbs/link.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/breadcrumbs/link.rb