rails_paginate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +100 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/rails_paginate.rb +56 -0
- data/lib/rails_paginate/collection.rb +94 -0
- data/lib/rails_paginate/core_ext/active_record.rb +9 -0
- data/lib/rails_paginate/core_ext/array.rb +8 -0
- data/lib/rails_paginate/method.rb +8 -0
- data/lib/rails_paginate/method/base.rb +6 -0
- data/lib/rails_paginate/method/jumping.rb +6 -0
- data/lib/rails_paginate/method/sliding.rb +6 -0
- data/lib/rails_paginate/renderer.rb +8 -0
- data/lib/rails_paginate/renderer/base.rb +6 -0
- data/lib/rails_paginate/renderer/html_default.rb +6 -0
- data/lib/rails_paginate/renderer/html_list.rb +6 -0
- data/rails_paginate.gemspec +95 -0
- data/spec/db/migrate/20110215200000_create_items.rb +7 -0
- data/spec/rails_paginate_spec.rb +202 -0
- data/spec/renderer_html_default_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/10_activerecord.rb +9 -0
- metadata +178 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "autotest/bundler"
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.4.2)
|
5
|
+
abstract (1.0.0)
|
6
|
+
actionmailer (3.0.4)
|
7
|
+
actionpack (= 3.0.4)
|
8
|
+
mail (~> 2.2.15)
|
9
|
+
actionpack (3.0.4)
|
10
|
+
activemodel (= 3.0.4)
|
11
|
+
activesupport (= 3.0.4)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
erubis (~> 2.6.6)
|
14
|
+
i18n (~> 0.4)
|
15
|
+
rack (~> 1.2.1)
|
16
|
+
rack-mount (~> 0.6.13)
|
17
|
+
rack-test (~> 0.5.7)
|
18
|
+
tzinfo (~> 0.3.23)
|
19
|
+
activemodel (3.0.4)
|
20
|
+
activesupport (= 3.0.4)
|
21
|
+
builder (~> 2.1.2)
|
22
|
+
i18n (~> 0.4)
|
23
|
+
activerecord (3.0.4)
|
24
|
+
activemodel (= 3.0.4)
|
25
|
+
activesupport (= 3.0.4)
|
26
|
+
arel (~> 2.0.2)
|
27
|
+
tzinfo (~> 0.3.23)
|
28
|
+
activeresource (3.0.4)
|
29
|
+
activemodel (= 3.0.4)
|
30
|
+
activesupport (= 3.0.4)
|
31
|
+
activesupport (3.0.4)
|
32
|
+
arel (2.0.8)
|
33
|
+
autotest (4.4.6)
|
34
|
+
ZenTest (>= 4.4.1)
|
35
|
+
builder (2.1.2)
|
36
|
+
diff-lcs (1.1.2)
|
37
|
+
erubis (2.6.6)
|
38
|
+
abstract (>= 1.0.0)
|
39
|
+
git (1.2.5)
|
40
|
+
i18n (0.5.0)
|
41
|
+
jeweler (1.5.2)
|
42
|
+
bundler (~> 1.0.0)
|
43
|
+
git (>= 1.2.5)
|
44
|
+
rake
|
45
|
+
mail (2.2.15)
|
46
|
+
activesupport (>= 2.3.6)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.16)
|
51
|
+
polyglot (0.3.1)
|
52
|
+
rack (1.2.1)
|
53
|
+
rack-mount (0.6.13)
|
54
|
+
rack (>= 1.0.0)
|
55
|
+
rack-test (0.5.7)
|
56
|
+
rack (>= 1.0)
|
57
|
+
rails (3.0.4)
|
58
|
+
actionmailer (= 3.0.4)
|
59
|
+
actionpack (= 3.0.4)
|
60
|
+
activerecord (= 3.0.4)
|
61
|
+
activeresource (= 3.0.4)
|
62
|
+
activesupport (= 3.0.4)
|
63
|
+
bundler (~> 1.0)
|
64
|
+
railties (= 3.0.4)
|
65
|
+
railties (3.0.4)
|
66
|
+
actionpack (= 3.0.4)
|
67
|
+
activesupport (= 3.0.4)
|
68
|
+
rake (>= 0.8.7)
|
69
|
+
thor (~> 0.14.4)
|
70
|
+
rake (0.8.7)
|
71
|
+
rspec (2.5.0)
|
72
|
+
rspec-core (~> 2.5.0)
|
73
|
+
rspec-expectations (~> 2.5.0)
|
74
|
+
rspec-mocks (~> 2.5.0)
|
75
|
+
rspec-core (2.5.1)
|
76
|
+
rspec-expectations (2.5.0)
|
77
|
+
diff-lcs (~> 1.1.2)
|
78
|
+
rspec-mocks (2.5.0)
|
79
|
+
simplecov (0.4.0)
|
80
|
+
simplecov-html (~> 0.4.0)
|
81
|
+
simplecov-html (0.4.3)
|
82
|
+
sqlite3 (1.3.3)
|
83
|
+
thor (0.14.6)
|
84
|
+
treetop (1.4.9)
|
85
|
+
polyglot (>= 0.3.1)
|
86
|
+
tzinfo (0.3.24)
|
87
|
+
yard (0.6.4)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
autotest
|
94
|
+
bundler
|
95
|
+
jeweler
|
96
|
+
rails (~> 3.0.0)
|
97
|
+
rspec
|
98
|
+
simplecov
|
99
|
+
sqlite3
|
100
|
+
yard
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Marco Scholl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= rails_paginate
|
2
|
+
|
3
|
+
a new rails 3 paginate plugin as will_paginate replacement
|
4
|
+
better as will_paginate
|
5
|
+
|
6
|
+
== Development status
|
7
|
+
|
8
|
+
* Collection - 100%
|
9
|
+
* -> Array - 100%
|
10
|
+
* -> ActiveRecord - 100%
|
11
|
+
* -> Rspec - 100%
|
12
|
+
* ViewHelper - 10%
|
13
|
+
* -> HtmlDefault
|
14
|
+
* -> HtmlList
|
15
|
+
* -> Rspec
|
16
|
+
|
17
|
+
== Installation
|
18
|
+
Add the following line to your Gemfile
|
19
|
+
gem "rails_paginate"
|
20
|
+
|
21
|
+
If you want to use it as plugin
|
22
|
+
rails plugin install git://github.com/traxanos/rails_paginate.git
|
23
|
+
|
24
|
+
== Using
|
25
|
+
|
26
|
+
=== ActiveRecord
|
27
|
+
|
28
|
+
User.order(:login).where(:active => 1).paginate :page => 1, :per_page => 10
|
29
|
+
|
30
|
+
=== Array
|
31
|
+
|
32
|
+
(1..555).to_a.paginate :page => 1, :per_page => 10
|
33
|
+
|
34
|
+
|
35
|
+
== Maintainers
|
36
|
+
|
37
|
+
* Team Phatworx (http://github.com/phatworx)
|
38
|
+
* Marco Scholl (http://github.com/traxanos)
|
39
|
+
|
40
|
+
== Contributing to rails_paginate
|
41
|
+
|
42
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
43
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
44
|
+
* Fork the project
|
45
|
+
* Start a feature/bugfix branch
|
46
|
+
* Commit and push until you are happy with your contribution
|
47
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
49
|
+
|
50
|
+
== Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2011 Marco Scholl. See LICENSE.txt for further details.
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "rails_paginate"
|
16
|
+
gem.homepage = "http://github.com/phatworx/rails_paginate"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{a new rails 3 paginate plugin}
|
19
|
+
gem.description = %Q{a new rails 3 paginate plugin as will_paginate replacement}
|
20
|
+
gem.email = "develop@marco-scholl.de"
|
21
|
+
gem.authors = ["Marco Scholl"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'yard'
|
38
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails_paginate'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
# nice rails paginate plugin
|
4
|
+
module RailsPaginate
|
5
|
+
autoload :Renderer, 'rails_paginate/renderer'
|
6
|
+
autoload :Collection, 'rails_paginate/collection'
|
7
|
+
|
8
|
+
# page_param
|
9
|
+
mattr_accessor :page_param
|
10
|
+
@@page_param = :page
|
11
|
+
|
12
|
+
# per_page
|
13
|
+
mattr_accessor :per_page
|
14
|
+
@@per_page = 20
|
15
|
+
|
16
|
+
# method: :jumping or :sliding
|
17
|
+
mattr_accessor :method
|
18
|
+
@@method = :sliding
|
19
|
+
|
20
|
+
|
21
|
+
class << self
|
22
|
+
# to configure rails_paginate
|
23
|
+
# for a sample look the readme.rdoc file
|
24
|
+
def setup
|
25
|
+
yield self
|
26
|
+
end
|
27
|
+
|
28
|
+
# renderer
|
29
|
+
def renderer(renderer = nil, &block)
|
30
|
+
if renderer.nil?
|
31
|
+
@renderer
|
32
|
+
else
|
33
|
+
renderer = renderer.to_s if renderer.is_a? Symbol
|
34
|
+
if renderer.is_a? String
|
35
|
+
renderer = "rails_paginate/renderer/#{renderer}".camelize.constantize
|
36
|
+
end
|
37
|
+
|
38
|
+
if block_given?
|
39
|
+
@renderer = renderer.new &block
|
40
|
+
else
|
41
|
+
@renderer = renderer.new
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def init
|
47
|
+
require 'rails_paginate/core_ext/active_record'
|
48
|
+
require 'rails_paginate/core_ext/array'
|
49
|
+
|
50
|
+
# set default method
|
51
|
+
renderer :html_default
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
RailsPaginate.init
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module RailsPaginate
|
2
|
+
# method modules
|
3
|
+
class Collection < Array
|
4
|
+
attr_reader :current_page, :per_page, :pages, :array_or_relation
|
5
|
+
|
6
|
+
# initialize collection
|
7
|
+
def initialize(array_or_relation, page = nil, per_page = nil)
|
8
|
+
# validate
|
9
|
+
raise ArgumentError, "per_page is not valid" if not per_page.nil? and per_page <= 0
|
10
|
+
raise ArgumentError, "result is not an array or relation" unless array_or_relation.respond_to? :count
|
11
|
+
|
12
|
+
# array_or_relation
|
13
|
+
@array_or_relation = array_or_relation
|
14
|
+
|
15
|
+
# save meta data
|
16
|
+
@per_page = per_page || RailsPaginate.per_page
|
17
|
+
|
18
|
+
# load page with result
|
19
|
+
load_page(page) unless page.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
# switch page
|
23
|
+
def load_page(page)
|
24
|
+
# jump to correct page
|
25
|
+
page = page.to_i if page.is_a? String
|
26
|
+
page = first_page unless page.is_a? Fixnum
|
27
|
+
page = first_page unless page > 0
|
28
|
+
page = last_page if page > pages
|
29
|
+
|
30
|
+
# save page
|
31
|
+
@current_page = page
|
32
|
+
|
33
|
+
# load result
|
34
|
+
load_result
|
35
|
+
end
|
36
|
+
|
37
|
+
# load result from input array_or_relation to internal array
|
38
|
+
def load_result
|
39
|
+
if array_or_relation.is_a? Array
|
40
|
+
self.replace array_or_relation[offset..(offset + per_page - 1)]
|
41
|
+
else
|
42
|
+
self.replace array_or_relation.limit(@per_page).offset(offset).all
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def total
|
47
|
+
@total ||= array_or_relation.count
|
48
|
+
end
|
49
|
+
|
50
|
+
def pages
|
51
|
+
@pages ||= (total / per_page.to_f).ceil
|
52
|
+
end
|
53
|
+
|
54
|
+
# get offset
|
55
|
+
def offset
|
56
|
+
(current_page - 1) * per_page
|
57
|
+
end
|
58
|
+
|
59
|
+
# need paginate
|
60
|
+
def need_paginate?
|
61
|
+
total > per_page
|
62
|
+
end
|
63
|
+
|
64
|
+
# return first page
|
65
|
+
def first_page
|
66
|
+
1
|
67
|
+
end
|
68
|
+
|
69
|
+
# return last page
|
70
|
+
def last_page
|
71
|
+
pages
|
72
|
+
end
|
73
|
+
|
74
|
+
# is current page the last page?
|
75
|
+
def last_page?
|
76
|
+
current_page == last_page
|
77
|
+
end
|
78
|
+
|
79
|
+
# is current page the first page?
|
80
|
+
def first_page?
|
81
|
+
current_page == first_page
|
82
|
+
end
|
83
|
+
|
84
|
+
# return next page
|
85
|
+
def next_page
|
86
|
+
current_page < pages ? (current_page + 1) : nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# return previous page
|
90
|
+
def previous_page
|
91
|
+
current_page > 1 ? (current_page - 1) : nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
class ActiveRecord::Base
|
3
|
+
def self.paginate(*args)
|
4
|
+
options = args.extract_options!
|
5
|
+
per_page = options.delete(:per_page) || RailsPaginate.per_page
|
6
|
+
page = options.delete(:page) || 1
|
7
|
+
RailsPaginate::Collection.new(self, page, per_page)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rails_paginate}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marco Scholl"]
|
12
|
+
s.date = %q{2011-02-15}
|
13
|
+
s.description = %q{a new rails 3 paginate plugin as will_paginate replacement}
|
14
|
+
s.email = %q{develop@marco-scholl.de}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".autotest",
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"init.rb",
|
30
|
+
"lib/rails_paginate.rb",
|
31
|
+
"lib/rails_paginate/collection.rb",
|
32
|
+
"lib/rails_paginate/core_ext/active_record.rb",
|
33
|
+
"lib/rails_paginate/core_ext/array.rb",
|
34
|
+
"lib/rails_paginate/method.rb",
|
35
|
+
"lib/rails_paginate/method/base.rb",
|
36
|
+
"lib/rails_paginate/method/jumping.rb",
|
37
|
+
"lib/rails_paginate/method/sliding.rb",
|
38
|
+
"lib/rails_paginate/renderer.rb",
|
39
|
+
"lib/rails_paginate/renderer/base.rb",
|
40
|
+
"lib/rails_paginate/renderer/html_default.rb",
|
41
|
+
"lib/rails_paginate/renderer/html_list.rb",
|
42
|
+
"rails_paginate.gemspec",
|
43
|
+
"spec/db/migrate/20110215200000_create_items.rb",
|
44
|
+
"spec/rails_paginate_spec.rb",
|
45
|
+
"spec/renderer_html_default_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/support/10_activerecord.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/phatworx/rails_paginate}
|
50
|
+
s.licenses = ["MIT"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.5.0}
|
53
|
+
s.summary = %q{a new rails 3 paginate plugin}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/db/migrate/20110215200000_create_items.rb",
|
56
|
+
"spec/rails_paginate_spec.rb",
|
57
|
+
"spec/renderer_html_default_spec.rb",
|
58
|
+
"spec/spec_helper.rb",
|
59
|
+
"spec/support/10_activerecord.rb"
|
60
|
+
]
|
61
|
+
|
62
|
+
if s.respond_to? :specification_version then
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
|
67
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
69
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
70
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
72
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
73
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
76
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
77
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
78
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
79
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
80
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
83
|
+
end
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
86
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
87
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
88
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
89
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
90
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
91
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
92
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate do
|
4
|
+
describe :setup, "to configure" do
|
5
|
+
RailsPaginate.setup do |setup|
|
6
|
+
subject { setup }
|
7
|
+
|
8
|
+
describe :per_page, "set to 15" do
|
9
|
+
before { subject.per_page = 15 }
|
10
|
+
its(:per_page) { should be 15 }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe :page_param, "set to :p" do
|
14
|
+
before { subject.page_param = :p }
|
15
|
+
its(:page_param) { should be :p }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :renderer, "set to :html_default" do
|
19
|
+
before { subject.renderer :html_default }
|
20
|
+
its(:renderer) { should be_a RailsPaginate::Renderer::HtmlDefault }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe :renderer, "set to :html_list" do
|
24
|
+
before { subject.renderer :html_list }
|
25
|
+
its(:renderer) { should be_a RailsPaginate::Renderer::HtmlList }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe :renderer, "set with block" do
|
29
|
+
setup.renderer :html_list do |renderer_setup|
|
30
|
+
subject { renderer_setup }
|
31
|
+
its(:renderer) { should be_a RailsPaginate::Renderer::HtmlDefault }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe RailsPaginate::Collection do
|
40
|
+
before :all do
|
41
|
+
RailsPaginate.setup do |setup|
|
42
|
+
setup.per_page = 10
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe Item, "with 561 items" do
|
47
|
+
before(:all) do
|
48
|
+
561.times { |x| Item.create! :dummy => "Item #{x}" }
|
49
|
+
end
|
50
|
+
subject { Item }
|
51
|
+
specify { should respond_to :paginate }
|
52
|
+
|
53
|
+
describe "return of #paginate" do
|
54
|
+
subject { Item.paginate }
|
55
|
+
it { should be_a RailsPaginate::Collection }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "without per_page on first page" do
|
59
|
+
before(:all) { @collection = Item.paginate :page => 1 }
|
60
|
+
subject { @collection }
|
61
|
+
its(:count) { should eq 10 }
|
62
|
+
its(:pages) { should eq 57 }
|
63
|
+
its(:total) { should eq 561 }
|
64
|
+
its(:offset) { should eq 0 }
|
65
|
+
its(:next_page) { should eq 2 }
|
66
|
+
its(:previous_page) { should be_nil }
|
67
|
+
its(:need_paginate?) { should be_true }
|
68
|
+
its(:first_page?) { should be_true }
|
69
|
+
its(:last_page?) { should be_false }
|
70
|
+
end
|
71
|
+
|
72
|
+
context "without per_page on page 10" do
|
73
|
+
before(:all) { @collection = Item.paginate :page => 10 }
|
74
|
+
subject { @collection }
|
75
|
+
its(:count) { should eq 10 }
|
76
|
+
its(:pages) { should eq 57 }
|
77
|
+
its(:total) { should eq 561 }
|
78
|
+
its(:offset) { should eq 90 }
|
79
|
+
its(:next_page) { should eq 11 }
|
80
|
+
its(:previous_page) { should eq 9 }
|
81
|
+
its(:need_paginate?) { should be_true }
|
82
|
+
its(:first_page?) { should be_false }
|
83
|
+
its(:last_page?) { should be_false }
|
84
|
+
end
|
85
|
+
|
86
|
+
context "without per_page on last page" do
|
87
|
+
before(:all) { @collection = Item.paginate :page => 57 }
|
88
|
+
subject { @collection }
|
89
|
+
its(:count) { should eq 1 }
|
90
|
+
its(:pages) { should eq 57 }
|
91
|
+
its(:total) { should eq 561 }
|
92
|
+
its(:offset) { should eq 560 }
|
93
|
+
its(:next_page) { should be_nil }
|
94
|
+
its(:previous_page) { should eq 56 }
|
95
|
+
its(:need_paginate?) { should be_true }
|
96
|
+
its(:first_page?) { should be_false }
|
97
|
+
its(:last_page?) { should be_true }
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with per_page 60 on page 4" do
|
101
|
+
before(:all) { @collection = Item.paginate :page => 3, :per_page => 60 }
|
102
|
+
subject { @collection }
|
103
|
+
its(:count) { should eq 60 }
|
104
|
+
its(:pages) { should eq 10 }
|
105
|
+
its(:total) { should eq 561 }
|
106
|
+
its(:offset) { should eq 120 }
|
107
|
+
its(:next_page) { should eq 4 }
|
108
|
+
its(:previous_page) { should eq 2 }
|
109
|
+
its(:need_paginate?) { should be_true }
|
110
|
+
its(:first_page?) { should be_false }
|
111
|
+
its(:last_page?) { should be_false }
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Array, "with 199 items" do
|
117
|
+
before(:all) { @array = (1..199).to_a }
|
118
|
+
subject { @array }
|
119
|
+
specify { should respond_to :paginate }
|
120
|
+
|
121
|
+
describe "return of #paginate" do
|
122
|
+
subject { @array.paginate }
|
123
|
+
it { should be_a RailsPaginate::Collection }
|
124
|
+
end
|
125
|
+
|
126
|
+
context "without per_page on first page" do
|
127
|
+
before(:all) { @collection = @array.paginate :page => 1 }
|
128
|
+
subject { @collection }
|
129
|
+
its(:count) { should eq 10 }
|
130
|
+
its(:pages) { should eq 20 }
|
131
|
+
its(:total) { should eq 199 }
|
132
|
+
its(:offset) { should eq 0 }
|
133
|
+
its(:next_page) { should eq 2 }
|
134
|
+
its(:previous_page) { should be_nil }
|
135
|
+
its(:need_paginate?) { should be_true }
|
136
|
+
its(:first_page?) { should be_true }
|
137
|
+
its(:last_page?) { should be_false }
|
138
|
+
end
|
139
|
+
|
140
|
+
context "without per_page on page 10" do
|
141
|
+
before(:all) { @collection = @array.paginate :page => 10 }
|
142
|
+
subject { @collection }
|
143
|
+
its(:count) { should eq 10 }
|
144
|
+
its(:pages) { should eq 20 }
|
145
|
+
its(:total) { should eq 199 }
|
146
|
+
its(:offset) { should eq 90 }
|
147
|
+
its(:next_page) { should eq 11 }
|
148
|
+
its(:previous_page) { should eq 9 }
|
149
|
+
its(:need_paginate?) { should be_true }
|
150
|
+
its(:first_page?) { should be_false }
|
151
|
+
its(:last_page?) { should be_false }
|
152
|
+
end
|
153
|
+
|
154
|
+
context "without per_page on last page" do
|
155
|
+
before(:all) { @collection = @array.paginate :page => 20 }
|
156
|
+
subject { @collection }
|
157
|
+
its(:count) { should eq 9 }
|
158
|
+
its(:pages) { should eq 20 }
|
159
|
+
its(:total) { should eq 199 }
|
160
|
+
its(:offset) { should eq 190 }
|
161
|
+
its(:next_page) { should be_nil }
|
162
|
+
its(:previous_page) { should eq 19 }
|
163
|
+
its(:need_paginate?) { should be_true }
|
164
|
+
its(:first_page?) { should be_false }
|
165
|
+
its(:last_page?) { should be_true }
|
166
|
+
end
|
167
|
+
|
168
|
+
context "with per_page 60 on page 4" do
|
169
|
+
before(:all) { @collection = @array.paginate :page => 3, :per_page => 60 }
|
170
|
+
subject { @collection }
|
171
|
+
its(:count) { should eq 60 }
|
172
|
+
its(:pages) { should eq 4 }
|
173
|
+
its(:total) { should eq 199 }
|
174
|
+
its(:offset) { should eq 120 }
|
175
|
+
its(:next_page) { should eq 4 }
|
176
|
+
its(:previous_page) { should eq 2 }
|
177
|
+
its(:need_paginate?) { should be_true }
|
178
|
+
its(:first_page?) { should be_false }
|
179
|
+
its(:last_page?) { should be_false }
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
describe Array, "with 6 items" do
|
185
|
+
before(:all) { @array = (1..6).to_a }
|
186
|
+
context "without per_page on last page" do
|
187
|
+
before(:all) { @collection = @array.paginate :page => 1 }
|
188
|
+
subject { @collection }
|
189
|
+
its(:count) { should eq 6 }
|
190
|
+
its(:pages) { should eq 1 }
|
191
|
+
its(:total) { should eq 6 }
|
192
|
+
its(:offset) { should eq 0 }
|
193
|
+
its(:next_page) { should be_nil }
|
194
|
+
its(:previous_page) { should be_nil }
|
195
|
+
its(:need_paginate?) { should be_false }
|
196
|
+
its(:first_page?) { should be_true }
|
197
|
+
its(:last_page?) { should be_true }
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start 'rails'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rails_paginate'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
ActiveRecord::Base.establish_connection({
|
2
|
+
:adapter => 'sqlite3',
|
3
|
+
:database => ":memory:"
|
4
|
+
})
|
5
|
+
ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', 'db', 'migrate'))
|
6
|
+
|
7
|
+
class Item < ActiveRecord::Base
|
8
|
+
scope :reverse_sort, order("dummy DESC")
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_paginate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marco Scholl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-15 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.0.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: autotest
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bundler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: jeweler
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: simplecov
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rspec
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: yard
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
description: a new rails 3 paginate plugin as will_paginate replacement
|
105
|
+
email: develop@marco-scholl.de
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files:
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.rdoc
|
113
|
+
files:
|
114
|
+
- .autotest
|
115
|
+
- .document
|
116
|
+
- .rspec
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.rdoc
|
121
|
+
- Rakefile
|
122
|
+
- VERSION
|
123
|
+
- init.rb
|
124
|
+
- lib/rails_paginate.rb
|
125
|
+
- lib/rails_paginate/collection.rb
|
126
|
+
- lib/rails_paginate/core_ext/active_record.rb
|
127
|
+
- lib/rails_paginate/core_ext/array.rb
|
128
|
+
- lib/rails_paginate/method.rb
|
129
|
+
- lib/rails_paginate/method/base.rb
|
130
|
+
- lib/rails_paginate/method/jumping.rb
|
131
|
+
- lib/rails_paginate/method/sliding.rb
|
132
|
+
- lib/rails_paginate/renderer.rb
|
133
|
+
- lib/rails_paginate/renderer/base.rb
|
134
|
+
- lib/rails_paginate/renderer/html_default.rb
|
135
|
+
- lib/rails_paginate/renderer/html_list.rb
|
136
|
+
- rails_paginate.gemspec
|
137
|
+
- spec/db/migrate/20110215200000_create_items.rb
|
138
|
+
- spec/rails_paginate_spec.rb
|
139
|
+
- spec/renderer_html_default_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/support/10_activerecord.rb
|
142
|
+
has_rdoc: true
|
143
|
+
homepage: http://github.com/phatworx/rails_paginate
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
hash: 2756331228915534243
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
version: "0"
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: "0"
|
166
|
+
requirements: []
|
167
|
+
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 1.5.0
|
170
|
+
signing_key:
|
171
|
+
specification_version: 3
|
172
|
+
summary: a new rails 3 paginate plugin
|
173
|
+
test_files:
|
174
|
+
- spec/db/migrate/20110215200000_create_items.rb
|
175
|
+
- spec/rails_paginate_spec.rb
|
176
|
+
- spec/renderer_html_default_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/support/10_activerecord.rb
|