rails_pagination 2.0.10 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- metadata +18 -174
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -46
- data/Rakefile +0 -40
- data/app/views/rails_pagination/_pager.html.erb +0 -29
- data/config/locales/en.yml +0 -6
- data/config/locales/es.yml +0 -6
- data/lib/rails_pagination.rb +0 -11
- data/lib/rails_pagination/action_view/base.rb +0 -15
- data/lib/rails_pagination/active_record/base.rb +0 -28
- data/lib/rails_pagination/active_record/relation.rb +0 -81
- data/lib/rails_pagination/engine.rb +0 -7
- data/lib/rails_pagination/navigation.rb +0 -39
- data/lib/rails_pagination/pagination.rb +0 -97
- data/lib/rails_pagination/railtie.rb +0 -15
- data/lib/rails_pagination/version.rb +0 -5
- data/test/collection_empty_test.rb +0 -37
- data/test/collection_first_test.rb +0 -38
- data/test/collection_last_test.rb +0 -38
- data/test/collection_middle_test.rb +0 -38
- data/test/collection_padding_test.rb +0 -83
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/test_controller.rb +0 -7
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/model.rb +0 -3
- data/test/dummy/app/views/layouts/application.html.erb +0 -12
- data/test/dummy/app/views/test/index.html.erb +0 -1
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -59
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -61
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20120908215532_create_models.rb +0 -8
- data/test/dummy/db/schema.rb +0 -22
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -3129
- data/test/dummy/log/test.log +0 -201719
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/cache/assets/CBF/7A0/sprockets%2Fc9192594b6d1b927590d37ebad844808 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D50/930/sprockets%2F277654ad498bbc928b88364ffcbad129 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D9B/E00/sprockets%2Fb66a75bd10bef6da5f16f4fa9113926c +0 -0
- data/test/dummy/tmp/cache/assets/DAC/650/sprockets%2Ff8ec2e25f819797cb9a491d0af22ae9b +0 -0
- data/test/dummy/tmp/cache/assets/DB2/700/sprockets%2Fa4f4b12a5cbea015faede527e4a04307 +0 -0
- data/test/dummy/tmp/cache/assets/DD5/C50/sprockets%2Fcdcdad84697d0b186a1de99f1950e5ab +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DEF/100/sprockets%2F8b9d88bfa8f8eed7910469ef2ab8a8c7 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E29/AA0/sprockets%2F6eaab4ab4dbae1b8b5a6f9286aa966d4 +0 -0
- data/test/helpers_empty_test.rb +0 -42
- data/test/helpers_first_test.rb +0 -43
- data/test/helpers_last_test.rb +0 -43
- data/test/helpers_middle_test.rb +0 -43
- data/test/test_helper.rb +0 -21
@@ -1,81 +0,0 @@
|
|
1
|
-
module RailsPagination
|
2
|
-
module ActiveRecord
|
3
|
-
module Relation
|
4
|
-
|
5
|
-
def per(value)
|
6
|
-
value = [value.to_i, 1].max
|
7
|
-
limit(value).offset(value * (offset_value / limit_value))
|
8
|
-
end
|
9
|
-
|
10
|
-
def pad(value)
|
11
|
-
@padding = value
|
12
|
-
r = (offset_value + value) < 0 ? self : offset(offset_value + value)
|
13
|
-
decrease_limit? ? r.limit(limit_value + value) : r
|
14
|
-
end
|
15
|
-
|
16
|
-
def total_count
|
17
|
-
@total_count ||= begin
|
18
|
-
c = except(:offset, :limit, :order)
|
19
|
-
c = c.except(:includes) unless references_eager_loaded_tables?
|
20
|
-
if c.to_sql =~ /DISTINCT/i
|
21
|
-
c.length
|
22
|
-
else
|
23
|
-
c = c.count
|
24
|
-
c.respond_to?(:count) ? c.count : c
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def total_pages
|
30
|
-
@total_pages ||= [(fixed_total_count.to_f / fixed_limit_value).ceil, 1].max
|
31
|
-
end
|
32
|
-
|
33
|
-
def current_page
|
34
|
-
@current_page ||= (offset_value.to_f / fixed_limit_value).ceil + 1
|
35
|
-
end
|
36
|
-
|
37
|
-
def previous_page
|
38
|
-
@previous_page ||= current_page > 1 ? (current_page - 1) : nil
|
39
|
-
end
|
40
|
-
|
41
|
-
def next_page
|
42
|
-
@next_page ||= current_page < total_pages ? (current_page + 1) : nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def first_page
|
46
|
-
1
|
47
|
-
end
|
48
|
-
|
49
|
-
def last_page
|
50
|
-
total_pages
|
51
|
-
end
|
52
|
-
|
53
|
-
def out_of_bounds?
|
54
|
-
@out_of_bounds ||= current_page > total_pages or current_page < first_page
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
|
59
|
-
def has_padding?
|
60
|
-
not defined?(@padding).nil?
|
61
|
-
end
|
62
|
-
|
63
|
-
def padding_negative?
|
64
|
-
has_padding? and @padding < 0
|
65
|
-
end
|
66
|
-
|
67
|
-
def decrease_limit?
|
68
|
-
padding_negative? and offset_value == 0
|
69
|
-
end
|
70
|
-
|
71
|
-
def fixed_total_count
|
72
|
-
total_count - (padding_negative? ? @padding : 0)
|
73
|
-
end
|
74
|
-
|
75
|
-
def fixed_limit_value
|
76
|
-
limit_value - (decrease_limit? ? @padding : 0)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module RailsPagination
|
2
|
-
class Navigation
|
3
|
-
|
4
|
-
def initialize(collection, length)
|
5
|
-
if collection.total_pages >= length
|
6
|
-
middle = (length / 2).ceil
|
7
|
-
if collection.current_page > collection.total_pages - middle
|
8
|
-
starts_at = collection.total_pages - length + 1
|
9
|
-
ends_at = collection.total_pages
|
10
|
-
elsif collection.current_page <= middle
|
11
|
-
starts_at = 1
|
12
|
-
ends_at = length
|
13
|
-
else
|
14
|
-
starts_at = collection.current_page - middle
|
15
|
-
ends_at = collection.current_page + middle
|
16
|
-
end
|
17
|
-
else
|
18
|
-
starts_at = 1
|
19
|
-
ends_at = collection.total_pages
|
20
|
-
end
|
21
|
-
@has_less_pages = starts_at > 1
|
22
|
-
@has_more_pages = ends_at < collection.total_pages
|
23
|
-
@pages = Range.new(starts_at, ends_at)
|
24
|
-
end
|
25
|
-
|
26
|
-
def has_less_pages?
|
27
|
-
@has_less_pages
|
28
|
-
end
|
29
|
-
|
30
|
-
def has_more_pages?
|
31
|
-
@has_more_pages
|
32
|
-
end
|
33
|
-
|
34
|
-
def pages
|
35
|
-
@pages
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module RailsPagination
|
2
|
-
class Pagination
|
3
|
-
|
4
|
-
def initialize(*args)
|
5
|
-
options = args.extract_options!
|
6
|
-
@request = args[0]
|
7
|
-
@collection = args[1]
|
8
|
-
@parameter = options[:parameter] || Rails.application.config.pagination.default_parameter
|
9
|
-
@navigation = Navigation.new(args[1], options[:navigation] || Rails.application.config.pagination.default_navigation)
|
10
|
-
end
|
11
|
-
|
12
|
-
def has_multiple_pages?
|
13
|
-
@has_multiple_pages ||= @collection.total_pages > 1
|
14
|
-
end
|
15
|
-
|
16
|
-
def is_current_page?(page)
|
17
|
-
@collection.current_page == page
|
18
|
-
end
|
19
|
-
|
20
|
-
def has_previous_page?
|
21
|
-
@has_previous_page ||= @collection.previous_page != nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def has_next_page?
|
25
|
-
@has_next_page ||= @collection.next_page != nil
|
26
|
-
end
|
27
|
-
|
28
|
-
def has_first_page?
|
29
|
-
@collection.current_page > 1 and @collection.total_pages > 1
|
30
|
-
end
|
31
|
-
|
32
|
-
def is_first_page?
|
33
|
-
@is_first_page ||= @collection.current_page == 1
|
34
|
-
end
|
35
|
-
|
36
|
-
def has_last_page?
|
37
|
-
@collection.current_page != @collection.last_page and @collection.total_pages > 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def is_last_page?
|
41
|
-
@is_last_page ||= @collection.current_page == total_pages
|
42
|
-
end
|
43
|
-
|
44
|
-
def navigation
|
45
|
-
@navigation
|
46
|
-
end
|
47
|
-
|
48
|
-
def page_path(page)
|
49
|
-
@request.path + '?' + @request.query_parameters.merge(@parameter => page).to_query
|
50
|
-
end
|
51
|
-
|
52
|
-
def page_url(page)
|
53
|
-
@request.protocol + @request.host_with_port + page_path(page)
|
54
|
-
end
|
55
|
-
|
56
|
-
def current_page_path
|
57
|
-
page_path @collection.current_page
|
58
|
-
end
|
59
|
-
|
60
|
-
def current_page_url
|
61
|
-
page_url @collection.current_page
|
62
|
-
end
|
63
|
-
|
64
|
-
def first_page_path
|
65
|
-
page_path @collection.first_page
|
66
|
-
end
|
67
|
-
|
68
|
-
def first_page_url
|
69
|
-
page_url @collection.first_page
|
70
|
-
end
|
71
|
-
|
72
|
-
def previous_page_path
|
73
|
-
page_path @collection.previous_page
|
74
|
-
end
|
75
|
-
|
76
|
-
def previous_page_url
|
77
|
-
page_url @collection.previous_page
|
78
|
-
end
|
79
|
-
|
80
|
-
def next_page_path
|
81
|
-
page_path @collection.next_page
|
82
|
-
end
|
83
|
-
|
84
|
-
def next_page_url
|
85
|
-
page_url @collection.next_page
|
86
|
-
end
|
87
|
-
|
88
|
-
def last_page_path
|
89
|
-
page_path @collection.last_page
|
90
|
-
end
|
91
|
-
|
92
|
-
def last_page_url
|
93
|
-
page_url @collection.last_page
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module RailsPagination
|
2
|
-
class Railtie < Rails::Railtie
|
3
|
-
|
4
|
-
config.pagination = ActiveSupport::OrderedOptions.new
|
5
|
-
config.pagination.default_per_page = 30
|
6
|
-
config.pagination.default_parameter = :p
|
7
|
-
config.pagination.default_navigation = 5
|
8
|
-
|
9
|
-
initializer 'rails_pagination' do
|
10
|
-
::ActiveRecord::Base.send :extend, RailsPagination::ActiveRecord::Base
|
11
|
-
::ActionView::Base.send :include, RailsPagination::ActionView::Base
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CollectionEmptyTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@collection = Model.page(1).per(2)
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should have 1 page" do
|
10
|
-
assert_equal @collection.total_pages, 1
|
11
|
-
end
|
12
|
-
|
13
|
-
test "current page should be 1" do
|
14
|
-
assert_equal @collection.current_page, 1
|
15
|
-
end
|
16
|
-
|
17
|
-
test "first page should be 1" do
|
18
|
-
assert_equal @collection.first_page, 1
|
19
|
-
end
|
20
|
-
|
21
|
-
test "should have no previous page" do
|
22
|
-
assert_nil @collection.previous_page
|
23
|
-
end
|
24
|
-
|
25
|
-
test "should have no next page" do
|
26
|
-
assert_nil @collection.next_page
|
27
|
-
end
|
28
|
-
|
29
|
-
test "last page should be 1" do
|
30
|
-
assert_equal @collection.last_page, 1
|
31
|
-
end
|
32
|
-
|
33
|
-
test "should not be out of bounds" do
|
34
|
-
assert !@collection.out_of_bounds?
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CollectionFirstTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
-
@collection = Model.page(1).per(2)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should have 5 pages" do
|
11
|
-
assert_equal @collection.total_pages, 5
|
12
|
-
end
|
13
|
-
|
14
|
-
test "current page should be 1" do
|
15
|
-
assert_equal @collection.current_page, 1
|
16
|
-
end
|
17
|
-
|
18
|
-
test "first page should be 1" do
|
19
|
-
assert_equal @collection.first_page, 1
|
20
|
-
end
|
21
|
-
|
22
|
-
test "should have no previous page" do
|
23
|
-
assert_nil @collection.previous_page
|
24
|
-
end
|
25
|
-
|
26
|
-
test "next page should be 2" do
|
27
|
-
assert_equal @collection.next_page, 2
|
28
|
-
end
|
29
|
-
|
30
|
-
test "last page shuold be 5" do
|
31
|
-
assert_equal @collection.last_page, 5
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should not be out of bounds" do
|
35
|
-
assert !@collection.out_of_bounds?
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CollectionLastTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
-
@collection = Model.page(5).per(2)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should have 5 pages" do
|
11
|
-
assert_equal @collection.total_pages, 5
|
12
|
-
end
|
13
|
-
|
14
|
-
test "current page should be 5" do
|
15
|
-
assert_equal @collection.current_page, 5
|
16
|
-
end
|
17
|
-
|
18
|
-
test "first page should be 1" do
|
19
|
-
assert_equal @collection.first_page, 1
|
20
|
-
end
|
21
|
-
|
22
|
-
test "should have previous page 4" do
|
23
|
-
assert_equal @collection.previous_page, 4
|
24
|
-
end
|
25
|
-
|
26
|
-
test "should not have next page" do
|
27
|
-
assert_nil @collection.next_page
|
28
|
-
end
|
29
|
-
|
30
|
-
test "last page shuold be 5" do
|
31
|
-
assert_equal @collection.last_page, 5
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should not be out of bounds" do
|
35
|
-
assert !@collection.out_of_bounds?
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CollectionMiddleTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
-
@collection = Model.page(3).per(2)
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should have 5 pages" do
|
11
|
-
assert_equal @collection.total_pages, 5
|
12
|
-
end
|
13
|
-
|
14
|
-
test "current page should be 3" do
|
15
|
-
assert_equal @collection.current_page, 3
|
16
|
-
end
|
17
|
-
|
18
|
-
test "first page should be 1" do
|
19
|
-
assert_equal @collection.first_page, 1
|
20
|
-
end
|
21
|
-
|
22
|
-
test "should have previous page 2" do
|
23
|
-
assert_equal @collection.previous_page, 2
|
24
|
-
end
|
25
|
-
|
26
|
-
test "should have next page 4" do
|
27
|
-
assert_equal @collection.next_page, 4
|
28
|
-
end
|
29
|
-
|
30
|
-
test "last page shuold be 5" do
|
31
|
-
assert_equal @collection.last_page, 5
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should not be out of bounds" do
|
35
|
-
assert !@collection.out_of_bounds?
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CollectionPaddingTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test "negative padding should have 1 page" do
|
6
|
-
11.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
-
|
8
|
-
@collection = Model.page(1).per(15).pad(-4)
|
9
|
-
assert_equal @collection.total_pages, 1
|
10
|
-
|
11
|
-
@collection = Model.page(2).per(15).pad(-4)
|
12
|
-
assert_equal @collection.total_pages, 1
|
13
|
-
|
14
|
-
@collection = Model.page(3).per(15).pad(-4)
|
15
|
-
assert_equal @collection.total_pages, 1
|
16
|
-
end
|
17
|
-
|
18
|
-
test "negative padding should have 2 pages" do
|
19
|
-
12.times.each { |id| Model.create title: "Record #{id}" }
|
20
|
-
|
21
|
-
@collection = Model.page(1).per(15).pad(-4)
|
22
|
-
assert_equal @collection.total_pages, 2
|
23
|
-
|
24
|
-
@collection = Model.page(2).per(15).pad(-4)
|
25
|
-
assert_equal @collection.total_pages, 2
|
26
|
-
|
27
|
-
@collection = Model.page(3).per(15).pad(-4)
|
28
|
-
assert_equal @collection.total_pages, 2
|
29
|
-
end
|
30
|
-
|
31
|
-
test "negative padding should have 3 pages" do
|
32
|
-
27.times.each { |id| Model.create title: "Record #{id}" }
|
33
|
-
|
34
|
-
@collection = Model.page(1).per(15).pad(-4)
|
35
|
-
assert_equal @collection.total_pages, 3
|
36
|
-
|
37
|
-
@collection = Model.page(2).per(15).pad(-4)
|
38
|
-
assert_equal @collection.total_pages, 3
|
39
|
-
|
40
|
-
@collection = Model.page(3).per(15).pad(-4)
|
41
|
-
assert_equal @collection.total_pages, 3
|
42
|
-
end
|
43
|
-
|
44
|
-
test "positive padding should have 1 page" do
|
45
|
-
15.times.each { |id| Model.create title: "Record #{id}" }
|
46
|
-
|
47
|
-
@collection = Model.page(1).per(15).pad(4)
|
48
|
-
assert_equal @collection.total_pages, 1
|
49
|
-
|
50
|
-
@collection = Model.page(2).per(15).pad(4)
|
51
|
-
assert_equal @collection.total_pages, 1
|
52
|
-
|
53
|
-
@collection = Model.page(3).per(15).pad(4)
|
54
|
-
assert_equal @collection.total_pages, 1
|
55
|
-
end
|
56
|
-
|
57
|
-
test "positive padding should have 2 pages" do
|
58
|
-
16.times.each { |id| Model.create title: "Record #{id}" }
|
59
|
-
|
60
|
-
@collection = Model.page(1).per(15).pad(4)
|
61
|
-
assert_equal @collection.total_pages, 2
|
62
|
-
|
63
|
-
@collection = Model.page(2).per(15).pad(4)
|
64
|
-
assert_equal @collection.total_pages, 2
|
65
|
-
|
66
|
-
@collection = Model.page(3).per(15).pad(4)
|
67
|
-
assert_equal @collection.total_pages, 2
|
68
|
-
end
|
69
|
-
|
70
|
-
test "positive padding should have 3 pages" do
|
71
|
-
31.times.each { |id| Model.create title: "Record #{id}" }
|
72
|
-
|
73
|
-
@collection = Model.page(1).per(15).pad(4)
|
74
|
-
assert_equal @collection.total_pages, 3
|
75
|
-
|
76
|
-
@collection = Model.page(2).per(15).pad(4)
|
77
|
-
assert_equal @collection.total_pages, 3
|
78
|
-
|
79
|
-
@collection = Model.page(3).per(15).pad(4)
|
80
|
-
assert_equal @collection.total_pages, 3
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|