Sha256: ad5248154f50dbf75d49b4fd9c7a4c9e4f5a10776368f7062bcf0b919116d229
Contents?: true
Size: 1.68 KB
Versions: 6
Compression:
Stored size: 1.68 KB
Contents
module Component class CollectionTable < Base SIZE_MAP = { default: nil, small: :sm } def initialize(*args) super @columns = {} @collection = @options.delete(:collection) @resource_class = @collection.first.class end def column(name, options = {}, &block) options.reverse_merge!(block: block) if block_given? @columns[name] = options end def timestamps(options = {}) column(:created_at, options) column(:updated_at, options) end def association(name, options = {}, &block) options.reverse_merge!(block: block) if block_given? @columns[name] = options end private def table self end def view_locals { columns: @columns, collection: @collection, resource_class: @resource_class, table_css_classes: table_css_classes } end def striped? !!@options[:striped] end def responsive? !!@options[:responsive] end def inverse? !!@options[:inverse] end def bordered? !!@options[:bordered] end def hover? !!@options[:hover] end def size SIZE_MAP[@options[:size] || :default] end def table_css_classes classes = ['table', 'collection-table', @resource_class.name.underscore.pluralize] classes << 'table-bordered' if bordered? classes << 'table-hover' if hover? classes << 'table-inverse' if inverse? classes << 'table-striped' if striped? classes << 'table-responsive' if responsive? classes << "table-#{size}" if size.present? classes end end end
Version data entries
6 entries across 6 versions & 1 rubygems