Class: TableSortable::Column
- Inherits:
-
Object
- Object
- TableSortable::Column
- Defined in:
- lib/table_sortable/column.rb,
lib/table_sortable/column/filter.rb,
lib/table_sortable/column/sorter.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#column_partial ⇒ Object
readonly
Returns the value of attribute column_partial.
-
#content(record) ⇒ Object
readonly
Returns the value of attribute content.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#header_partial ⇒ Object
readonly
Returns the value of attribute header_partial.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#placeholder ⇒ Object
readonly
Returns the value of attribute placeholder.
-
#sorter ⇒ Object
readonly
Returns the value of attribute sorter.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
-
#translation_key ⇒ Object
readonly
Returns the value of attribute translation_key.
Instance Method Summary collapse
-
#initialize(col_name, *options) ⇒ Column
constructor
A new instance of Column.
- #value(record) ⇒ Object
Constructor Details
#initialize(col_name, *options) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/table_sortable/column.rb', line 6 def initialize(col_name, *) = . value = [:value] || col_name content = [:content] || value translation_key = [:translation_key] template_path = [:template_path] label = [:label] || ([:label] == false ? '' : I18n.translate("table_sortable.#{"#{translation_key}." if translation_key }#{col_name.to_s}", :default => col_name.to_s).titleize) placeholder = [:placeholder] || ([:placeholder] == false ? nil : label) template = [:template] || col_name = [:options] || {} controller = [:controller] @name = col_name @value = value.respond_to?(:call) ? value : -> (record) { record.send(value) } @content = content.respond_to?(:call) ? content : -> (record) { record.send(content) } @label = label @placeholder = placeholder @template = template @template_path = template_path view_path = @template_path || (defined?(Rails) ? File.join(Rails.root, 'app', 'views', "#{controller.controller_path}/table_sortable/") : '') view_filename = "_#{@template}_column.html" view = Dir.glob(File.join(view_path, "#{view_filename}.*")) @column_partial = view.any? ? File.join(view_path, "#{view_filename}") : false view_filename = "_#{@template}_header.html" view = Dir.glob(File.join(view_path, "#{view_filename}.*")) @header_partial = view.any? ? File.join(view_path, "#{view_filename}") : false @options = @filter = TableSortable::Column::Filter.new(.merge(:column => self) ) @sorter = TableSortable::Column::Sorter.new(.merge(:column => self) ) end |
Instance Attribute Details
#column_partial ⇒ Object (readonly)
Returns the value of attribute column_partial.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def column_partial @column_partial end |
#content(record) ⇒ Object (readonly)
Returns the value of attribute content.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def content @content end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def filter @filter end |
#header_partial ⇒ Object (readonly)
Returns the value of attribute header_partial.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def header_partial @header_partial end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def @options end |
#placeholder ⇒ Object (readonly)
Returns the value of attribute placeholder.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def placeholder @placeholder end |
#sorter ⇒ Object (readonly)
Returns the value of attribute sorter.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def sorter @sorter end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def template @template end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def template_path @template_path end |
#translation_key ⇒ Object (readonly)
Returns the value of attribute translation_key.
4 5 6 |
# File 'lib/table_sortable/column.rb', line 4 def translation_key @translation_key end |
Instance Method Details
#value(record) ⇒ Object
43 44 45 |
# File 'lib/table_sortable/column.rb', line 43 def value(record) record.instance_eval(&@value) unless @value.nil? end |