Class: CCS::Components::GovUK::SummaryList::Row

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/summary_list/row.rb,
lib/ccs/components/govuk/summary_list/row/key.rb,
lib/ccs/components/govuk/summary_list/row/value.rb,
lib/ccs/components/govuk/summary_list/row/actions.rb

Overview

GOV.UK Summary list row

Generates the HTML for a summary list row

Defined Under Namespace

Classes: Actions, Key, Value

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the summary list row

{ class: 'govuk-summary-list__row' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(any_row_has_actions:, key:, value:, actions: nil, card_title: nil, **options) ⇒ Row

Returns a new instance of Row.

Parameters:

  • any_row_has_actions (Boolean)

    flag to indicate if any rows have actions

  • key (Hash)

    attributes for the key, see Key#initialize for more details.

  • value (Hash)

    attributes for the value, see Value#initialize for more details.

  • actions (Hash) (defaults to: nil)

    attributes for the actions, see Actions#initialize for more details.

  • card_title (String) (defaults to: nil)

    the text for the card title

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the summary list row HTML



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ccs/components/govuk/summary_list/row.rb', line 39

def initialize(any_row_has_actions:, key:, value:, actions: nil, card_title: nil, **options)
  super(**options)

  actions_present = actions && actions[:items].present?

  @options[:attributes][:class] << ' govuk-summary-list__row--no-actions' if any_row_has_actions && !actions_present

  @key = Key.new(context: @context, **key)
  @value = Value.new(context: @context, **value)
  @actions = Actions.new(context: @context, card_title: card_title, **actions) if actions_present
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Summary list row

Returns:

  • (ActiveSupport::SafeBuffer)


57
58
59
60
61
62
63
# File 'lib/ccs/components/govuk/summary_list/row.rb', line 57

def render
  tag.div(class: options[:attributes][:class]) do
    concat(key.render)
    concat(value.render)
    concat(actions.render) if actions
  end
end