From 2cf0e7dcb5ec26e3d2c1e06178b6d1487ce1205d Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 9 Jan 2020 17:29:10 -0600 Subject: [PATCH] table builder: add default html ids and css classes. * Add default IDs for tags (ex:
). * Add default CSS classes for
and tags (ex: ). --- app/logical/table_builder.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/logical/table_builder.rb b/app/logical/table_builder.rb index e89faca2d..fac059117 100644 --- a/app/logical/table_builder.rb +++ b/app/logical/table_builder.rb @@ -10,6 +10,12 @@ class TableBuilder @name = name || attribute @name = @name.to_s.titleize unless @name.kind_of?(String) + + if @name.present? + column_class = "#{@name.parameterize.dasherize}-column" + @header_attributes[:class] = "#{column_class} #{@header_attributes[:class]}".strip + @body_attributes[:class] = "#{column_class} #{@body_attributes[:class]}".strip + end end def value(item, i, j) @@ -30,6 +36,11 @@ class TableBuilder @items = items @columns = [] @table_attributes = { class: "striped", **table_attributes } + + if items.respond_to?(:model_name) + @table_attributes[:id] ||= "#{items.model_name.plural.dasherize}-table" + end + yield self if block_given? end