zhanghd_kaminari 0.10.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/CHANGELOG +159 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +141 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +177 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/app/views/kaminari/_current_page.html.erb +9 -0
- data/app/views/kaminari/_current_page.html.haml +9 -0
- data/app/views/kaminari/_first_page_link.html.erb +12 -0
- data/app/views/kaminari/_first_page_link.html.haml +10 -0
- data/app/views/kaminari/_last_page_link.html.erb +12 -0
- data/app/views/kaminari/_last_page_link.html.haml +10 -0
- data/app/views/kaminari/_next_link.html.erb +11 -0
- data/app/views/kaminari/_next_link.html.haml +9 -0
- data/app/views/kaminari/_next_span.html.erb +8 -0
- data/app/views/kaminari/_next_span.html.haml +7 -0
- data/app/views/kaminari/_page_link.html.erb +12 -0
- data/app/views/kaminari/_page_link.html.haml +10 -0
- data/app/views/kaminari/_paginator.html.erb +29 -0
- data/app/views/kaminari/_paginator.html.haml +23 -0
- data/app/views/kaminari/_prev_link.html.erb +11 -0
- data/app/views/kaminari/_prev_link.html.haml +9 -0
- data/app/views/kaminari/_prev_span.html.erb +8 -0
- data/app/views/kaminari/_prev_span.html.haml +7 -0
- data/app/views/kaminari/_truncated_span.html.erb +8 -0
- data/app/views/kaminari/_truncated_span.html.haml +8 -0
- data/config/locales/kaminari.yml +8 -0
- data/kaminari.gemspec +152 -0
- data/lib/generators/kaminari/views_generator.rb +99 -0
- data/lib/kaminari.rb +2 -0
- data/lib/kaminari/engine.rb +4 -0
- data/lib/kaminari/helpers/action_view_extension.rb +25 -0
- data/lib/kaminari/helpers/helpers.rb +75 -0
- data/lib/kaminari/helpers/tags.rb +263 -0
- data/lib/kaminari/models/active_record_extension.rb +32 -0
- data/lib/kaminari/models/active_record_relation_methods.rb +12 -0
- data/lib/kaminari/models/array_paginate_extension.rb +17 -0
- data/lib/kaminari/models/configuration_methods.rb +20 -0
- data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -0
- data/lib/kaminari/models/mongoid_extension.rb +30 -0
- data/lib/kaminari/models/page_scope_methods.rb +26 -0
- data/lib/kaminari/railtie.rb +34 -0
- data/spec/acceptance/acceptance_helper.rb +5 -0
- data/spec/acceptance/support/helpers.rb +5 -0
- data/spec/acceptance/support/paths.rb +9 -0
- data/spec/acceptance/users_spec.rb +44 -0
- data/spec/fake_app.rb +48 -0
- data/spec/helpers/helpers_spec.rb +126 -0
- data/spec/helpers/tags_spec.rb +158 -0
- data/spec/models/default_per_page_spec.rb +29 -0
- data/spec/models/mongoid_spec.rb +72 -0
- data/spec/models/scopes_spec.rb +109 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/matchers.rb +46 -0
- metadata +344 -0
data/.document
ADDED
data/.gemtest
ADDED
File without changes
|
data/.rspec
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
== 0.10.4
|
2
|
+
|
3
|
+
* Do not break ActiveRecord::Base.descendants, by making sure to call super
|
4
|
+
from ActiveRecord::Base.inherited #34 [rolftimmermans]
|
5
|
+
|
6
|
+
* Fixed vanishing mongoid criteria after calling page() #26 [tyok]
|
7
|
+
|
8
|
+
== 0.10.3
|
9
|
+
|
10
|
+
* Fixed a bug that total_count() didn't work when chained with group() scope
|
11
|
+
#21 [jgeiger]
|
12
|
+
|
13
|
+
* Fixed a bug that the paginate helper didn't work properly with an Ajax call
|
14
|
+
#23 [hjuskewycz]
|
15
|
+
|
16
|
+
== 0.10.2
|
17
|
+
|
18
|
+
* Added :param_name option to the pagination helper #10 [ivanvr]
|
19
|
+
Example:
|
20
|
+
= paginate @users, :param_name => :pagina
|
21
|
+
|
22
|
+
== 0.10.1
|
23
|
+
|
24
|
+
* Fixed a bug that the whole <nav> section was not rendered in some cases
|
25
|
+
[GarthSnyder]
|
26
|
+
|
27
|
+
== 0.10.0
|
28
|
+
|
29
|
+
* Railtie initializer name is "kaminari" from now
|
30
|
+
* Changed bundler settings to work both on 1.9.2 and 1.8.7 #12 [l15n]
|
31
|
+
* Fixed bugs encountered when running specs on Ruby 1.9.2 #12 [l15n]
|
32
|
+
* Clean up documentation (formatting and editing) #12 [l15n]
|
33
|
+
* Use Proc.new instead of lambda for scoped_options #13 [l15n]
|
34
|
+
* Use AS hooks for loading AR #14 [hasimo]
|
35
|
+
* Refactor scope definition with Concerns #15 [l15n]
|
36
|
+
* Ensure output_buffer is always initialized #11 [kichiro]
|
37
|
+
|
38
|
+
== 0.9.13
|
39
|
+
|
40
|
+
* Added Mongoid support #5 [juno, hibariya]
|
41
|
+
This means, Kaminari is now *ORM agnostic* ☇3☇3☇3
|
42
|
+
|
43
|
+
== 0.9.12
|
44
|
+
|
45
|
+
* Moved the whole pagination logic to the paginator partial so that users can
|
46
|
+
touch it
|
47
|
+
Note: You need to update your _paginator.html.* if you've already customized
|
48
|
+
it. If you haven't overridden _paginator.html.* files, then probably
|
49
|
+
there're nothing you have to do.
|
50
|
+
See this commit for the example:
|
51
|
+
https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
|
52
|
+
|
53
|
+
== 0.9.10
|
54
|
+
|
55
|
+
* the per() method accepts String, zero and minus value now #7 [koic]
|
56
|
+
This enables you to do something like this:
|
57
|
+
Model.page(params[:page]).per(params[:per])
|
58
|
+
|
59
|
+
* Added support for Gem Testers (http://gem-testers.org/) #8 [joealba]
|
60
|
+
|
61
|
+
== 0.9.9
|
62
|
+
|
63
|
+
* :params option for the helper [yomukaku_memo]
|
64
|
+
You can override each link's url_for option by this option
|
65
|
+
Example:
|
66
|
+
= paginate @users, :params => {:controller => 'users', :action => 'index2'}
|
67
|
+
|
68
|
+
* refactor tags
|
69
|
+
|
70
|
+
== 0.9.8
|
71
|
+
|
72
|
+
* I18n for the partials
|
73
|
+
[:previous, :next, :truncate] are externalized to the I18n resource.
|
74
|
+
|
75
|
+
== 0.9.7
|
76
|
+
|
77
|
+
* moved template themes to another repo
|
78
|
+
https://github.com/amatsuda/kaminari_themes
|
79
|
+
|
80
|
+
== 0.9.6
|
81
|
+
|
82
|
+
* added paginates_per method for setting default per_page value for each model
|
83
|
+
in a declarative way
|
84
|
+
Example:
|
85
|
+
class Article < ActiveRecord::Base
|
86
|
+
paginates_per 10
|
87
|
+
end
|
88
|
+
|
89
|
+
== 0.9.5
|
90
|
+
|
91
|
+
* works on AR 3.0.0 and 3.0.1 now #4 [danillos]
|
92
|
+
|
93
|
+
== 0.9.4
|
94
|
+
|
95
|
+
* introduced module based tags
|
96
|
+
As a side effect of this internal change, I have to confess that this
|
97
|
+
version brings you a slight backward incompatibility on template API.
|
98
|
+
If you're using custom templates, be sure to update your existing templates.
|
99
|
+
To catch up the new API, you need to update %w[next_url prev_url page_url]
|
100
|
+
local variables to simple 'url' like this.
|
101
|
+
https://github.com/amatsuda/kaminari/commit/da88729
|
102
|
+
|
103
|
+
== 0.9.3
|
104
|
+
|
105
|
+
* improved template detection logic
|
106
|
+
When a template for a tag could not be found in the app/views/kaminari/
|
107
|
+
directory, it searches the tag's ancestor template files before falling back
|
108
|
+
to engine's default template. This may help keeping your custom templates DRY.
|
109
|
+
|
110
|
+
* simplified bundled template themes
|
111
|
+
|
112
|
+
== 0.9.2
|
113
|
+
|
114
|
+
* stop adding extra LF between templates when joining
|
115
|
+
|
116
|
+
* githubish template theme [maztomo]
|
117
|
+
|
118
|
+
== 0.9.1
|
119
|
+
|
120
|
+
* googlish template theme [maztomo]
|
121
|
+
|
122
|
+
== 0.9.0
|
123
|
+
|
124
|
+
* added "per_page" to the template local variables #3 [hsbt]
|
125
|
+
|
126
|
+
* show no contents when the current page is the only page (in other words,
|
127
|
+
num_pages == 1) #2 [hsbt]
|
128
|
+
|
129
|
+
== 0.8.0
|
130
|
+
|
131
|
+
* using HTML5 <nav> tag rather than <div> for the container tag
|
132
|
+
|
133
|
+
== 0.7.0
|
134
|
+
|
135
|
+
* Ajaxified paginator templates
|
136
|
+
|
137
|
+
== 0.6.0
|
138
|
+
|
139
|
+
* Hamlized paginator templates
|
140
|
+
|
141
|
+
== 0.5.0
|
142
|
+
|
143
|
+
* reset content_for :kaminari_paginator_tags before rendering #1 [hsbt]
|
144
|
+
|
145
|
+
== 0.4.0
|
146
|
+
|
147
|
+
* partialize the outer div
|
148
|
+
|
149
|
+
== 0.3.0
|
150
|
+
|
151
|
+
* suppress logging when rendering each partial
|
152
|
+
|
153
|
+
== 0.2.0
|
154
|
+
|
155
|
+
* default PER_PAGE to 25 [hsbt]
|
156
|
+
|
157
|
+
== 0.1.0
|
158
|
+
|
159
|
+
* First release
|
data/Gemfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem 'rspec', '>= 2.5.0'
|
10
|
+
gem 'rr', '>= 1.0.2'
|
11
|
+
gem 'steak', '>= 1.1.0'
|
12
|
+
gem 'capybara', '>= 0.4.1.1'
|
13
|
+
gem 'bundler', '>= 1.0.0'
|
14
|
+
gem 'jeweler', '>= 1.5.2'
|
15
|
+
gem 'rcov', '>= 0'
|
16
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
17
|
+
gem 'rails', '>= 3.0.3'
|
18
|
+
# gem 'rack', :git => 'git://github.com/rack/rack.git'
|
19
|
+
# gem 'arel', :git => 'git://github.com/rails/arel.git'
|
20
|
+
gem 'rspec-rails', '>= 2.5.0'
|
21
|
+
gem 'sqlite3', '>= 1.3.3'
|
22
|
+
gem 'mongoid', '2.0.0.rc.7'
|
23
|
+
gem 'bson_ext', '~> 1.2'
|
24
|
+
# platforms :mri_18 do
|
25
|
+
# gem 'ruby-debug'
|
26
|
+
# end
|
27
|
+
# platforms :mri_19 do
|
28
|
+
# gem 'ruby-debug19'
|
29
|
+
# end
|
30
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.5)
|
6
|
+
actionpack (= 3.0.5)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.5)
|
9
|
+
activemodel (= 3.0.5)
|
10
|
+
activesupport (= 3.0.5)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.5)
|
19
|
+
activesupport (= 3.0.5)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.5)
|
23
|
+
activemodel (= 3.0.5)
|
24
|
+
activesupport (= 3.0.5)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.5)
|
28
|
+
activemodel (= 3.0.5)
|
29
|
+
activesupport (= 3.0.5)
|
30
|
+
activesupport (3.0.5)
|
31
|
+
arel (2.0.9)
|
32
|
+
bson (1.2.4)
|
33
|
+
bson_ext (1.2.4)
|
34
|
+
builder (2.1.2)
|
35
|
+
capybara (0.4.1.2)
|
36
|
+
celerity (>= 0.7.9)
|
37
|
+
culerity (>= 0.2.4)
|
38
|
+
mime-types (>= 1.16)
|
39
|
+
nokogiri (>= 1.3.3)
|
40
|
+
rack (>= 1.0.0)
|
41
|
+
rack-test (>= 0.5.4)
|
42
|
+
selenium-webdriver (>= 0.0.27)
|
43
|
+
xpath (~> 0.1.3)
|
44
|
+
celerity (0.8.8)
|
45
|
+
childprocess (0.1.7)
|
46
|
+
ffi (~> 0.6.3)
|
47
|
+
culerity (0.2.15)
|
48
|
+
diff-lcs (1.1.2)
|
49
|
+
erubis (2.6.6)
|
50
|
+
abstract (>= 1.0.0)
|
51
|
+
ffi (0.6.3)
|
52
|
+
rake (>= 0.8.7)
|
53
|
+
git (1.2.5)
|
54
|
+
i18n (0.5.0)
|
55
|
+
jeweler (1.5.2)
|
56
|
+
bundler (~> 1.0.0)
|
57
|
+
git (>= 1.2.5)
|
58
|
+
rake
|
59
|
+
json_pure (1.5.1)
|
60
|
+
mail (2.2.15)
|
61
|
+
activesupport (>= 2.3.6)
|
62
|
+
i18n (>= 0.4.0)
|
63
|
+
mime-types (~> 1.16)
|
64
|
+
treetop (~> 1.4.8)
|
65
|
+
mime-types (1.16)
|
66
|
+
mongo (1.2.4)
|
67
|
+
bson (>= 1.2.4)
|
68
|
+
mongoid (2.0.0.rc.7)
|
69
|
+
activemodel (~> 3.0)
|
70
|
+
mongo (~> 1.2)
|
71
|
+
tzinfo (~> 0.3.22)
|
72
|
+
will_paginate (~> 3.0.pre)
|
73
|
+
nokogiri (1.4.4)
|
74
|
+
polyglot (0.3.1)
|
75
|
+
rack (1.2.1)
|
76
|
+
rack-mount (0.6.13)
|
77
|
+
rack (>= 1.0.0)
|
78
|
+
rack-test (0.5.7)
|
79
|
+
rack (>= 1.0)
|
80
|
+
rails (3.0.5)
|
81
|
+
actionmailer (= 3.0.5)
|
82
|
+
actionpack (= 3.0.5)
|
83
|
+
activerecord (= 3.0.5)
|
84
|
+
activeresource (= 3.0.5)
|
85
|
+
activesupport (= 3.0.5)
|
86
|
+
bundler (~> 1.0)
|
87
|
+
railties (= 3.0.5)
|
88
|
+
railties (3.0.5)
|
89
|
+
actionpack (= 3.0.5)
|
90
|
+
activesupport (= 3.0.5)
|
91
|
+
rake (>= 0.8.7)
|
92
|
+
thor (~> 0.14.4)
|
93
|
+
rake (0.8.7)
|
94
|
+
rcov (0.9.9)
|
95
|
+
rr (1.0.2)
|
96
|
+
rspec (2.5.0)
|
97
|
+
rspec-core (~> 2.5.0)
|
98
|
+
rspec-expectations (~> 2.5.0)
|
99
|
+
rspec-mocks (~> 2.5.0)
|
100
|
+
rspec-core (2.5.1)
|
101
|
+
rspec-expectations (2.5.0)
|
102
|
+
diff-lcs (~> 1.1.2)
|
103
|
+
rspec-mocks (2.5.0)
|
104
|
+
rspec-rails (2.5.0)
|
105
|
+
actionpack (~> 3.0)
|
106
|
+
activesupport (~> 3.0)
|
107
|
+
railties (~> 3.0)
|
108
|
+
rspec (~> 2.5.0)
|
109
|
+
rubyzip (0.9.4)
|
110
|
+
selenium-webdriver (0.1.3)
|
111
|
+
childprocess (~> 0.1.5)
|
112
|
+
ffi (~> 0.6.3)
|
113
|
+
json_pure
|
114
|
+
rubyzip
|
115
|
+
sqlite3 (1.3.3)
|
116
|
+
steak (1.1.0)
|
117
|
+
rspec (>= 1.3)
|
118
|
+
thor (0.14.6)
|
119
|
+
treetop (1.4.9)
|
120
|
+
polyglot (>= 0.3.1)
|
121
|
+
tzinfo (0.3.24)
|
122
|
+
will_paginate (3.0.pre2)
|
123
|
+
xpath (0.1.3)
|
124
|
+
nokogiri (~> 1.3)
|
125
|
+
|
126
|
+
PLATFORMS
|
127
|
+
ruby
|
128
|
+
|
129
|
+
DEPENDENCIES
|
130
|
+
bson_ext (~> 1.2)
|
131
|
+
bundler (>= 1.0.0)
|
132
|
+
capybara (>= 0.4.1.1)
|
133
|
+
jeweler (>= 1.5.2)
|
134
|
+
mongoid (= 2.0.0.rc.7)
|
135
|
+
rails (>= 3.0.3)
|
136
|
+
rcov
|
137
|
+
rr (>= 1.0.2)
|
138
|
+
rspec (>= 2.5.0)
|
139
|
+
rspec-rails (>= 2.5.0)
|
140
|
+
sqlite3 (>= 1.3.3)
|
141
|
+
steak (>= 1.1.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Akira Matsuda
|
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,177 @@
|
|
1
|
+
= Kaminari
|
2
|
+
|
3
|
+
A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3
|
4
|
+
|
5
|
+
|
6
|
+
== Features
|
7
|
+
|
8
|
+
=== Clean
|
9
|
+
Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
|
10
|
+
|
11
|
+
=== Easy to use
|
12
|
+
Just bundle the gem, then your models are ready to be paginated. No configuration required. Don't have to define anything in your models or helpers.
|
13
|
+
|
14
|
+
=== Simple scope-based API
|
15
|
+
Everything is method chainable with less "Hasheritis". You know, that's the Rails 3 way.
|
16
|
+
No special collection class or anything for the paginated values, instead using a general <tt>AR::Relation</tt> instance. So, of course you can chain any other conditions before or after the paginator scope.
|
17
|
+
|
18
|
+
=== Customizable engine-based I18n-aware helper
|
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
|
+
|
21
|
+
=== ORM & template engine agnostic
|
22
|
+
Kaminari supports multiple ORMs (ActiveRecord, Mongoid) and multiple template engines (ERB, Haml).
|
23
|
+
|
24
|
+
=== Modern
|
25
|
+
The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
|
26
|
+
|
27
|
+
|
28
|
+
== Supported versions
|
29
|
+
|
30
|
+
* Ruby 1.8.7, 1.9.2, 1.9.3 (trunk)
|
31
|
+
|
32
|
+
* Rails 3.0.x, 3.1 (edge)
|
33
|
+
|
34
|
+
* Haml 3
|
35
|
+
|
36
|
+
* Mongoid 2 (beta)
|
37
|
+
|
38
|
+
== Install
|
39
|
+
|
40
|
+
Put this line in your Gemfile:
|
41
|
+
gem 'kaminari'
|
42
|
+
|
43
|
+
Then bundle:
|
44
|
+
% bundle
|
45
|
+
|
46
|
+
== Usage
|
47
|
+
|
48
|
+
=== Query Basics
|
49
|
+
|
50
|
+
* the +page+ scope
|
51
|
+
|
52
|
+
To fetch the 7th page of users (default +per_page+ is 25)
|
53
|
+
User.page(7)
|
54
|
+
|
55
|
+
* the +per+ scope
|
56
|
+
|
57
|
+
To show a lot more users per each page (change the +per_page+ value)
|
58
|
+
User.page(7).per(50)
|
59
|
+
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.
|
60
|
+
|
61
|
+
=== Configuring default +per_page+ value for each model
|
62
|
+
|
63
|
+
* +paginates_per+
|
64
|
+
|
65
|
+
You can specify default +per_page+ value per each model using the following declarative DSL.
|
66
|
+
class User < ActiveRecord::Base
|
67
|
+
paginates_per 50
|
68
|
+
end
|
69
|
+
|
70
|
+
=== Controllers
|
71
|
+
|
72
|
+
* the page parameter is in <tt>params[:page]</tt>
|
73
|
+
|
74
|
+
Typically, your controller code will look like this:
|
75
|
+
@users = User.order(:name).page params[:page]
|
76
|
+
|
77
|
+
=== Views
|
78
|
+
|
79
|
+
* the same old helper method
|
80
|
+
|
81
|
+
Just call the +paginate+ helper:
|
82
|
+
<%= paginate @users %>
|
83
|
+
|
84
|
+
This will render several <tt>?page=N</tt> pagination links surrounded by an HTML5 <+nav+> tag.
|
85
|
+
|
86
|
+
=== Helper Options
|
87
|
+
|
88
|
+
* specifing the "inner window" size (4 by default)
|
89
|
+
|
90
|
+
<%= paginate @users, :window => 2 %>
|
91
|
+
This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
|
92
|
+
|
93
|
+
* specifing the "outer window" size (1 by default)
|
94
|
+
|
95
|
+
<%= paginate @users, :outer_window => 3 %>
|
96
|
+
This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
|
97
|
+
|
98
|
+
* outer window can be separetely specified by +left+, +right+ (1 by default)
|
99
|
+
|
100
|
+
<%= paginate @users, :left => 0, :right => 2 %>
|
101
|
+
This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
|
102
|
+
|
103
|
+
* changing the parameter name (:+param_name+) for the links
|
104
|
+
|
105
|
+
<%= paginate @users, :param_name => :pagina
|
106
|
+
This would modify the query parameter name on each links.
|
107
|
+
|
108
|
+
* extra parameters (:+params+) for the links
|
109
|
+
|
110
|
+
<%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
|
111
|
+
This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
|
112
|
+
|
113
|
+
* Ajax links (crazy simple, but works perfectly!)
|
114
|
+
|
115
|
+
<%= paginate @users, :remote => true %>
|
116
|
+
This would add <tt>data-remote="true"</tt> to all the links inside.
|
117
|
+
|
118
|
+
=== I18n and labels
|
119
|
+
|
120
|
+
The default labels for 'previous', '...' and 'next' are stored in the I18n yaml inside the engine, and rendered through I18n API. You can switch the label value per I18n.locale for your internationalized application.
|
121
|
+
Keys and the default values are the following. You can override them by adding to a YAML file in your <tt>Rails.root/config/locales</tt> directory.
|
122
|
+
|
123
|
+
en:
|
124
|
+
views:
|
125
|
+
pagination:
|
126
|
+
previous: "« Prev"
|
127
|
+
next: "Next »"
|
128
|
+
truncate: "..."
|
129
|
+
|
130
|
+
=== Customizing the pagination helper
|
131
|
+
|
132
|
+
Kaminari includes a handy template generator.
|
133
|
+
|
134
|
+
* to edit your paginator
|
135
|
+
|
136
|
+
Run the generator first,
|
137
|
+
% rails g kaminari:views default
|
138
|
+
|
139
|
+
then edit the partials in your app's <tt>app/views/kaminari/</tt> directory.
|
140
|
+
|
141
|
+
* for Haml users
|
142
|
+
|
143
|
+
Haml templates generator is also available by adding the <tt>-e haml</tt> option (this is automatically invoked when the default template_engine is set to Haml).
|
144
|
+
|
145
|
+
% rails g kaminari:views default -e haml
|
146
|
+
|
147
|
+
* themes
|
148
|
+
|
149
|
+
The generator has the ability to fetch several sample template themes from
|
150
|
+
the external repository (https://github.com/amatsuda/kaminari_themes) in
|
151
|
+
addition to the bundled "default" one, which will help you creating a nice
|
152
|
+
looking paginator.
|
153
|
+
% rails g kaminari:views THEME
|
154
|
+
|
155
|
+
To see the full list of avaliable themes, take a look at the themes repository,
|
156
|
+
or just hit the generator without specifying +THEME+ argument.
|
157
|
+
% rails g kaminari:views
|
158
|
+
|
159
|
+
|
160
|
+
== For more information
|
161
|
+
|
162
|
+
Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques.
|
163
|
+
https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
|
164
|
+
|
165
|
+
== Questions, Feedback
|
166
|
+
|
167
|
+
Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
|
168
|
+
|
169
|
+
|
170
|
+
== Contributing to Kaminari
|
171
|
+
|
172
|
+
* Fork, fix, then send me a pull request.
|
173
|
+
|
174
|
+
|
175
|
+
== Copyright
|
176
|
+
|
177
|
+
Copyright (c) 2011 Akira Matsuda. See LICENSE.txt for further details.
|