Module: SortableTable::App::Helpers::ApplicationHelper::InstanceMethods
- Defined in:
- lib/sortable_table/app/helpers/application_helper.rb
Instance Method Summary collapse
- #class_name_for_sortable_table_header_tag(opts) ⇒ Object
- #default_sort_to_most_recent?(opts) ⇒ Boolean
- #link_sort_order(opts) ⇒ Object
- #re_sort?(opts) ⇒ Boolean
- #reverse_order(order) ⇒ Object
- #sortable_table_header(opts = {}) ⇒ Object
- #sortable_url(opts) ⇒ Object
Instance Method Details
#class_name_for_sortable_table_header_tag(opts) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 23 def class_name_for_sortable_table_header_tag(opts) if default_sort_to_most_recent? opts 'descending' elsif re_sort? opts params[:order] else nil end end |
#default_sort_to_most_recent?(opts) ⇒ Boolean
33 34 35 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 33 def default_sort_to_most_recent?(opts) params[:sort].nil? && opts[:sort] == 'date' end |
#link_sort_order(opts) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 49 def link_sort_order(opts) if default_sort_to_most_recent? opts 'ascending' elsif re_sort? opts reverse_order params[:order] else 'ascending' end end |
#re_sort?(opts) ⇒ Boolean
37 38 39 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 37 def re_sort?(opts) params[:sort] == opts[:sort] end |
#reverse_order(order) ⇒ Object
41 42 43 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 41 def reverse_order(order) order == 'ascending' ? 'descending' : 'ascending' end |
#sortable_table_header(opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 13 def sortable_table_header(opts = {}) raise ArgumentError if opts[:name].nil? || opts[:sort].nil? anchor = opts[:anchor].blank? ? "" : "##{opts[:anchor]}" content_tag :th, link_to(opts[:name], sortable_url(opts) + anchor, :title => opts[:title]), :class => class_name_for_sortable_table_header_tag(opts) end |
#sortable_url(opts) ⇒ Object
45 46 47 |
# File 'lib/sortable_table/app/helpers/application_helper.rb', line 45 def sortable_url(opts) url_for(params.merge(:sort => opts[:sort], :order => link_sort_order(opts), :page => 1)) end |