kaminari 0.17.0 → 1.0.0.beta2

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.

Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +20 -39
  4. data/CHANGELOG.md +560 -0
  5. data/CONTRIBUTING.md +16 -0
  6. data/Gemfile +1 -0
  7. data/README.md +545 -0
  8. data/Rakefile +21 -24
  9. data/gemfiles/active_record_41.gemfile +2 -4
  10. data/gemfiles/active_record_42.gemfile +2 -4
  11. data/gemfiles/active_record_50.gemfile +20 -0
  12. data/gemfiles/active_record_edge.gemfile +5 -6
  13. data/kaminari.gemspec +11 -17
  14. data/lib/kaminari.rb +4 -39
  15. data/lib/kaminari/version.rb +2 -1
  16. metadata +44 -186
  17. data/.gemtest +0 -0
  18. data/.rspec +0 -2
  19. data/CHANGELOG.rdoc +0 -480
  20. data/README.rdoc +0 -336
  21. data/app/views/kaminari/_first_page.html.erb +0 -11
  22. data/app/views/kaminari/_first_page.html.haml +0 -9
  23. data/app/views/kaminari/_first_page.html.slim +0 -10
  24. data/app/views/kaminari/_gap.html.erb +0 -8
  25. data/app/views/kaminari/_gap.html.haml +0 -8
  26. data/app/views/kaminari/_gap.html.slim +0 -9
  27. data/app/views/kaminari/_last_page.html.erb +0 -11
  28. data/app/views/kaminari/_last_page.html.haml +0 -9
  29. data/app/views/kaminari/_last_page.html.slim +0 -10
  30. data/app/views/kaminari/_next_page.html.erb +0 -11
  31. data/app/views/kaminari/_next_page.html.haml +0 -9
  32. data/app/views/kaminari/_next_page.html.slim +0 -10
  33. data/app/views/kaminari/_page.html.erb +0 -12
  34. data/app/views/kaminari/_page.html.haml +0 -10
  35. data/app/views/kaminari/_page.html.slim +0 -11
  36. data/app/views/kaminari/_paginator.html.erb +0 -23
  37. data/app/views/kaminari/_paginator.html.haml +0 -18
  38. data/app/views/kaminari/_paginator.html.slim +0 -19
  39. data/app/views/kaminari/_prev_page.html.erb +0 -11
  40. data/app/views/kaminari/_prev_page.html.haml +0 -9
  41. data/app/views/kaminari/_prev_page.html.slim +0 -10
  42. data/config/locales/kaminari.yml +0 -19
  43. data/gemfiles/active_record_30.gemfile +0 -28
  44. data/gemfiles/active_record_31.gemfile +0 -26
  45. data/gemfiles/active_record_32.gemfile +0 -25
  46. data/gemfiles/active_record_40.gemfile +0 -26
  47. data/gemfiles/data_mapper_12.gemfile +0 -32
  48. data/gemfiles/mongo_mapper.gemfile +0 -25
  49. data/gemfiles/mongoid_30.gemfile +0 -22
  50. data/gemfiles/mongoid_31.gemfile +0 -21
  51. data/gemfiles/mongoid_40.gemfile +0 -19
  52. data/gemfiles/mongoid_50.gemfile +0 -23
  53. data/gemfiles/sinatra_13.gemfile +0 -36
  54. data/gemfiles/sinatra_14.gemfile +0 -33
  55. data/lib/generators/kaminari/config_generator.rb +0 -16
  56. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  57. data/lib/generators/kaminari/views_generator.rb +0 -119
  58. data/lib/kaminari/config.rb +0 -51
  59. data/lib/kaminari/engine.rb +0 -4
  60. data/lib/kaminari/grape.rb +0 -4
  61. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  62. data/lib/kaminari/helpers/paginator.rb +0 -195
  63. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  64. data/lib/kaminari/helpers/tags.rb +0 -108
  65. data/lib/kaminari/hooks.rb +0 -53
  66. data/lib/kaminari/models/active_record_extension.rb +0 -22
  67. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  68. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  69. data/lib/kaminari/models/array_extension.rb +0 -66
  70. data/lib/kaminari/models/configuration_methods.rb +0 -48
  71. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  72. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  73. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  74. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  75. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  76. data/lib/kaminari/models/page_scope_methods.rb +0 -73
  77. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  78. data/lib/kaminari/railtie.rb +0 -7
  79. data/lib/kaminari/sinatra.rb +0 -7
  80. data/spec/config/config_spec.rb +0 -91
  81. data/spec/fake_app/active_record/config.rb +0 -3
  82. data/spec/fake_app/active_record/models.rb +0 -65
  83. data/spec/fake_app/data_mapper/config.rb +0 -1
  84. data/spec/fake_app/data_mapper/models.rb +0 -27
  85. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  86. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  87. data/spec/fake_app/mongoid/config.rb +0 -20
  88. data/spec/fake_app/mongoid/models.rb +0 -38
  89. data/spec/fake_app/rails_app.rb +0 -56
  90. data/spec/fake_app/sinatra_app.rb +0 -22
  91. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  92. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  93. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  94. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  95. data/spec/fake_gem.rb +0 -20
  96. data/spec/generators/views_generator_spec.rb +0 -18
  97. data/spec/helpers/action_view_extension_spec.rb +0 -318
  98. data/spec/helpers/helpers_spec.rb +0 -144
  99. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  100. data/spec/helpers/tags_spec.rb +0 -140
  101. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  102. data/spec/models/active_record/inherited_spec.rb +0 -9
  103. data/spec/models/active_record/scopes_spec.rb +0 -265
  104. data/spec/models/array_spec.rb +0 -172
  105. data/spec/models/configuration_methods_spec.rb +0 -125
  106. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  107. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  108. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  109. data/spec/requests/users_spec.rb +0 -53
  110. data/spec/spec_helper.rb +0 -34
  111. data/spec/spec_helper_for_sinatra.rb +0 -34
  112. data/spec/support/database_cleaner.rb +0 -19
  113. data/spec/support/matchers.rb +0 -52
