Class: CCS::Components::GovUK::Pagination::Increment

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/pagination/increment.rb,
lib/ccs/components/govuk/pagination/increment/next.rb,
lib/ccs/components/govuk/pagination/increment/previous.rb

Overview

GOV.UK Pagination Increment

This generates the HTML for a pagination increment, that is Previous and Next

Direct Known Subclasses

Next, Previous

Defined Under Namespace

Classes: Next, Previous

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(type:, default_text:, block_is_level:, text: nil, label_text: nil, **options) ⇒ Increment

Returns a new instance of Increment.

Parameters:

  • type (Symbol)

    the type of increment, either :prev or :next

  • default_text (String)

    the default text for the pagination increment

  • text (String) (defaults to: nil)

    the text for the pagination increment

  • block_is_level (Boolean)

    when there are no items, this will be true and will add extra classes to the link to make the next and previous pagination links level

  • label_text (String) (defaults to: nil)

    additional text for the link when the pagination block is level

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :href (String)

    the URL for the link

  • :form (ActionView::Helpers::FormBuilder)

    optional form builder used to create the button

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ccs/components/govuk/pagination/increment.rb', line 43

def initialize(type:, default_text:, block_is_level:, text: nil, label_text: nil, **options)
  super(**options)

  @options[:attributes][:class] = "govuk-link govuk-pagination__link #{'pagination--button_as_link' if @options[:form]}".rstrip
  @options[:attributes][:rel] = type.to_s

  @type = type
  @default_text = default_text
  @text = text || default_text
  @block_is_level = block_is_level
  @label_text = label_text
end

Instance Method Details

#render { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the pagination increment link/button

Yields:

  • the HTML for the increment button/link

Returns:

  • (ActiveSupport::SafeBuffer)


64
65
66
67
68
69
70
# File 'lib/ccs/components/govuk/pagination/increment.rb', line 64

def render(&)
  if options[:form]
    options[:form].button(**options[:attributes], &)
  else
    link_to(options[:href], **options[:attributes], &)
  end
end