Module: TableFor::ViewAdditions::ClassMethods
- Defined in:
- lib/table_for/view_additions.rb
Instance Method Summary collapse
- #table_for(records, options = {}, &block) ⇒ Object
- #table_for_cell_data(record, column, options) ⇒ Object
- #table_for_header_html(table, column, options = {}) ⇒ Object
- #table_for_sort_link(column, options = {}) ⇒ Object
- #table_for_table_html(options) ⇒ Object
Instance Method Details
#table_for(records, options = {}, &block) ⇒ Object
4 5 6 |
# File 'lib/table_for/view_additions.rb', line 4 def table_for(records, ={}, &block) TableFor::Base.new(self, .merge(:variable => "table", :records => records, :use_partials => false)).render_template("table_for/table_for", &block) end |
#table_for_cell_data(record, column, options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/table_for/view_additions.rb', line 38 def table_for_cell_data(record, column, ) if ([:transformation]) if [:transformation].is_a?(Proc) [:transformation].call(*[record, column, ][0, [:transformation].arity]) else record.send(column.name).try(*[:transformation]) end else record.send(column.name) end end |
#table_for_header_html(table, column, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/table_for/view_additions.rb', line 8 def table_for_header_html(table, column, ={}) header_html = table.evaluated_procs([:header_html], column) if [:sortable] order = [:order] ? [:order].to_s : column.name.to_s sort_class = (params[:order] != order || params[:sort_mode] == "reset") ? "sorting" : (params[:sort_mode] == "desc" ? "sorting_desc" : "sorting_asc") header_html[:class] = (header_html[:class] ? "#{header_html[:class]} #{sort_class}" : sort_class) end header_html end |
#table_for_sort_link(column, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/table_for/view_additions.rb', line 18 def table_for_sort_link(column, ={}) order = [:order] ? [:order].to_s : column.name.to_s label = ([:label] ? [:label] : column.name.to_s.titleize) sort_mode = (params[:order] != order || params[:sort_mode] == "reset") ? "asc" : (params[:sort_mode] == "desc" ? "reset" : "desc") parameters = params.merge(:order => order, :sort_mode => sort_mode) parameters.delete(:action) parameters.delete(:controller) url = [:sort_url] ? [:sort_url] : "" link_to label, "#{url}?#{parameters.to_query}" end |
#table_for_table_html(options) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/table_for/view_additions.rb', line 29 def table_for_table_html() if [:table_html] [:table_html].merge!(:class => TableFor.default_table_class) if TableFor.default_table_class && ![:table_html][:class] [:table_html] elsif TableFor.default_table_class {:class => TableFor.default_table_class} end end |