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.



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ransack/helpers/form_helper.rb', line 165

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



186
187
188
# File 'lib/ransack/helpers/form_helper.rb', line 186

def default_arrow
  Ransack.options[:default_arrow]
end

#down_arrowObject



182
183
184
# File 'lib/ransack/helpers/form_helper.rb', line 182

def down_arrow
  Ransack.options[:down_arrow]
end

#html_options(args) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/ransack/helpers/form_helper.rb', line 203

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



190
191
192
193
194
195
# File 'lib/ransack/helpers/form_helper.rb', line 190

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

#up_arrowObject



178
179
180
# File 'lib/ransack/helpers/form_helper.rb', line 178

def up_arrow
  Ransack.options[:up_arrow]
end

#url_optionsObject



197
198
199
200
201
# File 'lib/ransack/helpers/form_helper.rb', line 197

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