table builder: add default html ids and css classes.
* Add default IDs for <table> tags (ex: <table id="artists-table">). * Add default CSS classes for <th> and <td> tags (ex: <td class="name-column">).
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user