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.
Assuming you generated views in
erb
format find following lines in _paginator.erb partial:<% if page.left_outer? || page.right_outer? || page.inside_window? -%> <%= page_tag page %>
Add special condition (or supply your custom logic) :
page.logarithmic?
Example:
<% 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
At the moment 2 strategies are available(TODO: describe both):
:even
.:fixed_steps
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