Use optional parameter to set column class

- Fixes the extremely long class name on the post versions view
- Can now use one value instead of having to set th and td
- Added missing column classes on all tables
This commit is contained in:
BrokenEagle
2020-01-13 20:57:16 +00:00
parent 34c3df78d9
commit 3ab2c4c3ea
24 changed files with 35 additions and 30 deletions

View File

@@ -2,8 +2,9 @@ class TableBuilder
class Column
attr_reader :attribute, :name, :block, :header_attributes, :body_attributes
def initialize(attribute = nil, th: {}, td: {}, width: nil, name: nil, &block)
def initialize(attribute = nil, column: nil, th: {}, td: {}, width: nil, name: nil, &block)
@attribute = attribute
@column = column
@header_attributes = { width: width, **th }
@body_attributes = td
@block = block
@@ -11,8 +12,12 @@ class TableBuilder
@name = name || attribute
@name = @name.to_s.titleize unless @name.is_a?(String)
if @name.present?
column_class = "#{@name.parameterize.dasherize}-column"
if @name.present? || @column.present?
if @column.present?
column_class = "#{@column}-column"
else
column_class = "#{@name.parameterize.dasherize}-column"
end
@header_attributes[:class] = "#{column_class} #{@header_attributes[:class]}".strip
@body_attributes[:class] = "#{column_class} #{@body_attributes[:class]}".strip
end