Module: CCS::FrontendHelpers::GovUKFrontend::Table

Included in:
CCS::FrontendHelpers::GovUKFrontend
Defined in:
lib/ccs/frontend_helpers/govuk_frontend/table.rb

Overview

GOV.UK Table

This helper is used for generating the table component from the GDS - Components - Table

Instance Method Summary collapse

Instance Method Details

#govuk_table(head_cells_or_rows, rows = nil) ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Table component

Parameters:

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

    array of table rows and cells. See Body::HeadCell#initialize or Body::DataCell#initialize for details of the items in the array.

  • head_cells (NilClass, Array)

    array of table head cells. See Header::HeadCell#initialize for details of the items in the array.

  • caption (NilClass, Hash)

    options for a table caption

  • first_cell_is_header (Boolean)

    if set to true, first cell in table row will be a TH instead of a TD

  • options (Hash)

    options that will be used in customising the HTML

Returns:

  • (ActiveSupport::SafeBuffer)


22
23
24
25
26
27
28
29
30
31
# File 'lib/ccs/frontend_helpers/govuk_frontend/table.rb', line 22

def govuk_table(head_cells_or_rows, rows = nil, **)
  if rows.nil?
    rows = head_cells_or_rows
    head_cells = nil
  else
    head_cells = head_cells_or_rows
  end

  Components::GovUK::Table.new(context: self, rows: rows, head_cells: head_cells, **).render
end