Class: GovukPublishingComponents::AppHelpers::TableHelper::TableBuilder
- Inherits:
-
Object
- Object
- GovukPublishingComponents::AppHelpers::TableHelper::TableBuilder
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/govuk_publishing_components/app_helpers/table_helper.rb
Instance Attribute Summary collapse
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #body ⇒ Object
- #cell(str, opt = {}) ⇒ Object
- #head ⇒ Object
- #header(str, opt = {}) ⇒ Object
-
#initialize(tag) ⇒ TableBuilder
constructor
A new instance of TableBuilder.
- #row ⇒ Object
Constructor Details
#initialize(tag) ⇒ TableBuilder
Returns a new instance of TableBuilder.
28 29 30 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 28 def initialize(tag) @tag = tag end |
Instance Attribute Details
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
26 27 28 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 26 def tag @tag end |
Instance Method Details
#body ⇒ Object
40 41 42 43 44 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 40 def body tag.tbody class: "govuk-table__body" do yield(self) end end |
#cell(str, opt = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 62 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 ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 32 def head tag.thead class: "govuk-table__head" do tag.tr class: "govuk-table__row" do yield(self) end end end |
#header(str, opt = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 52 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 ⇒ Object
46 47 48 49 50 |
# File 'lib/govuk_publishing_components/app_helpers/table_helper.rb', line 46 def row tag.tr class: "govuk-table__row js-govuk-table__row" do yield(self) end end |