Class: Trestle::SortHelper::SortLink
- Inherits:
-
Object
- Object
- Trestle::SortHelper::SortLink
- Defined in:
- app/helpers/trestle/sort_helper.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #classes ⇒ Object
- #current_order ⇒ Object
- #default_order ⇒ Object
-
#initialize(field, params, options) ⇒ SortLink
constructor
A new instance of SortLink.
- #order ⇒ Object
- #params ⇒ Object
- #reverse_order(order) ⇒ Object
Constructor Details
#initialize(field, params, options) ⇒ SortLink
Returns a new instance of SortLink.
11 12 13 |
# File 'app/helpers/trestle/sort_helper.rb', line 11 def initialize(field, params, ) @field, @params, @options = field, params, end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
9 10 11 |
# File 'app/helpers/trestle/sort_helper.rb', line 9 def field @field end |
Instance Method Details
#active? ⇒ Boolean
15 16 17 18 |
# File 'app/helpers/trestle/sort_helper.rb', line 15 def active? @params[:sort] == field.to_s || (@options[:default] && !@params.key?(:sort)) end |
#classes ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/trestle/sort_helper.rb', line 40 def classes classes = ["sort"] if active? classes << "sort-#{current_order}" classes << "active" end classes end |
#current_order ⇒ Object
32 33 34 |
# File 'app/helpers/trestle/sort_helper.rb', line 32 def current_order @params[:order] || default_order end |
#default_order ⇒ Object
36 37 38 |
# File 'app/helpers/trestle/sort_helper.rb', line 36 def default_order @options.fetch(:default_order, "asc").to_s end |
#order ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/helpers/trestle/sort_helper.rb', line 24 def order if active? reverse_order(current_order) else default_order end end |
#params ⇒ Object
20 21 22 |
# File 'app/helpers/trestle/sort_helper.rb', line 20 def params @params.merge(sort: field, order: order) end |
#reverse_order(order) ⇒ Object
51 52 53 |
# File 'app/helpers/trestle/sort_helper.rb', line 51 def reverse_order(order) order == "asc" ? "desc" : "asc" end |