Class: Ransack::Helpers::FormHelper::SortLink

Inherits:
Object
  • Object
show all
Defined in:
lib/ransack/helpers/form_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(search, attribute, args, params) ⇒ SortLink

Returns a new instance of SortLink.



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ransack/helpers/form_helper.rb', line 99

def initialize(search, attribute, args, params)
  @search         = search
  @params         = parameters_hash(params)
  @field          = attribute.to_s
  @sort_fields    = extract_sort_fields_and_mutate_args!(args).compact
  @current_dir    = existing_sort_direction
  @label_text     = extract_label_and_mutate_args!(args)
  @options        = extract_options_and_mutate_args!(args)
  @hide_indicator = @options.delete(:hide_indicator) ||
                    Ransack.options[:hide_sort_order_indicators]
  @default_order  = @options.delete :default_order
end

Instance Method Details

#default_arrowObject



120
121
122
# File 'lib/ransack/helpers/form_helper.rb', line 120

def default_arrow
  Ransack.options[:default_arrow]
end

#down_arrowObject



116
117
118
# File 'lib/ransack/helpers/form_helper.rb', line 116

def down_arrow
  Ransack.options[:down_arrow]
end

#html_options(args) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ransack/helpers/form_helper.rb', line 137

def html_options(args)
  if args.empty?
    html_options = @options
  else
    deprecation_message = "Passing two trailing hashes to `sort_link` is deprecated, merge the trailing hashes into a single one."
    caller_location = caller_locations(2, 2).first
    warn "#{deprecation_message} (called at #{caller_location.path}:#{caller_location.lineno})"
    html_options = extract_options_and_mutate_args!(args)
  end

  html_options.merge(
    class: [['sort_link'.freeze, @current_dir], html_options[:class]]
           .compact.join(' '.freeze)
  )
end

#nameObject



124
125
126
127
128
129
# File 'lib/ransack/helpers/form_helper.rb', line 124

def name
  [ERB::Util.h(@label_text), order_indicator]
  .compact
  .join(' '.freeze)
  .html_safe
end

#up_arrowObject



112
113
114
# File 'lib/ransack/helpers/form_helper.rb', line 112

def up_arrow
  Ransack.options[:up_arrow]
end

#url_optionsObject



131
132
133
134
135
# File 'lib/ransack/helpers/form_helper.rb', line 131

def url_options
  @params.except(:host).merge(
    @options.except(:class, :data, :host).merge(
      @search.context.search_key => search_and_sort_params))
end