Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deepfryed/sinatra-paginate
sinatra pagination helper
https://github.com/deepfryed/sinatra-paginate
Last synced: 3 months ago
JSON representation
sinatra pagination helper
- Host: GitHub
- URL: https://github.com/deepfryed/sinatra-paginate
- Owner: deepfryed
- Created: 2012-06-18T01:12:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-05-17T12:03:35.000Z (over 11 years ago)
- Last Synced: 2024-07-17T15:25:41.977Z (4 months ago)
- Language: Ruby
- Size: 108 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
Awesome Lists containing this project
README
# Sinatra Paginate
A simple Sinatra pagination helper.
## Example
```ruby
require 'sinatra/base'
require 'sinatra/paginate'Struct.new('Result', :total, :size, :users)
class MyApp < Sinatra::Base
register Sinatra::Paginatehelpers do
def page
[params[:page].to_i - 1, 0].max
end
endget '/' do
@users = User.all(limit: 10, offset: page * 10)
@result = Struct::Result.new(User.count, @users.count, @users)
haml :index
end
end
``````haml
-# views/index.haml%ul
- @result.users.each do |user|
%li
%span= user.id
%span= user.name!= paginate @result, items_per_page: 10, labels: {first: '«', last: '»'}, renderer: 'haml'
```## Sample Sinatra Application
```
bundle
cd example/
bundle exec rackup -p 3000
```## Options
```
* renderer # rendering engine to use (default: haml)
* view # override default view and use custom one
* items_per_page # maximum items per page (default: 10)
* uri # base pagination uri (defaults: request.path_info)
* width # number of pagination buttons (default: 5)
* labels # text labels for first & last buttons (default: {first: '«', last: '»'})
```# License
[Creative Commons Attribution - CC BY](http://creativecommons.org/licenses/by/3.0)