class GovukPublishingComponents::AppHelpers::TableHelper::TableBuilder

Attributes

tag[R]

Public Class Methods

new(tag) click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 25
def initialize(tag)
  @tag = tag
end

Public Instance Methods

body() { |self| ... } click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 37
def body
  tag.tbody class: "govuk-table__body" do
    yield(self)
  end
end
cell(str, opt = {}) click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 59
def cell(str, opt = {})
  classes = %w[govuk-table__cell]
  classes << "govuk-table__cell--#{opt[:format]}" if opt[:format]
  classes << "govuk-table__cell--empty" unless str
  str ||= "Not set"
  tag.td str, class: classes
end
head() { |self| ... } click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 29
def head
  tag.thead class: "govuk-table__head" do
    tag.tr class: "govuk-table__row" do
      yield(self)
    end
  end
end
header(str, opt = {}) click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 49
def header(str, opt = {})
  classes = %w[govuk-table__header]
  classes << "govuk-table__header--#{opt[:format]}" if opt[:format]
  classes << "govuk-table__header--active" if opt[:sort_direction]
  link_classes = %w[app-table__sort-link]
  link_classes << "app-table__sort-link--#{opt[:sort_direction]}" if opt[:sort_direction]
  str = link_to str, opt[:href], class: link_classes, data: opt[:data_attributes] if opt[:href]
  tag.th str, class: classes, scope: opt[:scope] || "col"
end
row() { |self| ... } click to toggle source
# File lib/govuk_publishing_components/app_helpers/table_helper.rb, line 43
def row
  tag.tr class: "govuk-table__row" do
    yield(self)
  end
end