Class: Trestle::Table::Column
- Inherits:
-
Object
- Object
- Trestle::Table::Column
- Defined in:
- lib/trestle/table/column.rb
Defined Under Namespace
Classes: Renderer
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #header ⇒ Object
-
#initialize(table, field, options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #renderer(template) ⇒ Object
- #sort_field ⇒ Object
- #sort_options ⇒ Object
- #sortable? ⇒ Boolean
Constructor Details
#initialize(table, field, options = {}, &block) ⇒ Column
Returns a new instance of Column.
6 7 8 9 |
# File 'lib/trestle/table/column.rb', line 6 def initialize(table, field, ={}, &block) @table, @field, @options = table, field, @block = block if block_given? end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/trestle/table/column.rb', line 4 def block @block end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'lib/trestle/table/column.rb', line 4 def field @field end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/trestle/table/column.rb', line 4 def @options end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/trestle/table/column.rb', line 4 def table @table end |
Instance Method Details
#header ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/trestle/table/column.rb', line 31 def header if [:header] [:header] elsif table.admin table.admin.t("table.headers.#{field}", default: table.admin.human_attribute_name(field)) else I18n.t("admin.table.headers.#{field}", default: field.to_s.humanize.titleize) end end |
#renderer(template) ⇒ Object
11 12 13 |
# File 'lib/trestle/table/column.rb', line 11 def renderer(template) Renderer.new(self, template) end |
#sort_field ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/trestle/table/column.rb', line 19 def sort_field if [:sort].is_a?(Hash) [:sort][:field] || field else [:sort] || field end end |
#sort_options ⇒ Object
27 28 29 |
# File 'lib/trestle/table/column.rb', line 27 def [:sort].is_a?(Hash) ? [:sort] : {} end |
#sortable? ⇒ Boolean
15 16 17 |
# File 'lib/trestle/table/column.rb', line 15 def sortable? table.sortable? && [:sort] != false && (!@block || .has_key?(:sort)) end |