Class: CCS::Components::GovUK::Table::Body::DataCell

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/table/body/data_cell.rb

Overview

GOV.UK Table Body data cell

The individual table body data cell

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the table body data cell

{ class: 'govuk-table__cell' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, **options) ⇒ DataCell

Returns a new instance of DataCell.

Parameters:

  • text (String)

    the text of the cell

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the cell

  • :format (String)

    specify format of a cell

  • :attributes (Hash) — default: {}

    any additional attributes that will be added as part of the cell



29
30
31
32
33
34
35
# File 'lib/ccs/components/govuk/table/body/data_cell.rb', line 29

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

  @options[:attributes][:class] += " govuk-table__cell--#{@options[:format]}" if @options[:format]

  @text = text
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Table Body data cell

Returns:

  • (ActiveSupport::SafeBuffer)


41
42
43
# File 'lib/ccs/components/govuk/table/body/data_cell.rb', line 41

def render
  tag.td(text, **options[:attributes])
end