@@ -0,0 +1,16 @@
1
+ Kaminari is a volunteer effort. We encourage you to pitch in.
2
+
3
+ __*We only accept bug reports and pull requests in GitHub*__. Join the team!
4
+
5
+ * If you have a support question about how to use kaminari, please [ask on StackOverflow](http://stackoverflow.com/search?tab=newest&q=kaminari).
6
+ * Bug reports should include the following:
7
+ - Minimal example of code to reproduce the bug
8
+ - Stacktrace
9
+ - What you expected to see, and what you actually saw.
10
+
11
+ * Feature requests should be accompanied by a patch, that includes tests.
12
+ * We won't accept any feature requests that come without a patch.
13
+
14
+ Thanks! :heart: :heart: :heart:
15
+
16
+ Kaminari Team
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in kaminari.gemspec
@@ -0,0 +1,545 @@
1
+ # Kaminari [![Build Status](https://travis-ci.org/amatsuda/kaminari.svg)](http://travis-ci.org/amatsuda/kaminari) [![Code Climate](https://img.shields.io/codeclimate/github/amatsuda/kaminari.svg)](https://codeclimate.com/github/amatsuda/kaminari) [![Inch CI](http://inch-ci.org/github/amatsuda/kaminari.svg)](http://inch-ci.org/github/amatsuda/kaminari)
2
+
3
+ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for modern web app frameworks and ORMs
4
+
5
+ ## Features
6
+
7
+ ### Clean
8
+ Does not globally pollute `Array`, `Hash`, `Object` or `AR::Base`.
9
+
10
+ ### Easy to Use
11
+ Just bundle the gem, then your models are ready to be paginated.
12
+ No configuration required.
13
+ Don't have to define anything in your models or helpers.
14
+
15
+ ### Simple Scope-based API
16
+ Everything is method chainable with less "Hasheritis". You know, that's the modern Rails way.
17
+ No special collection class or anything for the paginated values, instead using a general `AR::Relation` instance.
18
+ So, of course you can chain any other conditions before or after the paginator scope.
19
+
20
+ ### Customizable Engine-based I18n-aware Helpers
21
+ 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.
22
+ So, you can easily modify their behaviour, style or whatever by overriding partial templates.
23
+
24
+ ### ORM & Template Engine Agnostic
25
+ Kaminari supports multiple ORMs (ActiveRecord, DataMapper, Mongoid, MongoMapper) multiple web frameworks (Rails, Sinatra, Grape), and multiple template engines (ERB, Haml, Slim).
26
+
27
+ ### Modern
28
+ The pagination helper outputs the HTML5 `<nav>` tag by default. Plus, the helper supports Rails unobtrusive Ajax.
29
+
30
+
31
+ ## Supported Versions
32
+
33
+ * Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4
34
+
35
+ * Rails 4.1, 4.2, 5.0, 5.1
36
+
37
+ * Sinatra 1.4
38
+
39
+ * Haml 3+
40
+
41
+ * Mongoid 3+
42
+
43
+ * MongoMapper 0.9+
44
+
45
+ * DataMapper 1.1.0+
46
+
47
+
48
+ ## Installation
49
+
50
+ To install kaminari on the default Rails stack, just put this line in your Gemfile:
51
+
52
+ ```ruby
53
+ gem 'kaminari'
54
+ ```
55
+
56
+ Then bundle:
57
+
58
+ ```sh
59
+ % bundle
60
+ ```
61
+
62
+ If you're building non-Rails of non-ActiveRecord app and want the pagination feature on it, please take a look at [Other Framework/Library Support](#other-frameworklibrary-support) section.
63
+
64
+
65
+ ## Query Basics
66
+
67
+ ### The `page` Scope
68
+
69
+ To fetch the 7th page of users (default `per_page` is 25)
70
+
71
+ ```ruby
72
+ User.page(7)
73
+ ```
74
+
75
+ Note: pagination starts at page 1, not at page 0 (page(0) will return the same results as page(1)).
76
+
77
+ ### The `per` Scope
78
+
79
+ To show a lot more users per each page (change the `per_page` value)
80
+
81
+ ```ruby
82
+ User.page(7).per(50)
83
+ ```
84
+
85
+ Note that the `per` scope is not directly defined on the models but is just a method defined on the page scope.
86
+ This is absolutely reasonable because you will never actually use `per_page` without specifying the `page` number.
87
+
88
+ Keep in mind that `per` internally utilizes `limit` and so it will override any `limit` that was set previously.
89
+ And if you want to get the size for all request records you can use `total_count` method:
90
+
91
+ ```ruby
92
+ User.count #=> 1000
93
+ a = User.limit(5); a.count #=> 5
94
+ a.page(1).per(20).size #=> 20
95
+ a.page(1).per(20).total_count #=> 1000
96
+ ```
97
+
98
+ ### The `padding` Scope
99
+
100
+ Occasionally you need to pad a number of records that is not a multiple of the page size.
101
+
102
+ ```ruby
103
+ User.page(7).per(50).padding(3)
104
+ ```
105
+
106
+ Note that the `padding` scope also is not directly defined on the models.
107
+
108
+
109
+ ## Configuring Kaminari
110
+
111
+ ### General Configuration Options
112
+
113
+ You can configure the following default values by overriding these values using `Kaminari.configure` method.
114
+
115
+ default_per_page # 25 by default
116
+ max_per_page # nil by default
117
+ max_pages # nil by default
118
+ window # 4 by default
119
+ outer_window # 0 by default
120
+ left # 0 by default
121
+ right # 0 by default
122
+ page_method_name # :page by default
123
+ param_name # :page by default
124
+ params_on_first_page # false by default
125
+
126
+ There's a handy generator that generates the default configuration file into config/initializers directory.
127
+ Run the following generator command, then edit the generated file.
128
+
129
+ ```sh
130
+ % rails g kaminari:config
131
+ ```
132
+
133
+ ### Changing `page_method_name`
134
+
135
+ 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.
136
+
137
+
138
+ ### Configuring Default per_page Value for Each Model by `paginates_per`
139
+
140
+ You can specify default `per_page` value per each model using the following declarative DSL.
141
+
142
+ ```ruby
143
+ class User < ActiveRecord::Base
144
+ paginates_per 50
145
+ end
146
+ ```
147
+
148
+ ### Configuring Max per_page Value for Each Model by `max_paginates_per`
149
+
150
+ You can specify max `per_page` value per each model using the following declarative DSL.
151
+ If the variable that specified via `per` scope is more than this variable, `max_paginates_per` is used instead of it.
152
+ Default value is nil, which means you are not imposing any max `per_page` value.
153
+
154
+ ```ruby
155
+ class User < ActiveRecord::Base
156
+ max_paginates_per 100
157
+ end
158
+ ```
159
+
160
+
161
+ ## Controllers
162
+
163
+ ### The Page Parameter Is in `params[:page]`
164
+
165
+ Typically, your controller code will look like this:
166
+
167
+ ```ruby
168
+ @users = User.order(:name).page params[:page]
169
+ ```
170
+
171
+
172
+ ## Views
173
+
174
+ ### The Same Old Helper Method
175
+
176
+ Just call the `paginate` helper:
177
+
178
+ ```erb
179
+ <%= paginate @users %>
180
+ ```
181
+
182
+ This will render several `?page=N` pagination links surrounded by an HTML5 `<nav>` tag.
183
+
184
+
185
+ ## Helpers
186
+
187
+ ### The `paginate` Helper Method
188
+
189
+ ```erb
190
+ <%= paginate @users %>
191
+ ```
192
+
193
+ This would output several pagination links such as `« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »`
194
+
195
+ ### Specifying the "inner window" Size (4 by default)
196
+
197
+ ```erb
198
+ <%= paginate @users, window: 2 %>
199
+ ```
200
+
201
+ This would output something like `... 5 6 7 8 9 ...` when 7 is the current
202
+ page.
203
+
204
+ ### Specifying the "outer window" Size (0 by default)
205
+
206
+ ```erb
207
+ <%= paginate @users, outer_window: 3 %>
208
+ ```
209
+
210
+ This would output something like `1 2 3 4 ...(snip)... 17 18 19 20` while having 20 pages in total.
211
+
212
+ ### Outer Window Can Be Separately Specified by left, right (0 by default)
213
+
214
+ ```erb
215
+ <%= paginate @users, left: 1, right: 3 %>
216
+ ```
217
+
218
+ This would output something like `1 ...(snip)... 18 19 20` while having 20 pages in total.
219
+
220
+ ### Changing the Parameter Name (`:param_name`) for the Links
221
+
222
+ ```erb
223
+ <%= paginate @users, param_name: :pagina %>
224
+ ```
225
+
226
+ This would modify the query parameter name on each links.
227
+
228
+ ### Extra Parameters (`:params`) for the Links
229
+
230
+ ```erb
231
+ <%= paginate @users, params: {controller: 'foo', action: 'bar'} %>
232
+ ```
233
+
234
+ This would modify each link's `url_option`. :`controller` and :`action` might be the keys in common.
235
+
236
+ ### Ajax Links (crazy simple, but works perfectly!)
237
+
238
+ ```erb
239
+ <%= paginate @users, remote: true %>
240
+ ```
241
+
242
+ This would add `data-remote="true"` to all the links inside.
243
+
244
+ ### Specifying an Alternative Views Directory (default is kaminari/)
245
+
246
+ ```erb
247
+ <%= paginate @users, views_prefix: 'templates' %>
248
+ ```
249
+
250
+ This would search for partials in `app/views/templates/kaminari`.
251
+ 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 integration with other gems such as [cells](https://github.com/apotonick/cells).
252
+
253
+ ### The `link_to_next_page` and `link_to_previous_page` (aliased to `link_to_prev_page`) Helper Methods
254
+
255
+ ```erb
256
+ <%= link_to_next_page @items, 'Next Page' %>
257
+ ```
258
+
259
+ This simply renders a link to the next page. This would be helpful for creating a Twitter-like pagination feature.
260
+
261
+ ### The `page_entries_info` Helper Method
262
+
263
+ ```erb
264
+ <%= page_entries_info @posts %>
265
+ ```
266
+
267
+ This renders a helpful message with numbers of displayed vs. total entries.
268
+
269
+ By default, the message will use the humanized class name of objects in collection: for instance, "project types" for ProjectType models.
270
+ The namespace will be cut out and only the last name will be used. Override this with the `:entry_name` parameter:
271
+
272
+ ```erb
273
+ <%= page_entries_info @posts, entry_name: 'item' %>
274
+ #=> Displaying items 6 - 10 of 26 in total
275
+ ```
276
+
277
+ ### The `rel_next_prev_link_tags` Helper Method
278
+
279
+ ```erb
280
+ <%= rel_next_prev_link_tags @users %>
281
+ ```
282
+
283
+ This renders the rel next and prev link tags for the head.
284
+
285
+ ### The `path_to_next_page` Helper Method
286
+
287
+ ```erb
288
+ <%= path_to_next_page @users %>
289
+ ```
290
+
291
+ This returns the server relative path to the next page.
292
+
293
+ ### The `path_to_prev_page` Helper Method
294
+
295
+ ```erb
296
+ <%= path_to_prev_page @users %>
297
+ ```
298
+
299
+ This returns the server relative path to the previous page.
300
+
301
+
302
+ ## I18n and Labels
303
+
304
+ The default labels for 'first', 'last', 'previous', '...' and 'next' are stored in the I18n yaml inside the engine, and rendered through I18n API.
305
+ You can switch the label value per I18n.locale for your internationalized application. Keys and the default values are the following. You can override them by adding to a YAML file in your `Rails.root/config/locales` directory.
306
+
307
+ ```yaml
308
+ en:
309
+ views:
310
+ pagination:
311
+ first: "&laquo; First"
312
+ last: "Last &raquo;"
313
+ previous: "&lsaquo; Prev"
314
+ next: "Next &rsaquo;"
315
+ truncate: "&hellip;"
316
+ helpers:
317
+ page_entries_info:
318
+ one_page:
319
+ display_entries:
320
+ zero: "No %{entry_name} found"
321
+ one: "Displaying <b>1</b> %{entry_name}"
322
+ other: "Displaying <b>all %{count}</b> %{entry_name}"
323
+ more_pages:
324
+ display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
325
+ ```
326
+
327
+ If you use non-English localization see [i18n rules](https://github.com/svenfuchs/i18n/blob/master/test/test_data/locales/plurals.rb) for changing
328
+ `one_page:display_entries` block.
329
+
330
+
331
+ ## Customizing the Pagination Helper
332
+
333
+ Kaminari includes a handy template generator.
334
+
335
+ ### To Edit Your Paginator
336
+
337
+ Run the generator first,
338
+
339
+ ```sh
340
+ % rails g kaminari:views default
341
+ ```
342
+
343
+ then edit the partials in your app's `app/views/kaminari/` directory.
344
+
345
+ ### For Haml/Slim Users
346
+
347
+ You can use the [html2haml gem](https://github.com/haml/html2haml) or the [html2slim gem](https://github.com/slim-template/html2slim) to convert erb templates.
348
+ The kaminari gem will automatically pick up haml/slim templates if you place them in `app/views/kaminari/`.
349
+
350
+ ### Multiple Templates
351
+
352
+ In case you need different templates for your paginator (for example public and admin), you can pass `--views-prefix directory` like this:
353
+
354
+ ```sh
355
+ % rails g kaminari:views default --views-prefix admin
356
+ ```
357
+
358
+ that will generate partials in `app/views/admin/kaminari/` directory.
359
+
360
+ ### Themes
361
+
362
+ The generator has the ability to fetch several sample template themes from the external repository (https://github.com/amatsuda/kaminari_themes) in addition to the bundled "default" one, which will help you creating a nice looking paginator.
363
+
364
+ ```sh
365
+ % rails g kaminari:views THEME
366
+ ```
367
+
368
+ To see the full list of available themes, take a look at the themes repository, or just hit the generator without specifying `THEME` argument.
369
+
370
+ ```sh
371
+ % rails g kaminari:views
372
+ ```
373
+
374
+ ### Multiple Themes
375
+
376
+ 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.
377
+
378
+ ```sh
379
+ % rails g kaminari:views default (skip if you have existing kaminari views)
380
+ % cd app/views/kaminari
381
+ % mkdir my_custom_theme
382
+ % cp _*.html.* my_custom_theme/
383
+ ```
384
+
385
+ Next, reference that directory when calling the `paginate` method:
386
+
387
+ ```erb
388
+ <%= paginate @users, theme: 'my_custom_theme' %>
389
+ ```
390
+
391
+ Customize away!
392
+
393
+ Note: if the theme isn't present or none is specified, kaminari will default back to the views included within the gem.
394
+
395
+
396
+ ## Paginating Without Issuing SELECT COUNT Query
397
+
398
+ Generally the paginator needs to know the total number of records to display the links, but sometimes we don't need the total number of records and just need the "previous page" and "next page" links.
399
+ For such use case, Kaminari provides `without_count` mode that creates a paginatable collection without counting the number of all records.
400
+ This may be helpful when you're dealing with a very large dataset because counting on a big table tends to become slow on RDBMS.
401
+
402
+ Just add `.without_count` to your paginated object:
403
+
404
+ ```ruby
405
+ User.page(3).without_count
406
+ ```
407
+
408
+ In your view file, you can only use simple helpers like the following instead of the full-featured `paginate` helper:
409
+
410
+ ```erb
411
+ <%= link_to_prev_page @users, 'Previous Page' %>
412
+ <%= link_to_next_page @users, 'Next Page' %>
413
+ ```
414
+
415
+
416
+ ## Paginating a Generic Array object
417
+
418
+ Kaminari provides an Array wrapper class that adapts a generic Array object to the `paginate` view helper. However, the `paginate` helper doesn't automatically handle your Array object (this is intentional and by design).
419
+ `Kaminari::paginate_array` method converts your Array object into a paginatable Array that accepts `page` method.
420
+
421
+ ```ruby
422
+ @paginatable_array = Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
423
+ ```
424
+
425
+ 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:
426
+
427
+ ```ruby
428
+ @paginatable_array = Kaminari.paginate_array([], total_count: 145).page(params[:page]).per(10)
429
+ ```
430
+
431
+
432
+ ## Creating Friendly URLs and Caching
433
+
434
+ Because of the `page` parameter and Rails 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`:
435
+
436
+ ```ruby
437
+ resources :my_resources do
438
+ get 'page/:page', action: :index, on: :collection
439
+ end
440
+ ```
441
+
442
+ If you are using Rails 4 or later, you can simplify route definitions by using `concern`:
443
+
444
+ ```ruby
445
+ concern :paginatable do
446
+ get '(page/:page)', action: :index, on: :collection, as: ''
447
+ end
448
+
449
+ resources :my_resources, concerns: :paginatable
450
+ ```
451
+
452
+ This will create URLs like `/my_resources/page/33` instead of `/my_resources?page=33`. This is now a friendly URL, but it also has other added benefits...
453
+
454
+ 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)!
455
+
456
+ NOTE: In this example, I've pointed the route to my `:index` action. You may have defined a custom pagination action in your controller - you should point `action: :your_custom_action` instead.
457
+
458
+
459
+ ## Other Framework/Library Support
460
+
461
+ ### The kaminari gem
462
+
463
+ Technically, the kaminari gem consists of 3 individual components:
464
+
465
+ kaminari-core: the core pagination logic
466
+ kaminari-activerecord: Active Record adapter
467
+ kaminari-actionview: Action View adapter
468
+
469
+ So, bundling `gem 'kaminari'` is equivalent to the following 2 lines (kaminari-core is referenced from the adapters):
470
+
471
+ ```ruby
472
+ gem 'kaminari-activerecord'
473
+ gem 'kaminari-actionview'
474
+ ```
475
+
476
+ ### For Other ORM Users
477
+
478
+ If you want to use other supported ORMs instead of ActiveRecord, for example Mongoid, bundle its adapter instead of kaminari-activerecord.
479
+
480
+ ```ruby
481
+ gem 'kaminari-mongoid'
482
+ gem 'kaminari-actionview'
483
+ ```
484
+
485
+ Kaminari currently provides adapters for the following ORMs:
486
+
487
+ * Active Record: https://github.com/amatsuda/kaminari/tree/master/kaminari-activerecord (included in this repo)
488
+ * Mongoid: https://github.com/kaminari/kaminari-mongoid
489
+ * MongoMapper: https://github.com/kaminari/kaminari-mongo_mapper
490
+ * DataMapper: https://github.com/kaminari/kaminari-data_mapper (would not work on kaminari 1.0.x)
491
+
492
+ ### For Other Web Framework Users
493
+
494
+ If you want to use other web frameworks instead of Rails + Action View, for example Sinatra, bundle its adapter instead of kaminari-actionview.
495
+
496
+ ```ruby
497
+ gem 'kaminari-activerecord'
498
+ gem 'kaminari-sinatra'
499
+ ```
500
+
501
+ Kaminari currently provides adapters for the following web frameworks:
502
+
503
+ * Action View: https://github.com/amatsuda/kaminari/tree/master/kaminari-actionview (included in this repo)
504
+ * Sinatra: https://github.com/kaminari/kaminari-sinatra
505
+ * Grape: https://github.com/kaminari/kaminari-grape
506
+
507
+
508
+ ## For More Information
509
+
510
+ Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques. https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
511
+
512
+
513
+ ## Questions, Feedback
514
+
515
+ Feel free to message me on Github (amatsuda) or Twitter ([@a_matsuda](https://twitter.com/a_matsuda)) ☇☇☇ :)
516
+
517
+
518
+ ## Contributing to Kaminari
519
+
520
+ Fork, fix, then send a pull request.
521
+
522
+ To run the test suite locally against all supported frameworks:
523
+
524
+ ```sh
525
+ % bundle install
526
+ % rake test:all
527
+ ```
528
+
529
+ To target the test suite against one framework:
530
+
531
+ ```sh
532
+ % rake test:active_record_50
533
+ ```
534
+
535
+ You can find a list of supported test tasks by running `rake -T`. You may also find it useful to run a specific test for a specific framework. To do so, you'll have to first make sure you have bundled everything for that configuration, then you can run the specific test:
536
+
537
+ ```sh
538
+ % BUNDLE_GEMFILE='gemfiles/active_record_50.gemfile' bundle install
539
+ % BUNDLE_GEMFILE='gemfiles/active_record_50.gemfile' TEST=kaminari-core/test/requests/navigation_test.rb bundle exec rake test
540
+ ```
541
+
542
+
543
+ ## Copyright
544
+
545
+ Copyright (c) 2011- Akira Matsuda. See MIT-LICENSE for further details.