Class: GovukPublishingComponents::AppHelpers::TableHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/app_helpers/table_helper.rb

Defined Under Namespace

Classes: TableBuilder

Class Method Summary collapse

Class Method Details

.helper(context, caption = nil, opt = {}) ⇒ Object

This is part of the Public API of this gem Any non-backwards compatible changes to the signature will require a major version change



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 6

def self.helper(context, caption = nil, opt = {})
  builder = TableBuilder.new(context.tag)

  classes = %w[gem-c-table govuk-table]
  classes << "govuk-table--sortable" if opt[:sortable]

  caption_classes = %w[govuk-table__caption]
  caption_classes << opt[:caption_classes] if opt[:caption_classes]

  context.tag.table class: classes, id: opt[:table_id] do
    context.concat context.tag.caption caption, class: caption_classes
    yield(builder)
  end
end