kaminari-rails4 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +9 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +16 -0
  7. data/CHANGELOG +351 -0
  8. data/Gemfile +4 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.rdoc +300 -0
  11. data/Rakefile +42 -0
  12. data/app/helpers/kaminari_helper.rb +5 -0
  13. data/app/views/kaminari/_first_page.html.erb +11 -0
  14. data/app/views/kaminari/_first_page.html.haml +9 -0
  15. data/app/views/kaminari/_first_page.html.slim +10 -0
  16. data/app/views/kaminari/_gap.html.erb +8 -0
  17. data/app/views/kaminari/_gap.html.haml +8 -0
  18. data/app/views/kaminari/_gap.html.slim +9 -0
  19. data/app/views/kaminari/_last_page.html.erb +11 -0
  20. data/app/views/kaminari/_last_page.html.haml +9 -0
  21. data/app/views/kaminari/_last_page.html.slim +10 -0
  22. data/app/views/kaminari/_next_page.html.erb +11 -0
  23. data/app/views/kaminari/_next_page.html.haml +9 -0
  24. data/app/views/kaminari/_next_page.html.slim +10 -0
  25. data/app/views/kaminari/_page.html.erb +12 -0
  26. data/app/views/kaminari/_page.html.haml +10 -0
  27. data/app/views/kaminari/_page.html.slim +11 -0
  28. data/app/views/kaminari/_paginator.html.erb +23 -0
  29. data/app/views/kaminari/_paginator.html.haml +18 -0
  30. data/app/views/kaminari/_paginator.html.slim +19 -0
  31. data/app/views/kaminari/_prev_page.html.erb +11 -0
  32. data/app/views/kaminari/_prev_page.html.haml +9 -0
  33. data/app/views/kaminari/_prev_page.html.slim +10 -0
  34. data/config/locales/kaminari.yml +19 -0
  35. data/gemfiles/active_record_30.gemfile +7 -0
  36. data/gemfiles/active_record_31.gemfile +7 -0
  37. data/gemfiles/active_record_32.gemfile +10 -0
  38. data/gemfiles/active_record_40.gemfile +8 -0
  39. data/gemfiles/data_mapper_12.gemfile +15 -0
  40. data/gemfiles/mongo_mapper.gemfile +10 -0
  41. data/gemfiles/mongoid_24.gemfile +7 -0
  42. data/gemfiles/mongoid_30.gemfile +12 -0
  43. data/gemfiles/sinatra.gemfile +13 -0
  44. data/kaminari.gemspec +36 -0
  45. data/lib/generators/kaminari/config_generator.rb +16 -0
  46. data/lib/generators/kaminari/templates/kaminari_config.rb +10 -0
  47. data/lib/generators/kaminari/views_generator.rb +118 -0
  48. data/lib/kaminari.rb +38 -0
  49. data/lib/kaminari/config.rb +51 -0
  50. data/lib/kaminari/engine.rb +4 -0
  51. data/lib/kaminari/grape.rb +4 -0
  52. data/lib/kaminari/helpers/action_view_extension.rb +151 -0
  53. data/lib/kaminari/helpers/paginator.rb +186 -0
  54. data/lib/kaminari/helpers/sinatra_helpers.rb +144 -0
  55. data/lib/kaminari/helpers/tags.rb +95 -0
  56. data/lib/kaminari/hooks.rb +33 -0
  57. data/lib/kaminari/models/active_record_extension.rb +22 -0
  58. data/lib/kaminari/models/active_record_model_extension.rb +20 -0
  59. data/lib/kaminari/models/active_record_relation_methods.rb +29 -0
  60. data/lib/kaminari/models/array_extension.rb +58 -0
  61. data/lib/kaminari/models/configuration_methods.rb +48 -0
  62. data/lib/kaminari/models/data_mapper_collection_methods.rb +15 -0
  63. data/lib/kaminari/models/data_mapper_extension.rb +48 -0
  64. data/lib/kaminari/models/mongo_mapper_extension.rb +18 -0
  65. data/lib/kaminari/models/mongoid_criteria_methods.rb +23 -0
  66. data/lib/kaminari/models/mongoid_extension.rb +33 -0
  67. data/lib/kaminari/models/page_scope_methods.rb +70 -0
  68. data/lib/kaminari/models/plucky_criteria_methods.rb +18 -0
  69. data/lib/kaminari/railtie.rb +7 -0
  70. data/lib/kaminari/sinatra.rb +5 -0
  71. data/lib/kaminari/version.rb +3 -0
  72. data/spec/config/config_spec.rb +91 -0
  73. data/spec/fake_app/active_record/config.rb +3 -0
  74. data/spec/fake_app/active_record/models.rb +57 -0
  75. data/spec/fake_app/data_mapper/config.rb +1 -0
  76. data/spec/fake_app/data_mapper/models.rb +27 -0
  77. data/spec/fake_app/mongo_mapper/config.rb +2 -0
  78. data/spec/fake_app/mongo_mapper/models.rb +9 -0
  79. data/spec/fake_app/mongoid/config.rb +16 -0
  80. data/spec/fake_app/mongoid/models.rb +22 -0
  81. data/spec/fake_app/rails_app.rb +56 -0
  82. data/spec/fake_app/sinatra_app.rb +22 -0
  83. data/spec/fake_gem.rb +4 -0
  84. data/spec/helpers/action_view_extension_spec.rb +262 -0
  85. data/spec/helpers/helpers_spec.rb +135 -0
  86. data/spec/helpers/sinatra_helpers_spec.rb +170 -0
  87. data/spec/helpers/tags_spec.rb +140 -0
  88. data/spec/models/active_record/active_record_relation_methods_spec.rb +47 -0
  89. data/spec/models/active_record/default_per_page_spec.rb +32 -0
  90. data/spec/models/active_record/max_pages_spec.rb +23 -0
  91. data/spec/models/active_record/max_per_page_spec.rb +32 -0
  92. data/spec/models/active_record/scopes_spec.rb +242 -0
  93. data/spec/models/array_spec.rb +150 -0
  94. data/spec/models/data_mapper/data_mapper_spec.rb +179 -0
  95. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +84 -0
  96. data/spec/models/mongoid/mongoid_spec.rb +126 -0
  97. data/spec/requests/users_spec.rb +53 -0
  98. data/spec/spec_helper.rb +33 -0
  99. data/spec/spec_helper_for_sinatra.rb +33 -0
  100. data/spec/support/database_cleaner.rb +16 -0
  101. data/spec/support/matchers.rb +52 -0
  102. metadata +300 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05274cf73bd8919e0527dfeccb6bc6cdc47a7675
