Kaminari::Logarithmic
This plugin extends popular kaminari gem to provide functionality for distributing big number of pages logarithmically. Such approach originally was discussed here.
Installation
Add this line to your application's Gemfile:
gem 'kaminari-logarithmic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kaminari-logarithmic
Important
Currently you will not see any changes if you use default kaminari views. To make it work you should customize views.
-
First you should generate partials in
app/views/kaminari
folder (skip if you did that earlier):rails g kaminari:views default
More details and options on kaminari documentation page.
2. Assuming you generated views in erb
format find following lines in _paginator.erb partial:
```ruby
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
<%= page_tag page %>
```
- Add special condition (or supply your custom logic) :
page.logarithmic?
Example:
ruby <% if page.logarithmic? || page.left_outer? || page.right_outer? || page.inside_window? -%> <%= page_tag page %>
Usage
Do all the pagination stuff in controller and model usually. In your view use special helper instead of paginate
:
paginate_logarithmic @your_collection
By default even distribution strategy is used. You can specify strategy with strategy
option:
paginate_logarithmic @users, strategy: :fixed_steps
Strategies
At the moment 2 strategies are available:
-
:even
. :fixed_steps
Even distribution strategy
TODO: description and image
Fixed steps strategy
The strategy is illustrated on the following image:
Contributing
- Fork it ( https://github.com/[my-github-username]/kaminari-logarithmic/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request