-
-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add customizable indicator arrows #726
Changes from all commits
38c34ed
208a222
28dc9d1
c8a256a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,8 +213,18 @@ The sort link may be displayed without the order indicator arrow by passing | |
<%= sort_link(@q, :name, hide_indicator: true) %> | ||
``` | ||
|
||
Alternatively, all sort links may be displayed without the order indicator arrow | ||
by adding this to an initializer file like `config/initializers/ransack.rb`: | ||
These indicator arrows may also be customized by setting them in an initializer file like `config/initializers/ransack.rb`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here :) |
||
|
||
```ruby | ||
Ransack.configure do |c| | ||
c.custom_arrows = { | ||
up_arrow: '<i class="custom-up-arrow-icon"></i>', | ||
down_arrow: 'U+02193' | ||
} | ||
end | ||
``` | ||
|
||
Alternatively, all sort links may be displayed without the order indicator arrows: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here :) |
||
|
||
```ruby | ||
Ransack.configure do |c| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,9 @@ module Configuration | |
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 @@ def ignore_unknown_conditions=(boolean) | |
self.options[:ignore_unknown_conditions] = boolean | ||
end | ||
|
||
# Ransack's default indicator arrows are html-code snippets. These | ||
# arrows may be replaced by anything wrapped in quotation marks. Both | ||
# or just one 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For line 86, I'd suggest (Note: "up arrow" written as text instead of in snakecase) |
||
# 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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,11 +110,11 @@ def initialize(search, attribute, args, params) | |
end | ||
|
||
def up_arrow | ||
'▼'.freeze | ||
Ransack.options[:up_arrow] | ||
end | ||
|
||
def down_arrow | ||
'▲'.freeze | ||
Ransack.options[:down_arrow] | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I originally extracted these 2 public arrow methods out from the private method #order_indicator to allow developers to set custom arrows by overloading them. Now that developers can do it with a config setting, I'm not sure there is any reason to keep them as separate public methods. Performance-wise it would be better to inline them. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, except if anyone is actually overloading these methods now, their apps will break. Never mind 😄 |
||
|
||
def name | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please wrap at 80 characters in the source file?