Class: Trestle::Table::Automatic

Inherits:
Trestle::Table show all
Defined in:
lib/trestle/table/automatic.rb

Instance Attribute Summary

Attributes inherited from Trestle::Table

#options, #row

Instance Method Summary collapse

Methods inherited from Trestle::Table

#admin, #autolink?, #header?, #renderer, #sortable?, #with_options

Constructor Details

#initialize(admin) ⇒ Automatic

Returns a new instance of Automatic.


4
5
6
# File 'lib/trestle/table/automatic.rb', line 4

def initialize(admin)
  super(sortable: true, admin: admin)
end

Instance Method Details

#actions_columnObject


23
24
25
# File 'lib/trestle/table/automatic.rb', line 23

def actions_column
  ActionsColumn.new
end

#columnsObject


8
9
10
# File 'lib/trestle/table/automatic.rb', line 8

def columns
  content_columns + [actions_column]
end

#content_columnsObject


12
13
14
15
16
17
18
19
20
21
# File 'lib/trestle/table/automatic.rb', line 12

def content_columns
  admin.default_table_attributes.map.with_index do |attribute, index|
    case attribute.type
    when :association
      Column.new(attribute.association_name, sort: false)
    else
      Column.new(attribute.name, link: index.zero?, align: (:center if [:datetime, :boolean].include?(attribute.type)))
    end
  end
end