kaminari 0.14.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kaminari might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.document +1 -4
- data/.gitignore +1 -0
- data/.travis.yml +52 -5
- data/{CHANGELOG → CHANGELOG.rdoc} +129 -0
- data/Gemfile +1 -1
- data/README.rdoc +66 -25
- data/Rakefile +32 -9
- data/app/views/kaminari/_first_page.html.erb +1 -1
- data/app/views/kaminari/_first_page.html.haml +1 -1
- data/app/views/kaminari/_first_page.html.slim +1 -1
- data/app/views/kaminari/_gap.html.erb +1 -1
- data/app/views/kaminari/_gap.html.haml +1 -1
- data/app/views/kaminari/_gap.html.slim +1 -1
- data/app/views/kaminari/_last_page.html.erb +1 -1
- data/app/views/kaminari/_last_page.html.haml +1 -1
- data/app/views/kaminari/_last_page.html.slim +1 -1
- data/app/views/kaminari/_next_page.html.erb +1 -1
- data/app/views/kaminari/_next_page.html.haml +1 -1
- data/app/views/kaminari/_next_page.html.slim +1 -1
- data/app/views/kaminari/_prev_page.html.erb +1 -1
- data/app/views/kaminari/_prev_page.html.haml +1 -1
- data/app/views/kaminari/_prev_page.html.slim +1 -1
- data/gemfiles/active_record_30.gemfile +25 -4
- data/gemfiles/active_record_31.gemfile +23 -4
- data/gemfiles/active_record_32.gemfile +22 -4
- data/gemfiles/active_record_40.gemfile +26 -0
- data/gemfiles/active_record_41.gemfile +25 -0
- data/gemfiles/active_record_42.gemfile +25 -0
- data/gemfiles/active_record_edge.gemfile +30 -0
- data/gemfiles/data_mapper_12.gemfile +30 -10
- data/gemfiles/mongo_mapper.gemfile +20 -2
- data/gemfiles/mongoid_30.gemfile +18 -3
- data/gemfiles/mongoid_31.gemfile +21 -0
- data/gemfiles/mongoid_40.gemfile +19 -0
- data/gemfiles/mongoid_50.gemfile +23 -0
- data/gemfiles/sinatra_13.gemfile +36 -0
- data/gemfiles/sinatra_14.gemfile +33 -0
- data/kaminari.gemspec +13 -14
- data/lib/generators/kaminari/views_generator.rb +9 -8
- data/lib/kaminari/config.rb +2 -0
- data/lib/kaminari/helpers/action_view_extension.rb +9 -28
- data/lib/kaminari/helpers/paginator.rb +38 -18
- data/lib/kaminari/helpers/sinatra_helpers.rb +41 -3
- data/lib/kaminari/helpers/tags.rb +18 -5
- data/lib/kaminari/hooks.rb +31 -15
- data/lib/kaminari/models/active_record_extension.rb +8 -8
- data/lib/kaminari/models/active_record_model_extension.rb +8 -6
- data/lib/kaminari/models/active_record_relation_methods.rb +21 -10
- data/lib/kaminari/models/array_extension.rb +17 -11
- data/lib/kaminari/models/configuration_methods.rb +16 -2
- data/lib/kaminari/models/data_mapper_collection_methods.rb +4 -0
- data/lib/kaminari/models/data_mapper_extension.rb +5 -2
- data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -1
- data/lib/kaminari/models/mongoid_extension.rb +8 -15
- data/lib/kaminari/models/page_scope_methods.rb +37 -5
- data/lib/kaminari/models/plucky_criteria_methods.rb +6 -1
- data/lib/kaminari/railtie.rb +1 -1
- data/lib/kaminari/sinatra.rb +2 -0
- data/lib/kaminari/version.rb +1 -1
- data/lib/kaminari.rb +5 -4
- data/spec/config/config_spec.rb +15 -0
- data/spec/fake_app/active_record/config.rb +1 -1
- data/spec/fake_app/active_record/models.rb +9 -1
- data/spec/fake_app/mongo_mapper/config.rb +1 -1
- data/spec/fake_app/mongoid/config.rb +7 -3
- data/spec/fake_app/mongoid/models.rb +16 -0
- data/spec/fake_app/rails_app.rb +1 -0
- data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +1 -0
- data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +3 -0
- data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +1 -0
- data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +7 -0
- data/spec/fake_gem.rb +18 -2
- data/spec/generators/views_generator_spec.rb +18 -0
- data/spec/helpers/action_view_extension_spec.rb +68 -12
- data/spec/helpers/helpers_spec.rb +9 -0
- data/spec/helpers/sinatra_helpers_spec.rb +53 -0
- data/spec/models/active_record/active_record_relation_methods_spec.rb +48 -1
- data/spec/models/active_record/inherited_spec.rb +9 -0
- data/spec/models/active_record/scopes_spec.rb +104 -5
- data/spec/models/array_spec.rb +55 -4
- data/spec/models/configuration_methods_spec.rb +125 -0
- data/spec/models/data_mapper/data_mapper_spec.rb +76 -26
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +12 -0
- data/spec/models/mongoid/mongoid_spec.rb +119 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_for_sinatra.rb +2 -3
- data/spec/support/database_cleaner.rb +5 -2
- metadata +63 -87
- data/gemfiles/mongoid_24.gemfile +0 -7
- data/gemfiles/sinatra.gemfile +0 -10
- data/spec/models/active_record/default_per_page_spec.rb +0 -32
- data/spec/models/active_record/max_per_page_spec.rb +0 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f6f180b0164209c6b789f3ae855089840a905fd
|
4
|
+
data.tar.gz: 2bbc06afb48a4e28ca76f7c960b359eb440f4dc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3e4ac52fe8981e2610495da987398d455e25984d27a558f98175b512f22a938c58798225be16d526f38c6d19f9a1e1274612d6cf9e68e11f06bd4f4b8b0838a
|
7
|
+
data.tar.gz: 4f162bbb0935a179d6586316e9d3cf476ce1db7d15a61698c83313edf8c367b0df9ac14b99148e2153102f807f54d55fc1fe29894168417371b1954bf035ad63
|
data/.document
CHANGED
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,17 +1,64 @@
|
|
1
|
-
|
1
|
+
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
4
|
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.10
|
7
|
+
- 2.2.5
|
8
|
+
- 2.3.1
|
9
|
+
- jruby-1.7.25
|
10
|
+
- jruby-9.1.0.0
|
11
|
+
- rbx-2
|
6
12
|
|
7
13
|
gemfile:
|
14
|
+
- gemfiles/active_record_30.gemfile
|
15
|
+
- gemfiles/active_record_31.gemfile
|
8
16
|
- gemfiles/active_record_32.gemfile
|
17
|
+
- gemfiles/active_record_40.gemfile
|
18
|
+
- gemfiles/active_record_41.gemfile
|
19
|
+
- gemfiles/active_record_42.gemfile
|
20
|
+
- gemfiles/active_record_edge.gemfile
|
9
21
|
- gemfiles/data_mapper_12.gemfile
|
10
22
|
- gemfiles/mongo_mapper.gemfile
|
11
23
|
- gemfiles/mongoid_30.gemfile
|
12
|
-
- gemfiles/
|
24
|
+
- gemfiles/mongoid_31.gemfile
|
25
|
+
- gemfiles/mongoid_40.gemfile
|
26
|
+
- gemfiles/mongoid_50.gemfile
|
27
|
+
- gemfiles/sinatra_13.gemfile
|
28
|
+
- gemfiles/sinatra_14.gemfile
|
29
|
+
|
30
|
+
sudo: false
|
31
|
+
|
32
|
+
services: mongodb
|
33
|
+
|
34
|
+
script: "bundle exec rake spec"
|
35
|
+
|
36
|
+
cache: bundler
|
13
37
|
|
14
38
|
matrix:
|
15
39
|
exclude:
|
16
|
-
- rvm: 1.
|
17
|
-
gemfile: gemfiles/
|
40
|
+
- rvm: 1.9.3
|
41
|
+
gemfile: gemfiles/active_record_edge.gemfile
|
42
|
+
- rvm: 2.0.0
|
43
|
+
gemfile: gemfiles/active_record_edge.gemfile
|
44
|
+
- rvm: 2.1.10
|
45
|
+
gemfile: gemfiles/active_record_edge.gemfile
|
46
|
+
- rvm: 2.2.5
|
47
|
+
gemfile: gemfiles/active_record_30.gemfile
|
48
|
+
- rvm: 2.2.5
|
49
|
+
gemfile: gemfiles/active_record_31.gemfile
|
50
|
+
- rvm: 2.2.5
|
51
|
+
gemfile: gemfiles/active_record_32.gemfile
|
52
|
+
- rvm: 2.3.1
|
53
|
+
gemfile: gemfiles/active_record_30.gemfile
|
54
|
+
- rvm: 2.3.1
|
55
|
+
gemfile: gemfiles/active_record_31.gemfile
|
56
|
+
- rvm: 2.3.1
|
57
|
+
gemfile: gemfiles/active_record_32.gemfile
|
58
|
+
- rvm: jruby-1.7.25
|
59
|
+
gemfile: gemfiles/active_record_edge.gemfile
|
60
|
+
allow_failures:
|
61
|
+
- rvm: jruby-1.7.25
|
62
|
+
- rvm: jruby-9.1.0.0
|
63
|
+
- rvm: rbx-2
|
64
|
+
fast_finish: true
|
@@ -1,3 +1,132 @@
|
|
1
|
+
== 0.17.0
|
2
|
+
|
3
|
+
* Rails 5 ready!
|
4
|
+
|
5
|
+
* Mongoid 5.0 support
|
6
|
+
|
7
|
+
* Dropped Ruby 1.8 support
|
8
|
+
|
9
|
+
* Dropped Mongoid 2.x support
|
10
|
+
|
11
|
+
* Extracted Sinatra support to kaminari-sinatra gem
|
12
|
+
|
13
|
+
* Extracted DataMapper support to kaminari-data_mapper gem
|
14
|
+
|
15
|
+
* Extracted Mongoid support to kaminari-mongoid gem
|
16
|
+
|
17
|
+
* Extracted MongoMapper support to kaminari-mongo_mapper gem
|
18
|
+
|
19
|
+
* Deprecated Kaminari::PageScopeMethods#num_pages in favor of `total_pages`
|
20
|
+
|
21
|
+
* Deprecated :num_pages option for `paginate` in favor of :total_pages
|
22
|
+
|
23
|
+
* Fixed mangled params in pagination links on Rails 5 #766 [audionerd]
|
24
|
+
|
25
|
+
* Fixed a bug where the range of the records displayed on the last page
|
26
|
+
doesn't match #718 [danzanzini]
|
27
|
+
|
28
|
+
== 0.16.3
|
29
|
+
|
30
|
+
* Fixed a "stack level too deep" bug in mongoid #642 [bartes]
|
31
|
+
|
32
|
+
* Fixed a bug that Kaminari possibly crashes when combined with other gems
|
33
|
+
that define `inherited` method on model classes, such as aasm. #651 [zeitnot]
|
34
|
+
|
35
|
+
== 0.16.2
|
36
|
+
|
37
|
+
* Fixed a bug where cloned Relations remember previous relations'
|
38
|
+
@total_count value #565 [inkstak]
|
39
|
+
|
40
|
+
* Fixed a bug where `paginate_array()` with total_count option returns whole
|
41
|
+
array for every page #516 [abhichvn]
|
42
|
+
|
43
|
+
* Fixed a bug where :num_pages option was backwards-incompatible #605
|
44
|
+
[klebershimabuku]
|
45
|
+
|
46
|
+
* Fixed a bug where themed views generator attempts to overwrite README.md
|
47
|
+
#623 [swrobel]
|
48
|
+
|
49
|
+
* Fixed a bug that ruby raises a NameError when theme was not found #622
|
50
|
+
[maxprokopiev]
|
51
|
+
|
52
|
+
* Fixed a bug that paginates_per does not work with subclasses on mongoid #634
|
53
|
+
[kouyaf77]
|
54
|
+
|
55
|
+
* Show an error message if a proper template was not found for the generator
|
56
|
+
theme #600 [meltedice]
|
57
|
+
|
58
|
+
== 0.16.1
|
59
|
+
|
60
|
+
* Fix a bug where :theme option for #paginate method doesn't work properly
|
61
|
+
#566 [commstratdev]
|
62
|
+
|
63
|
+
== 0.16.0
|
64
|
+
|
65
|
+
* Add support for mongoid max_scan option #500 [aptx4869]
|
66
|
+
|
67
|
+
* Add `link_to_previous_page` helper for Sinatra #504 [ikeay]
|
68
|
+
|
69
|
+
* Add :views_prefix option to #paginate for alternative views directory #552
|
70
|
+
[apotonick]
|
71
|
+
|
72
|
+
* Simplify `page_entries_info` by adding entry_name interface to each ORM
|
73
|
+
|
74
|
+
* Refer ActiveRecord::Base from top level namespace for more safety when
|
75
|
+
inherited class's namespace has 'ActiveRecord' constant #522 [yuroyoro]
|
76
|
+
|
77
|
+
* Fix a bug where runtime persistence not taken into account with
|
78
|
+
mongoid/kaminari #326 [nubeod]
|
79
|
+
|
80
|
+
* Fix a bug where helper methods were not available from inside
|
81
|
+
`paginator.render do ... end` block #239 [damien-roche]
|
82
|
+
|
83
|
+
* Fix a bug where theme generator didn't work on Rails 4.1 #526 [jimryan]
|
84
|
+
|
85
|
+
* Fix a bug that paginatable arrays with `total_count` option always returns
|
86
|
+
whole array #516 [abhichvn]
|
87
|
+
|
88
|
+
== 0.15.1
|
89
|
+
|
90
|
+
* page_method_name option was not working in 0.15.0 #481 [mauriciopasquier]
|
91
|
+
|
92
|
+
* Use the mongoid criteria #length method to cache the count of the collection
|
93
|
+
per criteria #484 [camallen]
|
94
|
+
|
95
|
+
* Don't inherit host, port, and protocol from the given params
|
96
|
+
|
97
|
+
== 0.15.0
|
98
|
+
|
99
|
+
* Allow count, total count to pass parameters to super #193 [bsimpson]
|
100
|
+
|
101
|
+
* Add `max_pages` and `max_pages_per` methods to limit displayed pages per
|
102
|
+
model or globally #301 [zpieslak]
|
103
|
+
|
104
|
+
* Add support for Sinatra views overrides (add app views paths) #332 [j15e]
|
105
|
+
|
106
|
+
* Fix wrong pagination when used with `padding` #359 [vladimir-vg, negipo]
|
107
|
+
|
108
|
+
* check for Hash in addition to OrderedHash, which seems to break in Rails 4,
|
109
|
+
for total_count #369 [aew]
|
110
|
+
|
111
|
+
* Make `to_s` in paginator threadsafe #374 [bf4]
|
112
|
+
|
113
|
+
* Fix Missing partial Error when 'paginate' called from different format
|
114
|
+
template #381 [joker1007]
|
115
|
+
|
116
|
+
* Add `PageScopeMethods#next_page`, `prev_page`, and `out_of_range?` [yuki24]
|
117
|
+
|
118
|
+
* Use html_safe in view partials instead of raw fixed #73 [zzak]
|
119
|
+
|
120
|
+
* Fix a bug that `PaginatableArray#total_pages` returns the wrong value #416 [yuki24]
|
121
|
+
|
122
|
+
* Make `num_pages` to return the same value as `total_pages` for backward compat [yuki24, eitoball]
|
123
|
+
|
124
|
+
* Change #page_entries_info to use model name #340, #348 [znz, eitoball]
|
125
|
+
|
126
|
+
* Change scope to class method #433 [kolodovskyy]
|
127
|
+
|
128
|
+
* Fix arity problem with Rails 4.1.0 #449 [bricker]
|
129
|
+
|
1
130
|
== 0.14.1
|
2
131
|
|
3
132
|
* Changed the default "truncation" String from "..." to … #264 [pjaspers]
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Kaminari
|
1
|
+
= Kaminari {<img src="https://travis-ci.org/amatsuda/kaminari.svg"/>}[http://travis-ci.org/amatsuda/kaminari] {<img src="https://img.shields.io/codeclimate/github/amatsuda/kaminari.svg" />}[https://codeclimate.com/github/amatsuda/kaminari] {<img src="http://inch-ci.org/github/amatsuda/kaminari.svg" alt="Inline docs" />}[http://inch-ci.org/github/amatsuda/kaminari]
|
2
2
|
|
3
3
|
A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for modern web app frameworks and ORMs
|
4
4
|
|
@@ -19,7 +19,7 @@ No special collection class or anything for the paginated values, instead using
|
|
19
19
|
As the whole pagination helper is basically just a collection of links and non-links, Kaminari renders each of them through its own partial template inside the Engine. So, you can easily modify their behaviour, style or whatever by overriding partial templates.
|
20
20
|
|
21
21
|
=== ORM & template engine agnostic
|
22
|
-
Kaminari supports multiple ORMs (ActiveRecord, Mongoid, MongoMapper) multiple web frameworks (Rails, Sinatra), and multiple template engines (ERB, Haml).
|
22
|
+
Kaminari supports multiple ORMs (ActiveRecord, DataMapper, Mongoid, MongoMapper) multiple web frameworks (Rails, Sinatra, Grape), and multiple template engines (ERB, Haml, Slim).
|
23
23
|
|
24
24
|
=== Modern
|
25
25
|
The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
|
@@ -27,9 +27,9 @@ The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper s
|
|
27
27
|
|
28
28
|
== Supported versions
|
29
29
|
|
30
|
-
* Ruby 1.
|
30
|
+
* Ruby 1.9.2, 1.9.3, 2.0.0, 2.1.x, 2.2.x
|
31
31
|
|
32
|
-
* Rails 3.0
|
32
|
+
* Rails 3.0, 3.1, 3.2, 4.0, 4.1, 4.2
|
33
33
|
|
34
34
|
* Haml 3+
|
35
35
|
|
@@ -63,9 +63,14 @@ Then bundle:
|
|
63
63
|
User.page(7).per(50)
|
64
64
|
Note that the +per+ scope is not directly defined on the models but is just a method defined on the page scope. This is absolutely reasonable because you will never actually use +per_page+ without specifying the +page+ number.
|
65
65
|
|
66
|
+
Keep in mind that +per+ utilizes internally +limit+ and so it will override any +limit+ that was set previously
|
67
|
+
User.count # => 1000
|
68
|
+
a = User.limit(5).count # => 5
|
69
|
+
b = a.page(1).per(20).size # => 20
|
70
|
+
|
66
71
|
* the +padding+ scope
|
67
72
|
|
68
|
-
Occasionally you need to
|
73
|
+
Occasionally you need to pad a number of records that is not a multiple of the page size.
|
69
74
|
User.page(7).per(50).padding(3)
|
70
75
|
Note that the +padding+ scope also is not directly defined on the models.
|
71
76
|
|
@@ -74,6 +79,7 @@ Then bundle:
|
|
74
79
|
You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
|
75
80
|
default_per_page # 25 by default
|
76
81
|
max_per_page # nil by default
|
82
|
+
max_pages # nil by default
|
77
83
|
window # 4 by default
|
78
84
|
outer_window # 0 by default
|
79
85
|
left # 0 by default
|
@@ -87,7 +93,7 @@ Run the following generator command, then edit the generated file.
|
|
87
93
|
|
88
94
|
* changing +page_method_name+
|
89
95
|
|
90
|
-
You can change the method name
|
96
|
+
You can change the method name +page+ to +bonzo+ or +plant+ or whatever you like, in order to play nice with existing +page+ method or association or scope or any other plugin that defines +page+ method on your models.
|
91
97
|
|
92
98
|
|
93
99
|
=== Configuring default +per_page+ value for each model
|
@@ -104,7 +110,7 @@ Run the following generator command, then edit the generated file.
|
|
104
110
|
* +max_paginates_per+
|
105
111
|
|
106
112
|
You can specify max +per_page+ value per each model using the following declarative DSL.
|
107
|
-
If the variable that specified via +per+ scope is more than this variable,
|
113
|
+
If the variable that specified via +per+ scope is more than this variable, +max_paginates_per+ is used instead of it. Default value is nil, which means you are not imposing any max +per_page+ value.
|
108
114
|
class User < ActiveRecord::Base
|
109
115
|
max_paginates_per 100
|
110
116
|
end
|
@@ -132,17 +138,17 @@ Run the following generator command, then edit the generated file.
|
|
132
138
|
<%= paginate @users %>
|
133
139
|
This would output several pagination links such as <tt>« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »</tt>
|
134
140
|
|
135
|
-
*
|
141
|
+
* specifying the "inner window" size (4 by default)
|
136
142
|
|
137
143
|
<%= paginate @users, :window => 2 %>
|
138
144
|
This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
|
139
145
|
|
140
|
-
*
|
146
|
+
* specifying the "outer window" size (0 by default)
|
141
147
|
|
142
148
|
<%= paginate @users, :outer_window => 3 %>
|
143
149
|
This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
|
144
150
|
|
145
|
-
* outer window can be
|
151
|
+
* outer window can be separately specified by +left+, +right+ (0 by default)
|
146
152
|
|
147
153
|
<%= paginate @users, :left => 1, :right => 3 %>
|
148
154
|
This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
|
@@ -162,10 +168,15 @@ Run the following generator command, then edit the generated file.
|
|
162
168
|
<%= paginate @users, :remote => true %>
|
163
169
|
This would add <tt>data-remote="true"</tt> to all the links inside.
|
164
170
|
|
171
|
+
* specifying an alternative views directory (default is <tt>kaminari/</tt>)
|
172
|
+
|
173
|
+
<%= paginate @users, :views_prefix => 'templates/' %>
|
174
|
+
This would search for partials in <tt>app/views/templates/kaminari</tt>. This option makes it easier to do things like A/B testing pagination templates/themes, using new/old templates at the same time as well as better intergration with other gems sush as {cells}[https://github.com/apotonick/cells].
|
175
|
+
|
165
176
|
* the +link_to_next_page+ and +link_to_previous_page+ helper method
|
166
177
|
|
167
178
|
<%= link_to_next_page @items, 'Next Page' %>
|
168
|
-
This simply renders a link to the next page. This would be helpful for creating
|
179
|
+
This simply renders a link to the next page. This would be helpful for creating a Twitter-like pagination feature.
|
169
180
|
|
170
181
|
* the +page_entries_info+ helper method
|
171
182
|
|
@@ -184,7 +195,16 @@ Keys and the default values are the following. You can override them by adding t
|
|
184
195
|
last: "Last »"
|
185
196
|
previous: "‹ Prev"
|
186
197
|
next: "Next ›"
|
187
|
-
truncate: "
|
198
|
+
truncate: "…"
|
199
|
+
helpers:
|
200
|
+
page_entries_info:
|
201
|
+
one_page:
|
202
|
+
display_entries:
|
203
|
+
zero: "No %{entry_name} found"
|
204
|
+
one: "Displaying <b>1</b> %{entry_name}"
|
205
|
+
other: "Displaying <b>all %{count}</b> %{entry_name}"
|
206
|
+
more_pages:
|
207
|
+
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
188
208
|
|
189
209
|
=== Customizing the pagination helper
|
190
210
|
|
@@ -206,7 +226,7 @@ Kaminari includes a handy template generator.
|
|
206
226
|
* themes
|
207
227
|
|
208
228
|
The generator has the ability to fetch several sample template themes from
|
209
|
-
the external repository (https://github.com/amatsuda/kaminari_themes) in
|
229
|
+
the external repository (https://github.com/amatsuda/kaminari_themes) in
|
210
230
|
addition to the bundled "default" one, which will help you creating a nice
|
211
231
|
looking paginator.
|
212
232
|
% rails g kaminari:views THEME
|
@@ -223,7 +243,7 @@ Kaminari includes a handy template generator.
|
|
223
243
|
% mkdir my_custom_theme
|
224
244
|
% cp _*.html.* my_custom_theme/
|
225
245
|
|
226
|
-
Next reference that directory when calling the paginate method:
|
246
|
+
Next, reference that directory when calling the +paginate+ method:
|
227
247
|
|
228
248
|
<%= paginate @users, :theme => 'my_custom_theme' %>
|
229
249
|
|
@@ -236,24 +256,26 @@ Kaminari includes a handy template generator.
|
|
236
256
|
Kaminari provides an Array wrapper class that adapts a generic Array object to the <tt>paginate</tt> view helper.
|
237
257
|
However, the <tt>paginate</tt> helper doesn't automatically handle your Array object (this is intentional and by design).
|
238
258
|
<tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
|
239
|
-
Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
|
240
259
|
|
241
|
-
|
242
|
-
|
260
|
+
@paginatable_array = Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
|
261
|
+
|
262
|
+
You can specify the +total_count+ value through options Hash. This would be helpful when handling an Array-ish object that has a different +count+ value from actual +count+ such as RSolr search result or when you need to generate a custom pagination. For example:
|
263
|
+
|
264
|
+
@paginatable_array = Kaminari.paginate_array([], total_count: 145).page(params[:page]).per(10)
|
243
265
|
|
244
266
|
== Creating friendly URLs and caching
|
245
267
|
|
246
|
-
Because of the
|
268
|
+
Because of the +page+ parameter and Rails 3 routing, you can easily generate SEO and user-friendly URLs. For any resource you'd like to paginate, just add the following to your +routes.rb+:
|
247
269
|
|
248
270
|
resources :my_resources do
|
249
271
|
get 'page/:page', :action => :index, :on => :collection
|
250
272
|
end
|
251
273
|
|
252
|
-
This will create URLs like
|
274
|
+
This will create URLs like <tt>/my_resources/page/33</tt> instead of <tt>/my_resources?page=33</tt>. This is now a friendly URL, but it also has other added benefits...
|
253
275
|
|
254
|
-
Because the
|
276
|
+
Because the +page+ parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!
|
255
277
|
|
256
|
-
NOTE: In this example, I've pointed the route to my
|
278
|
+
NOTE: In this example, I've pointed the route to my <tt>:index</tt> action. You may have defined a custom pagination action in your controller - you should point <tt>:action => :your_custom_action</tt> instead.
|
257
279
|
|
258
280
|
|
259
281
|
== Sinatra/Padrino support
|
@@ -268,6 +290,12 @@ or edit gemfile:
|
|
268
290
|
|
269
291
|
gem 'kaminari', :require => 'kaminari/sinatra'
|
270
292
|
|
293
|
+
This line just enables model-side features, such as <tt>Model#page</tt> and <tt>Model#per</tt>. If you want to use view helpers, please explicitly <tt>register</tt> helpers in your Sinatra or Padrino app:
|
294
|
+
|
295
|
+
register Kaminari::Helpers::SinatraHelpers
|
296
|
+
|
297
|
+
Or, you can implement your own awesome helper :)
|
298
|
+
|
271
299
|
More features are coming, and again, this is still experimental. Please let us know if you found anything wrong with the Sinatra support.
|
272
300
|
|
273
301
|
|
@@ -277,9 +305,6 @@ Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniq
|
|
277
305
|
https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
|
278
306
|
|
279
307
|
|
280
|
-
== Build Status {<img src="https://secure.travis-ci.org/amatsuda/kaminari.png"/>}[http://travis-ci.org/amatsuda/kaminari]
|
281
|
-
|
282
|
-
|
283
308
|
== Questions, Feedback
|
284
309
|
|
285
310
|
Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
|
@@ -287,7 +312,23 @@ Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇
|
|
287
312
|
|
288
313
|
== Contributing to Kaminari
|
289
314
|
|
290
|
-
|
315
|
+
Fork, fix, then send a pull request.
|
316
|
+
|
317
|
+
To run the test suite locally against all supported frameworks:
|
318
|
+
|
319
|
+
% bundle install
|
320
|
+
% rake spec:all
|
321
|
+
|
322
|
+
To target the test suite against one framework:
|
323
|
+
|
324
|
+
% rake spec:active_record_40
|
325
|
+
|
326
|
+
You can find a list of supported spec tasks by running <tt>rake -T</tt>. You may also find it useful to run a specific test
|
327
|
+
for a specific framework. To do so, you'll have to first make sure you have bundled everything for that configuration,
|
328
|
+
then you can run the specific test:
|
329
|
+
|
330
|
+
% BUNDLE_GEMFILE='gemfiles/active_record_40.gemfile' bundle install
|
331
|
+
% BUNDLE_GEMFILE='gemfiles/active_record_40.gemfile' bundle exec rspec ./spec/requests/users_spec.rb
|
291
332
|
|
292
333
|
|
293
334
|
== Copyright
|
data/Rakefile
CHANGED
@@ -13,7 +13,26 @@ end
|
|
13
13
|
task :default => "spec:all"
|
14
14
|
|
15
15
|
namespace :spec do
|
16
|
-
%w(
|
16
|
+
mappers = %w(
|
17
|
+
active_record_edge
|
18
|
+
active_record_42
|
19
|
+
active_record_41
|
20
|
+
active_record_40
|
21
|
+
active_record_32
|
22
|
+
active_record_31
|
23
|
+
active_record_30
|
24
|
+
data_mapper_12
|
25
|
+
mongoid_50
|
26
|
+
mongoid_40
|
27
|
+
mongoid_31
|
28
|
+
mongoid_30
|
29
|
+
mongoid_24
|
30
|
+
mongo_mapper
|
31
|
+
sinatra_13
|
32
|
+
sinatra_14
|
33
|
+
)
|
34
|
+
|
35
|
+
mappers.each do |gemfile|
|
17
36
|
desc "Run Tests against #{gemfile}"
|
18
37
|
task gemfile do
|
19
38
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
@@ -23,20 +42,24 @@ namespace :spec do
|
|
23
42
|
|
24
43
|
desc "Run Tests against all ORMs"
|
25
44
|
task :all do
|
26
|
-
|
45
|
+
mappers.each do |gemfile|
|
27
46
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
28
47
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
|
29
48
|
end
|
30
49
|
end
|
31
50
|
end
|
32
51
|
|
33
|
-
|
52
|
+
begin
|
53
|
+
require 'rdoc/task'
|
34
54
|
|
35
|
-
Rake::RDocTask.new do |rdoc|
|
36
|
-
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
require 'kaminari/version'
|
37
57
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "kaminari #{Kaminari::VERSION}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
63
|
+
rescue LoadError
|
64
|
+
puts 'RDocTask is not supported on this VM and platform combination.'
|
42
65
|
end
|
@@ -7,5 +7,5 @@
|
|
7
7
|
remote: data-remote
|
8
8
|
-%>
|
9
9
|
<span class="first">
|
10
|
-
<%= link_to_unless current_page.first?,
|
10
|
+
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote %>
|
11
11
|
</span>
|
@@ -6,4 +6,4 @@
|
|
6
6
|
-# per_page: number of items to fetch per page
|
7
7
|
-# remote: data-remote
|
8
8
|
%span.first
|
9
|
-
= link_to_unless current_page.first?,
|
9
|
+
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
|
@@ -6,5 +6,5 @@
|
|
6
6
|
per_page : number of items to fetch per page
|
7
7
|
remote : data-remote
|
8
8
|
span.first
|
9
|
-
== link_to_unless current_page.first?,
|
9
|
+
== link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
|
10
10
|
'
|
@@ -6,4 +6,4 @@
|
|
6
6
|
-# per_page: number of items to fetch per page
|
7
7
|
-# remote: data-remote
|
8
8
|
%span.last
|
9
|
-
= link_to_unless current_page.last?,
|
9
|
+
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
|
@@ -6,5 +6,5 @@
|
|
6
6
|
per_page : number of items to fetch per page
|
7
7
|
remote : data-remote
|
8
8
|
span.last
|
9
|
-
== link_to_unless current_page.last?,
|
9
|
+
== link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
|
10
10
|
'
|
@@ -7,5 +7,5 @@
|
|
7
7
|
remote: data-remote
|
8
8
|
-%>
|
9
9
|
<span class="next">
|
10
|
-
<%= link_to_unless current_page.last?,
|
10
|
+
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote %>
|
11
11
|
</span>
|
@@ -6,4 +6,4 @@
|
|
6
6
|
-# per_page: number of items to fetch per page
|
7
7
|
-# remote: data-remote
|
8
8
|
%span.next
|
9
|
-
= link_to_unless current_page.last?,
|
9
|
+
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
|
@@ -6,5 +6,5 @@
|
|
6
6
|
per_page : number of items to fetch per page
|
7
7
|
remote : data-remote
|
8
8
|
span.next
|
9
|
-
== link_to_unless current_page.last?,
|
9
|
+
== link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote
|
10
10
|
'
|
@@ -7,5 +7,5 @@
|
|
7
7
|
remote: data-remote
|
8
8
|
-%>
|
9
9
|
<span class="prev">
|
10
|
-
<%= link_to_unless current_page.first?,
|
10
|
+
<%= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote %>
|
11
11
|
</span>
|
@@ -6,4 +6,4 @@
|
|
6
6
|
-# per_page: number of items to fetch per page
|
7
7
|
-# remote: data-remote
|
8
8
|
%span.prev
|
9
|
-
= link_to_unless current_page.first?,
|
9
|
+
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
|
@@ -6,5 +6,5 @@
|
|
6
6
|
per_page : number of items to fetch per page
|
7
7
|
remote : data-remote
|
8
8
|
span.prev
|
9
|
-
== link_to_unless current_page.first?,
|
9
|
+
== link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, :rel => 'prev', :remote => remote
|
10
10
|
'
|