Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Pagination tools for Array(or custom class), DataMapper and ActiveRecord
Ruby
tag: pagify-0.6.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
test
tmp
.gitignore
CHANGES
LICENSE
NOTICE
README
Rakefile
TODO
pagify.gemspec

README

= pagify 0.6.2
by Lin Jen-Shin (aka godfat-真常[http://godfat.org])
  godfat (XD) godfat.org

== LINKS:

* github-project[http://github.com/godfat/pagify]
* rubyforge-project[http://rubyforge.org/projects/ludy]

== DESCRIPTION:

 Pagination tools for Array(or custom class), DataMapper and ActiveRecord

== FEATURES:

* Aims to be as flexible as possible
* Separate intrusive "pagify" method and Array/DataMapper/ActiveRecord Pager.
* Separate view helpers. There's only html helper right now.

== SYNOPSIS:

 # for fast will_paginate replacement:
 require 'pagify/active_record'
 require 'pagify/helper/rails'

 # in controller:
 @photos = Photo.pagify(:page => params[:page])

 # in view:
 pagify_links(@photos)



 # basic DataMapper usage:
 require 'pagify/data_mapper'

 class User
   include DataMapper::Resource
   property :id, Serial
   property :name, String
   has n, :pets
 end

 class Pet
   include DataMapper::Resource
   property :id, Serial
   property :name, String
   belongs_to :user
 end

 User.pagify :page => 1, :per_page => 10 # => create a page contains users
 User.all(:name => 'godfat').pagify      # => create a page contains users named godfat

 User.get(1).pets.pagify                 # => create a page contains pets owned by user 1



 # basic html helper usage:
 require 'pagify/helper/html'

 # create a string with page links.
 Pet.pagify.pager.html.links(params[:page]){ |page|
   # the block result would be used as url for each page
   "/pets/list?page=#{page}"
 }

 Pagify::Helper::HTML.setting[:prev_text] = '<]' # globally change html setting
 # NOTE: if you would like to use instance level setting, you shouldn't use method pagify,
 # NOTE: new your own DataMapperPager or so to remember instance level html setting.
 # NOTE: for example, see below:

 class Pet
 # same as above
   def self.page num
     @pager ||= begin
       pager = Pagify::DataMapperPager.new(:per_page => 20)
       # below would be pager instance level setting
       # you can setup global setting mentioned above in your init script perhaps
       pager.html.setting[:separator] = ' . '
       pager.html.setting[:ellipsis]  = '...'
       pager
     end
     @pager.page(num)
   end
 end

 # then you would use Pet.page(3) or user.pets.page(2) to retrieve data

 # this would create next/prev links only.
 Pet.page(1).html.links_navigate{ |page|
   "/pets/list?page=#{page}"
 }

 # this would create next/prev links and other page links
 pet_pager.page(1).html.links_full{ |page|
   "/pets/show?page=#{page}"
 }

 # and you can build your pager from scratch via BasicPager.
 # e.g. BasicPager.new :fetcher => lambda{|*a|[]}, :counter => lambda{0}
 # this would be similar to Pagify::NullPager.

 # you can disable null page via passing :null_page => false to any pager,
 # or set pager.null_page = false; anytime.

 # see example or test for more examples (and use case for ActiveRecordPager).

== REQUIREMENTS:

* ruby 1.8+ or 1.9.1+
* for  Basic/ArrayPager: only ruby is needed
* for   DataMapperPager: dm-core and dm-aggregates 0.9.9+
* for ActiveRecordPager: activerecord 2.1.1+

== INSTALL:

* gem install pagify

== LICENSE:

Apache License 2.0

Copyright (c) 2008, Lin Jen-Shin (aka godfat 真常)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Something went wrong with that request. Please try again.