app/components/katalyst/table_component.rb in katalyst-tables-2.1.3 vs app/components/katalyst/table_component.rb in katalyst-tables-2.2.0
- old
+ new
@@ -52,51 +52,39 @@
@caption_options = (caption if caption.is_a?(Hash)) || {}
super(**html_attributes)
end
- def call
- tag.table(**html_attributes) do
- concat(caption)
- concat(thead)
- concat(tbody)
- end
+ def caption?
+ @caption.present?
end
def caption
- caption_component&.new(self)&.render_in(view_context) if @caption
+ caption_component&.new(self)
end
- def thead
- return "".html_safe unless @header
-
- tag.thead do
- concat(render_header)
- end
+ def header?
+ @header.present?
end
- def tbody
- tag.tbody do
- collection.each do |record|
- concat(render_row(record))
- end
- end
+ def header_row
+ header_row_component.new(self, **@header_options)
end
- def render_header
- # extract the column's block from the slot and pass it to the cell for rendering
- header_row_component.new(self, **@header_options).render_in(view_context, &row_proc)
+ def body_row(record)
+ body_row_component.new(self, record)
end
- def render_row(record)
- body_row_component.new(self, record).render_in(view_context) do |row|
- row_proc.call(row, record)
- end
- end
-
def sorting
return @sorting if @sorting.present?
collection.sorting if collection.respond_to?(:sorting)
end
+
+ def inspect
+ "#<#{self.class.name} collection: #{collection.inspect}>"
+ end
+
+ define_html_attribute_methods(:thead_attributes)
+ define_html_attribute_methods(:tbody_attributes)
end
end