rails_pagination 2.0.6 → 2.0.7
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.
- data/README.rdoc +8 -24
- data/Rakefile +2 -0
- data/app/views/rails_pagination/_pager.html.erb +23 -0
- data/config/locales/en.yml +6 -0
- data/config/locales/es.yml +6 -0
- data/lib/rails_pagination/action_view/base.rb +5 -1
- data/lib/rails_pagination/engine.rb +7 -0
- data/lib/rails_pagination/{pager.rb → pagination.rb} +4 -4
- data/lib/rails_pagination/version.rb +1 -1
- data/lib/rails_pagination.rb +2 -1
- data/test/collection_empty_test.rb +3 -7
- data/test/collection_first_test.rb +4 -8
- data/test/collection_last_test.rb +4 -8
- data/test/collection_middle_test.rb +4 -8
- data/test/collection_padding_test.rb +6 -6
- data/test/dummy/app/views/layouts/application.html.erb +3 -5
- data/test/dummy/app/views/test/index.html.erb +1 -30
- data/test/dummy/log/development.log +906 -0
- data/test/dummy/log/test.log +17021 -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/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/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 +3 -7
- data/test/helpers_first_test.rb +4 -8
- data/test/helpers_last_test.rb +4 -8
- data/test/helpers_middle_test.rb +4 -8
- metadata +15 -5
- data/test/rails_pagination_test.rb +0 -9
data/README.rdoc
CHANGED
@@ -16,35 +16,19 @@ Then bundle:
|
|
16
16
|
|
17
17
|
The same approach as kaminari:
|
18
18
|
Model.page(1).per(20)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
%a.first{:href => pager.first_page_path}= t('pager.first')
|
26
|
-
- if pager.has_previous_page?
|
27
|
-
%a.previous{:href => pager.previous_page_path}= t('pager.previous')
|
28
|
-
- if pager.navigation.has_less_pages?
|
29
|
-
%span.ellipsis ...
|
30
|
-
- for page in pager.navigation.pages
|
31
|
-
- if pager.is_current_page? page
|
32
|
-
%span.page.current= page
|
33
|
-
- else
|
34
|
-
%a.page{:href => pager.page_path(page)}= page
|
35
|
-
- if pager.navigation.has_more_pages?
|
36
|
-
%span.ellipsis ...
|
37
|
-
- if pager.has_next_page?
|
38
|
-
%a.next{:href => pager.next_page_path}= t('pager.next')
|
39
|
-
- if pager.has_last_page?
|
40
|
-
%a.last{:href => pager.last_page_path}= t('pager.last')
|
19
|
+
|
20
|
+
You can use the default html with this helper:
|
21
|
+
pager @collection
|
22
|
+
|
23
|
+
Or you can make your own just paginating the collection:
|
24
|
+
paginate @collection # Loot at app/views/rails_pagination/_pager.html.erb
|
41
25
|
|
42
26
|
= Configuration
|
43
27
|
|
44
28
|
== Default param name
|
45
29
|
|
46
|
-
If you want to change the default parameter name or the default navigation length call paginate
|
47
|
-
|
30
|
+
If you want to change the default parameter name or the default navigation length call pager/paginate this way:
|
31
|
+
pager @collection, navigation: 3, parameter: :p
|
48
32
|
Or to set it globally put this in your application.rb:
|
49
33
|
config.pagination.default_parameter = :p
|
50
34
|
config.pagination.default_navigation = 5
|
data/Rakefile
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
<% if pagination.has_multiple_pages? %>
|
2
|
+
<div class="pager">
|
3
|
+
<% if pagination.has_first_page? %>
|
4
|
+
<%= link_to t('pager.first'), pagination.first_page_path, class: 'first' %>
|
5
|
+
<% end %>
|
6
|
+
<% if pagination.has_previous_page? %>
|
7
|
+
<%= link_to t('pager.previous'), pagination.previous_page_path, class: 'previous' %>
|
8
|
+
<% end %>
|
9
|
+
<% pagination.navigation.pages.each do |page| %>
|
10
|
+
<% if pagination.is_current_page? page %>
|
11
|
+
<span class="page current"><%= page %></span>
|
12
|
+
<% else %>
|
13
|
+
<%= link_to page, pagination.page_path(page), class: 'page' %>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
<% if pagination.has_next_page? %>
|
17
|
+
<%= link_to t('pager.next'), pagination.next_page_path, class: 'next' %>
|
18
|
+
<% end %>
|
19
|
+
<% if pagination.has_last_page? %>
|
20
|
+
<%= link_to t('pager.last'), pagination.last_page_path, class: 'last' %>
|
21
|
+
<% end %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
@@ -3,7 +3,11 @@ module RailsPagination
|
|
3
3
|
module Base
|
4
4
|
|
5
5
|
def paginate(*args)
|
6
|
-
|
6
|
+
Pagination.new *args.unshift(request)
|
7
|
+
end
|
8
|
+
|
9
|
+
def pager(*args)
|
10
|
+
render partial: 'rails_pagination/pager', locals: { pagination: paginate(*args) }
|
7
11
|
end
|
8
12
|
|
9
13
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RailsPagination
|
2
|
-
class
|
2
|
+
class Pagination
|
3
3
|
|
4
4
|
def initialize(*args)
|
5
5
|
options = args.extract_options!
|
6
|
-
@
|
6
|
+
@request = args[0]
|
7
7
|
@collection = args[1]
|
8
8
|
@parameter = options[:parameter] || Rails.application.config.pagination.default_parameter
|
9
9
|
@navigation = Navigation.new(args[1], options[:navigation] || Rails.application.config.pagination.default_navigation)
|
@@ -46,11 +46,11 @@ module RailsPagination
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def page_path(page)
|
49
|
-
@
|
49
|
+
@request.path + '?' + @request.query_parameters.merge(@parameter => page).to_query
|
50
50
|
end
|
51
51
|
|
52
52
|
def page_url(page)
|
53
|
-
@
|
53
|
+
@request.protocol + @request.host_with_port + page_path(page)
|
54
54
|
end
|
55
55
|
|
56
56
|
def current_page_path
|
data/lib/rails_pagination.rb
CHANGED
@@ -2,7 +2,8 @@ require 'rails_pagination/action_view/base'
|
|
2
2
|
require 'rails_pagination/active_record/base'
|
3
3
|
require 'rails_pagination/active_record/relation'
|
4
4
|
require 'rails_pagination/navigation'
|
5
|
-
require 'rails_pagination/
|
5
|
+
require 'rails_pagination/pagination'
|
6
|
+
require 'rails_pagination/engine'
|
6
7
|
require 'rails_pagination/railtie'
|
7
8
|
require 'rails_pagination/version'
|
8
9
|
|
@@ -2,7 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CollectionEmptyTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup
|
5
|
+
setup do
|
6
|
+
@collection = Model.page(1).per(2)
|
7
|
+
end
|
6
8
|
|
7
9
|
test "should have 1 page" do
|
8
10
|
assert_equal @collection.total_pages, 1
|
@@ -32,10 +34,4 @@ class CollectionEmptyTest < ActiveSupport::TestCase
|
|
32
34
|
assert !@collection.out_of_bounds?
|
33
35
|
end
|
34
36
|
|
35
|
-
protected
|
36
|
-
|
37
|
-
def create_records
|
38
|
-
@collection = Model.page(1).per(2)
|
39
|
-
end
|
40
|
-
|
41
37
|
end
|
@@ -2,7 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CollectionFirstTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup
|
5
|
+
setup do
|
6
|
+
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
+
@collection = Model.page(1).per(2)
|
8
|
+
end
|
6
9
|
|
7
10
|
test "should have 5 pages" do
|
8
11
|
assert_equal @collection.total_pages, 5
|
@@ -32,11 +35,4 @@ class CollectionFirstTest < ActiveSupport::TestCase
|
|
32
35
|
assert !@collection.out_of_bounds?
|
33
36
|
end
|
34
37
|
|
35
|
-
protected
|
36
|
-
|
37
|
-
def create_records
|
38
|
-
10.times.each { |id| Model.create :title => "Record #{id}" }
|
39
|
-
@collection = Model.page(1).per(2)
|
40
|
-
end
|
41
|
-
|
42
38
|
end
|
@@ -2,7 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CollectionLastTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup
|
5
|
+
setup do
|
6
|
+
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
+
@collection = Model.page(5).per(2)
|
8
|
+
end
|
6
9
|
|
7
10
|
test "should have 5 pages" do
|
8
11
|
assert_equal @collection.total_pages, 5
|
@@ -32,11 +35,4 @@ class CollectionLastTest < ActiveSupport::TestCase
|
|
32
35
|
assert !@collection.out_of_bounds?
|
33
36
|
end
|
34
37
|
|
35
|
-
protected
|
36
|
-
|
37
|
-
def create_records
|
38
|
-
10.times.each { |id| Model.create :title => "Record #{id}" }
|
39
|
-
@collection = Model.page(5).per(2)
|
40
|
-
end
|
41
|
-
|
42
38
|
end
|
@@ -2,7 +2,10 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class CollectionMiddleTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
setup
|
5
|
+
setup do
|
6
|
+
10.times.each { |id| Model.create title: "Record #{id}" }
|
7
|
+
@collection = Model.page(3).per(2)
|
8
|
+
end
|
6
9
|
|
7
10
|
test "should have 5 pages" do
|
8
11
|
assert_equal @collection.total_pages, 5
|
@@ -32,11 +35,4 @@ class CollectionMiddleTest < ActiveSupport::TestCase
|
|
32
35
|
assert !@collection.out_of_bounds?
|
33
36
|
end
|
34
37
|
|
35
|
-
protected
|
36
|
-
|
37
|
-
def create_records
|
38
|
-
10.times.each { |id| Model.create :title => "Record #{id}" }
|
39
|
-
@collection = Model.page(3).per(2)
|
40
|
-
end
|
41
|
-
|
42
38
|
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
class CollectionPaddingTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
test "negative padding should have 1 page" do
|
6
|
-
11.times.each { |id| Model.create :
|
6
|
+
11.times.each { |id| Model.create title: "Record #{id}" }
|
7
7
|
|
8
8
|
@collection = Model.page(1).per(15).pad(-4)
|
9
9
|
assert_equal @collection.total_pages, 1
|
@@ -16,7 +16,7 @@ class CollectionPaddingTest < ActiveSupport::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
test "negative padding should have 2 pages" do
|
19
|
-
12.times.each { |id| Model.create :
|
19
|
+
12.times.each { |id| Model.create title: "Record #{id}" }
|
20
20
|
|
21
21
|
@collection = Model.page(1).per(15).pad(-4)
|
22
22
|
assert_equal @collection.total_pages, 2
|
@@ -29,7 +29,7 @@ class CollectionPaddingTest < ActiveSupport::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
test "negative padding should have 3 pages" do
|
32
|
-
27.times.each { |id| Model.create :
|
32
|
+
27.times.each { |id| Model.create title: "Record #{id}" }
|
33
33
|
|
34
34
|
@collection = Model.page(1).per(15).pad(-4)
|
35
35
|
assert_equal @collection.total_pages, 3
|
@@ -42,7 +42,7 @@ class CollectionPaddingTest < ActiveSupport::TestCase
|
|
42
42
|
end
|
43
43
|
|
44
44
|
test "positive padding should have 1 page" do
|
45
|
-
15.times.each { |id| Model.create :
|
45
|
+
15.times.each { |id| Model.create title: "Record #{id}" }
|
46
46
|
|
47
47
|
@collection = Model.page(1).per(15).pad(4)
|
48
48
|
assert_equal @collection.total_pages, 1
|
@@ -55,7 +55,7 @@ class CollectionPaddingTest < ActiveSupport::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
test "positive padding should have 2 pages" do
|
58
|
-
16.times.each { |id| Model.create :
|
58
|
+
16.times.each { |id| Model.create title: "Record #{id}" }
|
59
59
|
|
60
60
|
@collection = Model.page(1).per(15).pad(4)
|
61
61
|
assert_equal @collection.total_pages, 2
|
@@ -68,7 +68,7 @@ class CollectionPaddingTest < ActiveSupport::TestCase
|
|
68
68
|
end
|
69
69
|
|
70
70
|
test "positive padding should have 3 pages" do
|
71
|
-
31.times.each { |id| Model.create :
|
71
|
+
31.times.each { |id| Model.create title: "Record #{id}" }
|
72
72
|
|
73
73
|
@collection = Model.page(1).per(15).pad(4)
|
74
74
|
assert_equal @collection.total_pages, 3
|
@@ -2,13 +2,11 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag
|
6
|
-
<%= javascript_include_tag
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
6
|
+
<%= javascript_include_tag 'application' %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
</head>
|
9
9
|
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
10
|
+
<%= yield %>
|
13
11
|
</body>
|
14
12
|
</html>
|
@@ -1,30 +1 @@
|
|
1
|
-
|
2
|
-
<% if pager.has_multiple_pages? %>
|
3
|
-
<div id="pager">
|
4
|
-
<% if pager.has_first_page? %>
|
5
|
-
<a class="first" href="<%= pager.first_page_path %>"><%= t('pager.first') %></a>
|
6
|
-
<% end %>
|
7
|
-
<% if pager.has_previous_page? %>
|
8
|
-
<a class="previous" href="<%= pager.previous_page_path %>"><%= t('pager.previous') %></a>
|
9
|
-
<% end %>
|
10
|
-
<% if pager.navigation.has_less_pages? %>
|
11
|
-
<span class="ellipsis">...</span>
|
12
|
-
<% end %>
|
13
|
-
<% for page in pager.navigation.pages %>
|
14
|
-
<% if pager.is_current_page? page %>
|
15
|
-
<span class="page current"><%= page %></span>
|
16
|
-
<% else %>
|
17
|
-
<a class="page" href="<%= pager.page_path(page) %>"><%= page %></a>
|
18
|
-
<% end %>
|
19
|
-
<% end %>
|
20
|
-
<% if pager.navigation.has_more_pages? %>
|
21
|
-
<span class="ellipsis">...</span>
|
22
|
-
<% end %>
|
23
|
-
<% if pager.has_next_page? %>
|
24
|
-
<a class="next" href="<%= pager.next_page_path %>"><%= t('pager.next') %></a>
|
25
|
-
<% end %>
|
26
|
-
<% if pager.has_last_page? %>
|
27
|
-
<a class="last" href="<%= pager.last_page_path %>"><%= t('pager.last') %></a>
|
28
|
-
<% end %>
|
29
|
-
</div>
|
30
|
-
<% end %>
|
1
|
+
<%= pager @collection %>
|