4
+ data.tar.gz: 0bce2e60f937dfac11e72aaf2ec663a9786f5527
5
+ SHA512:
6
+ metadata.gz: 57df9a1381774154b7ce2168d6e2c01ecd495110fefa43bbc75518853e1da2c35375123efd0abd33e3ce337fbf718c131f0b49d989701cc75a398fbc7908c315
7
+ data.tar.gz: a5bb95f02141ea9d111568c77253c32b264a051dc77985215728726f00cdf2f2e8e829d4e1777843f282f66af57e7a0f1943a55ed10593dfe2adf811dd82ab4a
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
File without changes
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ .idea
4
+ Gemfile.lock
5
+ gemfiles/*.lock
6
+ pkg/*
7
+
8
+ doc
9
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=d
@@ -0,0 +1,16 @@
1
+ services: mongodb
2
+
3
+ script: "bundle exec rake spec"
4
+
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - rbx-19mode
9
+
10
+ gemfile:
11
+ - gemfiles/active_record_32.gemfile
12
+ - gemfiles/active_record_40.gemfile
13
+ - gemfiles/data_mapper_12.gemfile
14
+ - gemfiles/mongo_mapper.gemfile
15
+ - gemfiles/mongoid_30.gemfile
16
+ - gemfiles/sinatra.gemfile
@@ -0,0 +1,351 @@
1
+ == 0.14.1
2
+
3
+ * Changed the default "truncation" String from "..." to … #264 [pjaspers]
4
+
5
+ * The theme generator is Github API v3 compatible now! #279 [eitoball]
6
+
7
+ * Made Kaminari.config.default_per_page changeable again #280 [yuki24]
8
+
9
+ == 0.14.0
10
+
11
+ * Grape framework support! #218 [mrplum]
12
+
13
+ * Mongoid 3 ready! #238 [shingara]
14
+
15
+ * Added link_to_previous_page helper #191 [timgremore]
16
+
17
+ * Added helper to generate rel="next" and rel="prev" link tags for SEO #200
18
+ [joe1chen]
19
+
20
+ * Added `max_per_page` configuration option #274 [keiko0713]
21
+ This would be useful for the case when you are using user input `per_page`
22
+ value but want to impose the upper bound.
23
+
24
+ * Added I18n to page_entries_info #207 [plribeiro3000]
25
+
26
+ * Changed method name "num_pages" to "total_pages"
27
+ num_pages" is still available as an alias of "total_pages", but will be
28
+ deprecated or removed in some future version.
29
+
30
+ * Changed the way page_entries_info behave so it can show appropriate names
31
+ for models with namespace #207 [plribeiro3000]
32
+
33
+ * Added html_safe to page_entries_info helper #190 [lucapette]
34
+
35
+ * Fixed displayed number of items on each page w/ Mongoid 2.4.x and
36
+ MongoMapper #194 [dblock]
37
+
38
+ * Removed a unused local variable from templates from default tamplate #245 [juno]
39
+
40
+ * Fixed page_entry_info to use the value of `entry_name` option when given
41
+ collection is empty or a PaginatableArray #265, #277 [eitoball]
42
+
43
+ * Added require 'dm-aggregates' in DataMapper hook #259 [shingara]
44
+
45
+ == 0.13.0
46
+
47
+ * Rails 3.2 ready! #180 [slbug]
48
+
49
+ * DataMapper support! #149 [NoICE, Ragmaanir]
50
+
51
+ * Sinatra & Padrino support! #179 [udzura, mlightner, aereal]
52
+
53
+ * Added mongoid embedded documents support! #155 [yuki24]
54
+
55
+ * Added `each_relevant_page` that only visits pages in the inner or outer
56
+ windows #154 [cbeer]
57
+ Performance improved, particularly with very large number of pages.
58
+
59
+ * Memoize count for AR when calling `total_count` #138 [sarmiena]
60
+ Increases performance for large datasets.
61
+
62
+ * Added `page_entries_info` view helper #140 [jeffreyiacono]
63
+ Example:
64
+ <%= page_entries_info @posts %>
65
+ #=> Displaying posts 6 - 10 of 26 in total
66
+
67
+ * Added `link_to_next_page` helper method that simply links to the next page
68
+ Example:
69
+ <%= link_to_next_page @posts, 'More' %>
70
+ #=> <a href="/posts?page=7" rel="next">More</a>
71
+
72
+ * Let one override the `rel` attribute for 'link_to_next_page` helper #177
73
+ [webmat]
74
+
75
+ * Added `total_count` param for PaginatableArray. Useful for when working with
76
+ RSolr #141 [samdalton]
77
+
78
+ * Changed `Kaminari.paginate_array` API to take a Hash `options`
79
+ And specifying :limit & :offset immediately builds a pagination ready object
80
+ Example:
81
+ # the following two are equivalent. Use whichever you like
82
+ Kaminari.paginate_array((1..100).to_a, limit: 10, offset: 10)
83
+ Kaminari.paginate_array((1..100).to_a).page(2).per(10)
84
+
85
+ * Added `padding` method to skip an arbitrary record count #60 [aaronjensen]
86
+ Example:
87
+ User.page(2).per(10).padding(3) # this will return users 14..23
88
+
89
+ * Made the pagination method name (defaulted to `page`) configurable #57, #162
90
+ Example:
91
+ # you can use the config file and its generator for this
92
+ Kaminari.config.page_method_name = :paging
93
+ Article.paging(3).per(30)
94
+
95
+ * Only add extensions to direct descendents of ActiveRecord::Base #108
96
+ [seejohnrun]
97
+
98
+ * AR models that were subclassed before Kaminari::ActiveRecordExtension is
99
+ included pick up the extensions #119 [pivotal-casebook]
100
+
101
+ * Avoid overwriting AR::Base inherited method #165 [briandmcnabb]
102
+
103
+ * Stopped depending on Rails gem #159 [alsemyonov]
104
+
105
+ * introduced Travis CI #181 [hsbt]
106
+
107
+ == 0.12.4
108
+
109
+ * Support for config.param_name as lambda #102 [ajrkerr]
110
+
111
+ * Stop duplicating order_values #65 [zettabyte]
112
+
113
+ * Preserve select value (e.g. "distinct") when counting #77, #104 [tbeauvais,
114
+ beatlevic]
115
+
116
+ == 0.12.3
117
+
118
+ * Haml 3.1 Support #96 [FlyboyArt, sonic921]
119
+
120
+ == 0.12.2
121
+
122
+ * Added MongoMapper Support #101 [hamin]
123
+
124
+ * Add first_page? and last_page? to page_scope_methods #51 [holinnn]
125
+
126
+ * Make sure that the paginate helper always returns a String #99 [Draiken]
127
+
128
+ * Don't remove includes scopes from count if they are needed #100 [flop]
129
+
130
+ == 0.12.1
131
+
132
+ * Slim template support #93 [detrain]
133
+
134
+ * Use Kaminari.config to specify default value for param_name #94 [avsej]
135
+
136
+ * Fixed "super called outside of method" error happened in particular versions
137
+ of Ruby 1.8.7 #91 [Skulli]
138
+
139
+ * _paginate.html.erb isn't rendered with custom theme #97 [danlunde]
140
+
141
+ == 0.12.0
142
+
143
+ * General configuration options #41 #62 [javierv, iain]
144
+ You can now globally override some default values such as default_per_page,
145
+ window, etc. via configuration file.
146
+ Also, here comes a generator command that generates the default
147
+ configuration file into your app's config/initilizers directory.
148
+
149
+ * Generic pagination support for Array object #47 #68 #74 [lda, ened, jianlin]
150
+ You can now paginate through any kind of Arrayish object in this way:
151
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
152
+
153
+ * Fixed a serious performance regression in 0.11.0 [ankane]
154
+ There was a critical performance issue on #count method in 0.11.0 gem.
155
+
156
+ * Bugfix: Pass the real @params to url_for #90 [utkarshkukreti]
157
+
158
+ * Fixed a gem packaging problem (circular dependency)
159
+ There was a packaging problem with Kaminari 0.11.0 that the gem depends on
160
+ Kaminari gem. Maybe Jeweler + "gemspec" method didn't work well...
161
+
162
+ == 0.11.0
163
+
164
+ This release contains several backward incompatibilities on template API.
165
+ You probably need to update your existing templates if you're already using
166
+ your own custom theme.
167
+
168
+ * Merge _current_page, _first_page_link, _last_page_link and _page_link into
169
+ one _page partial #28 [GarthSnyder]
170
+
171
+ * Add real first/last page links, and use them by default instead of outer
172
+ window #30 [GarthSnyder]
173
+
174
+ * The disabled items should simply not be emitted, even as an empty span #30
175
+ [GarthSnyder]
176
+
177
+ * Skip :order in #count_all so complex groups with generated columns don't
178
+ blow up in SQL-land #61 [keeran, Empact]
179
+
180
+ * Ignore :include in #count_all to make it work better with polymorphic eager
181
+ loading #80 [njakobsen]
182
+
183
+ * Quick fix on #count to return the actual number of records on AR 3.0 #45 #50
184
+
185
+ * Removed "TERRIBLE HORRIBLE NO GOOD VERY BAD HACK" #82 [janx, flop, pda]
186
+
187
+ * Allow for Multiple Themes #64 [tmilewski]
188
+
189
+ * Themes can contain the whole application directory structure now
190
+
191
+ * Use gemspec method in Gemfile [p_elliott]
192
+
193
+ == 0.10.4
194
+
195
+ * Do not break ActiveRecord::Base.descendants, by making sure to call super
196
+ from ActiveRecord::Base.inherited #34 [rolftimmermans]
197
+
198
+ * Fixed vanishing mongoid criteria after calling page() #26 [tyok]
199
+
200
+ == 0.10.3
201
+
202
+ * Fixed a bug that total_count() didn't work when chained with group() scope
203
+ #21 [jgeiger]
204
+
205
+ * Fixed a bug that the paginate helper didn't work properly with an Ajax call
206
+ #23 [hjuskewycz]
207
+
208
+ == 0.10.2
209
+
210
+ * Added :param_name option to the pagination helper #10 [ivanvr]
211
+ Example:
212
+ = paginate @users, :param_name => :pagina
213
+
214
+ == 0.10.1
215
+
216
+ * Fixed a bug that the whole <nav> section was not rendered in some cases
217
+ [GarthSnyder]
218
+
219
+ == 0.10.0
220
+
221
+ * Railtie initializer name is "kaminari" from now
222
+ * Changed bundler settings to work both on 1.9.2 and 1.8.7 #12 [l15n]
223
+ * Fixed bugs encountered when running specs on Ruby 1.9.2 #12 [l15n]
224
+ * Clean up documentation (formatting and editing) #12 [l15n]
225
+ * Use Proc.new instead of lambda for scoped_options #13 [l15n]
226
+ * Use AS hooks for loading AR #14 [hasimo]
227
+ * Refactor scope definition with Concerns #15 [l15n]
228
+ * Ensure output_buffer is always initialized #11 [kichiro]
229
+
230
+ == 0.9.13
231
+
232
+ * Added Mongoid support #5 [juno, hibariya]
233
+ This means, Kaminari is now *ORM agnostic* ☇3☇3☇3
234
+
235
+ == 0.9.12
236
+
237
+ * Moved the whole pagination logic to the paginator partial so that users can
238
+ touch it
239
+ Note: You need to update your _paginator.html.* if you've already customized
240
+ it. If you haven't overridden _paginator.html.* files, then probably
241
+ there're nothing you have to do.
242
+ See this commit for the example:
243
+ https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
244
+
245
+ == 0.9.10
246
+
247
+ * the per() method accepts String, zero and minus value now #7 [koic]
248
+ This enables you to do something like this:
249
+ Model.page(params[:page]).per(params[:per])
250
+
251
+ * Added support for Gem Testers (http://gem-testers.org/) #8 [joealba]
252
+
253
+ == 0.9.9
254
+
255
+ * :params option for the helper [yomukaku_memo]
256
+ You can override each link's url_for option by this option
257
+ Example:
258
+ = paginate @users, :params => {:controller => 'users', :action => 'index2'}
259
+
260
+ * refactor tags
261
+
262
+ == 0.9.8
263
+
264
+ * I18n for the partials
265
+ [:previous, :next, :truncate] are externalized to the I18n resource.
266
+
267
+ == 0.9.7
268
+
269
+ * moved template themes to another repo
270
+ https://github.com/amatsuda/kaminari_themes
271
+
272
+ == 0.9.6
273
+
274
+ * added paginates_per method for setting default per_page value for each model
275
+ in a declarative way
276
+ Example:
277
+ class Article < ActiveRecord::Base
278
+ paginates_per 10
279
+ end
280
+
281
+ == 0.9.5
282
+
283
+ * works on AR 3.0.0 and 3.0.1 now #4 [danillos]
284
+
285
+ == 0.9.4
286
+
287
+ * introduced module based tags
288
+ As a side effect of this internal change, I have to confess that this
289
+ version brings you a slight backward incompatibility on template API.
290
+ If you're using custom templates, be sure to update your existing templates.
291
+ To catch up the new API, you need to update %w[next_url prev_url page_url]
292
+ local variables to simple 'url' like this.
293
+ https://github.com/amatsuda/kaminari/commit/da88729
294
+
295
+ == 0.9.3
296
+
297
+ * improved template detection logic
298
+ When a template for a tag could not be found in the app/views/kaminari/
299
+ directory, it searches the tag's ancestor template files before falling back
300
+ to engine's default template. This may help keeping your custom templates DRY.
301
+
302
+ * simplified bundled template themes
303
+
304
+ == 0.9.2
305
+
306
+ * stop adding extra LF between templates when joining
307
+
308
+ * githubish template theme [maztomo]
309
+
310
+ == 0.9.1
311
+
312
+ * googlish template theme [maztomo]
313
+
314
+ == 0.9.0
315
+
316
+ * added "per_page" to the template local variables #3 [hsbt]
317
+
318
+ * show no contents when the current page is the only page (in other words,
319
+ num_pages == 1) #2 [hsbt]
320
+
321
+ == 0.8.0
322
+
323
+ * using HTML5 <nav> tag rather than <div> for the container tag
324
+
325
+ == 0.7.0
326
+
327
+ * Ajaxified paginator templates
328
+
329
+ == 0.6.0
330
+
331
+ * Hamlized paginator templates
332
+
333
+ == 0.5.0
334
+
335
+ * reset content_for :kaminari_paginator_tags before rendering #1 [hsbt]
336
+
337
+ == 0.4.0
338
+
339
+ * partialize the outer div
340
+
341
+ == 0.3.0
342
+
343
+ * suppress logging when rendering each partial
344
+
345
+ == 0.2.0
346
+
347
+ * default PER_PAGE to 25 [hsbt]
348
+
349
+ == 0.1.0
350
+
351
+ * First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kaminari.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,300 @@
1
+ = Kaminari
2
+
3
+ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for modern web app frameworks and ORMs
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, MongoMapper) multiple web frameworks (Rails, Sinatra), 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, 2.0.0, 2.1 (trunk)
31
+
32
+ * Rails 3.0.x, 3.1, 3.2, 4.0, 4.1 (edge)
33
+
34
+ * Haml 3+
35
+
36
+ * Mongoid 2+
37
+
38
+ * MongoMapper 0.9+
39
+
40
+ * DataMapper 1.1.0+
41
+
42
+ == Install
43
+
44
+ Put this line in your Gemfile:
45
+ gem 'kaminari'
46
+
47
+ Then bundle:
48
+ % bundle
49
+
50
+
51
+ == Usage
52
+
53
+ === Query Basics
54
+
55
+ * the +page+ scope
56
+
57
+ To fetch the 7th page of users (default +per_page+ is 25)
58
+ User.page(7)
59
+
60
+ * the +per+ scope
61
+
62
+ To show a lot more users per each page (change the +per_page+ value)
63
+ User.page(7).per(50)
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
+
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
+
71
+ * the +padding+ scope
72
+
73
+ Occasionally you need to pad a number of records that is not a multiple of the page size.
74
+ User.page(7).per(50).padding(3)
75
+ Note that the +padding+ scope also is not directly defined on the models.
76
+
77
+ === General configuration options
78
+
79
+ You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
80
+ default_per_page # 25 by default
81
+ max_per_page # nil by default
82
+ window # 4 by default
83
+ outer_window # 0 by default
84
+ left # 0 by default
85
+ right # 0 by default
86
+ page_method_name # :page by default
87
+ param_name # :page by default
88
+
89
+ There's a handy generator that generates the default configuration file into config/initializers directory.
90
+ Run the following generator command, then edit the generated file.
91
+ % rails g kaminari:config
92
+
93
+ * changing +page_method_name+
94
+
95
+ 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.
96
+
97
+
98
+ === Configuring default +per_page+ value for each model
99
+
100
+ * +paginates_per+
101
+
102
+ You can specify default +per_page+ value per each model using the following declarative DSL.
103
+ class User < ActiveRecord::Base
104
+ paginates_per 50
105
+ end
106
+
107
+ === Configuring max +per_page+ value for each model
108
+
109
+ * +max_paginates_per+
110
+
111
+ You can specify max +per_page+ value per each model using the following declarative DSL.
112
+ 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.
113
+ class User < ActiveRecord::Base
114
+ max_paginates_per 100
115
+ end
116
+
117
+ === Controllers
118
+
119
+ * the page parameter is in <tt>params[:page]</tt>
120
+
121
+ Typically, your controller code will look like this:
122
+ @users = User.order(:name).page params[:page]
123
+
124
+ === Views
125
+
126
+ * the same old helper method
127
+
128
+ Just call the +paginate+ helper:
129
+ <%= paginate @users %>
130
+
131
+ This will render several <tt>?page=N</tt> pagination links surrounded by an HTML5 <+nav+> tag.
132
+
133
+ === Helpers
134
+
135
+ * the +paginate+ helper method
136
+
137
+ <%= paginate @users %>
138
+ This would output several pagination links such as <tt>« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »</tt>
139
+
140
+ * specifying the "inner window" size (4 by default)
141
+
142
+ <%= paginate @users, :window => 2 %>
143
+ This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
144
+
145
+ * specifying the "outer window" size (0 by default)
146
+
147
+ <%= paginate @users, :outer_window => 3 %>
148
+ This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
149
+
150
+ * outer window can be separately specified by +left+, +right+ (0 by default)
151
+
152
+ <%= paginate @users, :left => 1, :right => 3 %>
153
+ This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
154
+
155
+ * changing the parameter name (:+param_name+) for the links
156
+
157
+ <%= paginate @users, :param_name => :pagina %>
158
+ This would modify the query parameter name on each links.
159
+
160
+ * extra parameters (:+params+) for the links
161
+
162
+ <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'} %>
163
+ This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
164
+
165
+ * Ajax links (crazy simple, but works perfectly!)
166
+
167
+ <%= paginate @users, :remote => true %>
168
+ This would add <tt>data-remote="true"</tt> to all the links inside.
169
+
170
+ * the +link_to_next_page+ and +link_to_previous_page+ helper method
171
+
172
+ <%= link_to_next_page @items, 'Next Page' %>
173
+ This simply renders a link to the next page. This would be helpful for creating a Twitter-like pagination feature.
174
+
175
+ * the +page_entries_info+ helper method
176
+
177
+ <%= page_entries_info @users %>
178
+ This renders a helpful message with numbers of displayed vs. total entries.
179
+
180
+ === I18n and labels
181
+
182
+ The default labels for 'first', 'last', '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.
183
+ 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.
184
+
185
+ en:
186
+ views:
187
+ pagination:
188
+ first: "&laquo; First"
189
+ last: "Last &raquo;"
190
+ previous: "&lsaquo; Prev"
191
+ next: "Next &rsaquo;"
192
+ truncate: "..."
193
+
194
+ === Customizing the pagination helper
195
+
196
+ Kaminari includes a handy template generator.
197
+
198
+ * to edit your paginator
199
+
200
+ Run the generator first,
201
+ % rails g kaminari:views default
202
+
203
+ then edit the partials in your app's <tt>app/views/kaminari/</tt> directory.
204
+
205
+ * for Haml users
206
+
207
+ 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).
208
+
209
+ % rails g kaminari:views default -e haml
210
+
211
+ * themes
212
+
213
+ The generator has the ability to fetch several sample template themes from
214
+ the external repository (https://github.com/amatsuda/kaminari_themes) in
215
+ addition to the bundled "default" one, which will help you creating a nice
216
+ looking paginator.
217
+ % rails g kaminari:views THEME
218
+
219
+ To see the full list of avaliable themes, take a look at the themes repository,
220
+ or just hit the generator without specifying +THEME+ argument.
221
+ % rails g kaminari:views
222
+
223
+ * multiple themes
224
+
225
+ To utilize multiple themes from within a single application, create a directory within the app/views/kaminari/ and move your custom template files into that directory.
226
+ % rails g kaminari:views default (skip if you have existing kaminari views)
227
+ % cd app/views/kaminari
228
+ % mkdir my_custom_theme
229
+ % cp _*.html.* my_custom_theme/
230
+
231
+ Next, reference that directory when calling the +paginate+ method:
232
+
233
+ <%= paginate @users, :theme => 'my_custom_theme' %>
234
+
235
+ Customize away!
236
+
237
+ Note: if the theme isn't present or none is specified, kaminari will default back to the views included within the gem.
238
+
239
+ === Paginating a generic Array object
240
+
241
+ Kaminari provides an Array wrapper class that adapts a generic Array object to the <tt>paginate</tt> view helper.
242
+ However, the <tt>paginate</tt> helper doesn't automatically handle your Array object (this is intentional and by design).
243
+ <tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
244
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
245
+
246
+ 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:
247
+ Kaminari.paginate_array([], total_count: 145).page(params[:page]).per(10)
248
+
249
+ == Creating friendly URLs and caching
250
+
251
+ 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+:
252
+
253
+ resources :my_resources do
254
+ get 'page/:page', :action => :index, :on => :collection
255
+ end
256
+
257
+ 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...
258
+
259
+ 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]!
260
+
261
+ 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.
262
+
263
+
264
+ == Sinatra/Padrino support
265
+
266
+ Since version 0.13.0, kaminari started to support Sinatra or Sinatra-based frameworks experimentally.
267
+
268
+ To use kaminari and its helpers with these frameworks,
269
+
270
+ require 'kaminari/sinatra'
271
+
272
+ or edit gemfile:
273
+
274
+ gem 'kaminari', :require => 'kaminari/sinatra'
275
+
276
+ More features are coming, and again, this is still experimental. Please let us know if you found anything wrong with the Sinatra support.
277
+
278
+
279
+ == For more information
280
+
281
+ Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques.
282
+ https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
283
+
284
+
285
+ == Build Status {<img src="https://secure.travis-ci.org/amatsuda/kaminari.png"/>}[http://travis-ci.org/amatsuda/kaminari]
286
+
287
+
288
+ == Questions, Feedback
289
+
290
+ Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
291
+
292
+
293
+ == Contributing to Kaminari
294
+
295
+ * Fork, fix, then send me a pull request.
296
+
297
+
298
+ == Copyright
299
+
300
+ Copyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.