Skip to content

Latest commit

 

History

History
102 lines (62 loc) · 2.95 KB

README.md

File metadata and controls

102 lines (62 loc) · 2.95 KB

Roda::WillPaginate

Use this plugin to use Will Paginate from Roda.

Installation

Add this line to your application's Gemfile:

gem 'roda-will_paginate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install roda-will_paginate

Usage

Add the plugin directive to your app

plugin :will_paginate

On your views you can use the same method you would use on a Rails app ie.

<%= will_paginate @collection %>

to include pagination links.

Links generated for pagination will include a parameter page=[page_no] that will have to be handled correctly by your application when requesting different pages.

Making collections work with Will Paginate

Please take into consideration that this plugin only takes care of generating the links to pages on your views, your paginated collections should comply with WillPaginate's requirements, these are defined in https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/collection.rb.

If you are using Sequel with your Roda app, you can easily enable to appropriate functionality. You need to enable the Sequel pagination extension; DB.extension(:pagination) and require will_paginate/sequel in your app class.

Otherwise, you will need to implement the interface yourself. Include WillPaginate::CollectionMethods and add current_page, per_page, offset, total_entries, total_pages as methods on your collection.

Customizing pagination links

In case you would like to customize the generated links you need to implement a renderer. Please take a look at Will Paginate's documentation to learn how to create your own renderers.

Alternative Twitter Bootstrap Pagination Theme:

We include a customized renderer if you are working with Twitter bootstrap, just:

require 'roda/will_paginate/bootstrap_pagination_renderer'

in you application and then specify the renderer to Will Paginate:

<%= will_paginate @collection, renderer: :bootstrap %>

or

<%= will_paginate @collection, renderer: Roda::WillPaginate::BootstrapPaginationRenderer %>

Alternative you can set it in the plugin configuration to avoid repeating it in each helper call:

plugin :will_paginate, renderer: :bootstrap

or

plugin :will_paginate, renderer: Roda::WillPaginate::BootstrapPaginationRenderer

Custom renderers

Please take a look at the Will Paginate docs to see how renderers work.

If you have a custom renderer named Foo you can namespace it inside Roda::WillPaginate::FooRenderer and then use the symbol :foo to refer to it. For example:

plugin :will_paginate, renderer: :foo

Contributing

  1. Fork it ( https://github.com/manuca/roda-will_paginate/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request