MobilePagination
Gem for producing minimal pagination links, best suited for smaller screens.
Installation
Add this line to your application's Gemfile:
gem 'mobile_pagination'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mobile_pagination
Usage
Initializes with 4 options: current_page, total_pages, query, path
.
# in your view, you may have something like this:
ol
= pagination_html
# in your helpers, you might have something like:
require 'mobile_pagination'
# http://local.m.newhomeguide.com/New-Homes/Georgia/Atlanta/?page=2
def opts
{
:current_page => params[:page], # => 2
:total_pages => total_pages, # => Int for total pages
:query => request.query_string, # => 'page=2'
:path => request.path # => '/New-Homes/Georgia/Atlanta/'
}
end
def pagination
@pagination ||= MobilePagination::Paginate.new(opts)
end
def pagination_html
pagination.html # => returns paginated elements
end
# Other public methods
previous_page_link # => path for the previous page
next_page_link # => path for the next page
previous_page? # => true or false
next_page? # => true or false
should_paginate? # => true or false
# Readers
current_page, total_pages query, path
Take a look at lib/mobile_pagination/paginate.rb for more information.
Overrides
If you don't like list items, you will need to override MobilePagination::Templates
Just add this to the bottom of one of your view helpers:
module MobilePagination
module Templates
def first_page_html
"<p>
<a title='First Page' href='#{first_page_link}'>Luke's Page</a> |
<p>"
end
def previous_page_html
"<h1>
<a title='Previous Page' href='#{previous_page_link}'>Previous Page</a> |
</h1>"
end
def next_page_html
"<span>
<a title='Next Page' href='#{next_page_link}'>Next Page</a> |
</span>"
end
def last_page_html
"<h3>
<a title='Last Page' href='#{last_page_link}'>Last Page</a>
</h3>"
end
end
end
Please note, any methods ending in _link
will need to remain, as these methods are responsible for generating the paginated urls.
Configuration
Configuration is optional.
Say for example you were paginating slides on a slideshow - instead of using page, you could configure the gem to use a different key.
MobilePagination.configure do |config|
config.page_key = 'slide'
end
Configuration must run prior to initialization. The resulting pagination links will now contain /?slide=2, /?slide=3
to suit your custom url structure. The default page_key is page
.
Contributing
- Fork it
- 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 new Pull Request
Running the Tests
rake
There is a default spec
task that will run.
License
mobile_pagination is released under the MIT License. See the bundled LICENSE file for details.