Add custom_arrows config functionality

This commit is contained in:
Garett Arrowood 2016-09-27 11:17:55 -04:00
parent 0a0cee3f77
commit 38c34ed314
2 changed files with 23 additions and 3 deletions

View File

@ -9,7 +9,9 @@ module Ransack
self.options = {
:search_key => :q,
:ignore_unknown_conditions => true,
:hide_sort_order_indicators => false
:hide_sort_order_indicators => false,
:up_arrow => '▼'.freeze,
:down_arrow => '▲'.freeze
}
def configure
@ -75,6 +77,24 @@ module Ransack
self.options[:ignore_unknown_conditions] = boolean
end
# Ransack's default arrows are html-code snippets found options at the
# top of this file. Arrows may be anything wrapped in quotation marks.
# Both arrows or a single arrow may be globally overridden in an
# initializer file like `config/initializers/ransack.rb` as follows:
#
# Ransack.configure do |config|
# # Set the up_arrow as an icon, set the down arrow as unicode
# config.custom_arrows = {
# up_arrow: '<i class="fa fa-long-arrow-up"></i>',
# down_arrow: 'U+02193'
# }
# end
#
def custom_arrows=(opts = {})
self.options[:up_arrow] = opts[:up_arrow].freeze if opts[:up_arrow]
self.options[:down_arrow] = opts[:down_arrow].freeze if opts[:down_arrow]
end
# By default, Ransack displays sort order indicator arrows in sort links.
# The default may be globally overridden in an initializer file like
# `config/initializers/ransack.rb` as follows:

View File

@ -110,11 +110,11 @@ module Ransack
end
def up_arrow
'&#9660;'.freeze
Ransack.options[:up_arrow]
end
def down_arrow
'&#9650;'.freeze
Ransack.options[:down_arrow]
end
def name