sayso-kaminari 0.12.4.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.document +5 -0
  2. data/.gemtest +0 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +2 -0
  5. data/CHANGELOG +245 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.rdoc +217 -0
  9. data/Rakefile +22 -0
  10. data/app/views/kaminari/_first_page.html.erb +11 -0
  11. data/app/views/kaminari/_first_page.html.haml +9 -0
  12. data/app/views/kaminari/_first_page.html.slim +10 -0
  13. data/app/views/kaminari/_gap.html.erb +8 -0
  14. data/app/views/kaminari/_gap.html.haml +8 -0
  15. data/app/views/kaminari/_gap.html.slim +9 -0
  16. data/app/views/kaminari/_last_page.html.erb +11 -0
  17. data/app/views/kaminari/_last_page.html.haml +9 -0
  18. data/app/views/kaminari/_last_page.html.slim +10 -0
  19. data/app/views/kaminari/_next_page.html.erb +11 -0
  20. data/app/views/kaminari/_next_page.html.haml +9 -0
  21. data/app/views/kaminari/_next_page.html.slim +10 -0
  22. data/app/views/kaminari/_page.html.erb +12 -0
  23. data/app/views/kaminari/_page.html.haml +10 -0
  24. data/app/views/kaminari/_page.html.slim +11 -0
  25. data/app/views/kaminari/_paginator.html.erb +23 -0
  26. data/app/views/kaminari/_paginator.html.haml +18 -0
  27. data/app/views/kaminari/_paginator.html.slim +19 -0
  28. data/app/views/kaminari/_prev_page.html.erb +11 -0
  29. data/app/views/kaminari/_prev_page.html.haml +9 -0
  30. data/app/views/kaminari/_prev_page.html.slim +10 -0
  31. data/config/locales/kaminari.yml +10 -0
  32. data/kaminari.gemspec +35 -0
  33. data/lib/generators/kaminari/config_generator.rb +16 -0
  34. data/lib/generators/kaminari/templates/kaminari_config.rb +8 -0
  35. data/lib/generators/kaminari/views_generator.rb +103 -0
  36. data/lib/kaminari.rb +2 -0
  37. data/lib/kaminari/config.rb +41 -0
  38. data/lib/kaminari/engine.rb +4 -0
  39. data/lib/kaminari/helpers/action_view_extension.rb +50 -0
  40. data/lib/kaminari/helpers/paginator.rb +154 -0
  41. data/lib/kaminari/helpers/tags.rb +95 -0
  42. data/lib/kaminari/models/active_record_extension.rb +25 -0
  43. data/lib/kaminari/models/active_record_relation_methods.rb +35 -0
  44. data/lib/kaminari/models/array_extension.rb +42 -0
  45. data/lib/kaminari/models/configuration_methods.rb +20 -0
  46. data/lib/kaminari/models/fixer.rb +102 -0
  47. data/lib/kaminari/models/mongo_mapper_extension.rb +18 -0
  48. data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -0
  49. data/lib/kaminari/models/mongoid_extension.rb +31 -0
  50. data/lib/kaminari/models/page_scope_methods.rb +36 -0
  51. data/lib/kaminari/models/plucky_criteria_methods.rb +18 -0
  52. data/lib/kaminari/railtie.rb +37 -0
  53. data/lib/kaminari/version.rb +3 -0
  54. data/spec/acceptance/acceptance_helper.rb +5 -0
  55. data/spec/acceptance/support/helpers.rb +5 -0
  56. data/spec/acceptance/support/paths.rb +9 -0
  57. data/spec/acceptance/users_spec.rb +53 -0
  58. data/spec/config/config_spec.rb +61 -0
  59. data/spec/fake_app.rb +80 -0
  60. data/spec/helpers/action_view_extension_spec.rb +37 -0
  61. data/spec/helpers/helpers_spec.rb +135 -0
  62. data/spec/helpers/tags_spec.rb +140 -0
  63. data/spec/models/active_record_relation_methods_spec.rb +28 -0
  64. data/spec/models/array_spec.rb +105 -0
  65. data/spec/models/default_per_page_spec.rb +29 -0
  66. data/spec/models/mongo_mapper_spec.rb +79 -0
  67. data/spec/models/mongoid_spec.rb +72 -0
  68. data/spec/models/scopes_spec.rb +149 -0
  69. data/spec/spec_helper.rb +28 -0
  70. data/spec/support/database_cleaner.rb +13 -0
  71. data/spec/support/matchers.rb +46 -0
  72. metadata +264 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ doc
7
+ log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=d
data/CHANGELOG ADDED
@@ -0,0 +1,245 @@
1
+ == 0.12.4
2
+
3
+ * Support for config.param_name as lambda #102 [ajrkerr]
4
+
5
+ * Stop duplicating order_values #65 [zettabyte]
6
+
7
+ * Preserve select value (e.g. "distinct") when counting #77, #104 [tbeauvais,
8
+ beatlevic]
9
+
10
+ == 0.12.3
11
+
12
+ * Haml 3.1 Support #96 [FlyboyArt, sonic921]
13
+
14
+ == 0.12.2
15
+
16
+ * Added MongoMapper Support #101 [hamin]
17
+
18
+ * Add first_page? and last_page? to page_scope_methods #51 [holinnn]
19
+
20
+ * Make sure that the paginate helper always returns a String #99 [Draiken]
21
+
22
+ * Don't remove includes scopes from count if they are needed #100 [flop]
23
+
24
+ == 0.12.1
25
+
26
+ * Slim template support #93 [detrain]
27
+
28
+ * Use Kaminari.config to specify default value for param_name #94 [avsej]
29
+
30
+ * Fixed "super called outside of method" error happened in particular versions
31
+ of Ruby 1.8.7 #91 [Skulli]
32
+
33
+ * _paginate.html.erb isn't rendered with custom theme #97 [danlunde]
34
+
35
+ == 0.12.0
36
+
37
+ * General configuration options #41 #62 [javierv, iain]
38
+ You can now globally override some default values such as default_per_page,
39
+ window, etc. via configuration file.
40
+ Also, here comes a generator command that generates the default
41
+ configuration file into your app's config/initilizers directory.
42
+
43
+ * Generic pagination support for Array object #47 #68 #74 [lda, ened, jianlin]
44
+ You can now paginate through any kind of Arrayish object in this way:
45
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
46
+
47
+ * Fixed a serious performance regression in 0.11.0 [ankane]
48
+ There was a critical performance issue on #count method in 0.11.0 gem.
49
+
50
+ * Bugfix: Pass the real @params to url_for #90 [utkarshkukreti]
51
+
52
+ * Fixed a gem packaging problem (circular dependency)
53
+ There was a packaging problem with Kaminari 0.11.0 that the gem depends on
54
+ Kaminari gem. Maybe Jeweler + "gemspec" method didn't work well...
55
+
56
+ == 0.11.0
57
+
58
+ This release contains several backward incompatibilities on template API.
59
+ You probably need to update your existing templates if you're already using
60
+ your own custom theme.
61
+
62
+ * Merge _current_page, _first_page_link, _last_page_link and _page_link into
63
+ one _page partial #28 [GarthSnyder]
64
+
65
+ * Add real first/last page links, and use them by default instead of outer
66
+ window #30 [GarthSnyder]
67
+
68
+ * The disabled items should simply not be emitted, even as an empty span #30
69
+ [GarthSnyder]
70
+
71
+ * Skip :order in #count_all so complex groups with generated columns don't
72
+ blow up in SQL-land #61 [keeran, Empact]
73
+
74
+ * Ignore :include in #count_all to make it work better with polymorphic eager
75
+ loading #80 [njakobsen]
76
+
77
+ * Quick fix on #count to return the actual number of records on AR 3.0 #45 #50
78
+
79
+ * Removed "TERRIBLE HORRIBLE NO GOOD VERY BAD HACK" #82 [janx, flop, pda]
80
+
81
+ * Allow for Multiple Themes #64 [tmilewski]
82
+
83
+ * Themes can contain the whole application directory structure now
84
+
85
+ * Use gemspec method in Gemfile [p_elliott]
86
+
87
+ == 0.10.4
88
+
89
+ * Do not break ActiveRecord::Base.descendants, by making sure to call super
90
+ from ActiveRecord::Base.inherited #34 [rolftimmermans]
91
+
92
+ * Fixed vanishing mongoid criteria after calling page() #26 [tyok]
93
+
94
+ == 0.10.3
95
+
96
+ * Fixed a bug that total_count() didn't work when chained with group() scope
97
+ #21 [jgeiger]
98
+
99
+ * Fixed a bug that the paginate helper didn't work properly with an Ajax call
100
+ #23 [hjuskewycz]
101
+
102
+ == 0.10.2
103
+
104
+ * Added :param_name option to the pagination helper #10 [ivanvr]
105
+ Example:
106
+ = paginate @users, :param_name => :pagina
107
+
108
+ == 0.10.1
109
+
110
+ * Fixed a bug that the whole <nav> section was not rendered in some cases
111
+ [GarthSnyder]
112
+
113
+ == 0.10.0
114
+
115
+ * Railtie initializer name is "kaminari" from now
116
+ * Changed bundler settings to work both on 1.9.2 and 1.8.7 #12 [l15n]
117
+ * Fixed bugs encountered when running specs on Ruby 1.9.2 #12 [l15n]
118
+ * Clean up documentation (formatting and editing) #12 [l15n]
119
+ * Use Proc.new instead of lambda for scoped_options #13 [l15n]
120
+ * Use AS hooks for loading AR #14 [hasimo]
121
+ * Refactor scope definition with Concerns #15 [l15n]
122
+ * Ensure output_buffer is always initialized #11 [kichiro]
123
+
124
+ == 0.9.13
125
+
126
+ * Added Mongoid support #5 [juno, hibariya]
127
+ This means, Kaminari is now *ORM agnostic* ☇3☇3☇3
128
+
129
+ == 0.9.12
130
+
131
+ * Moved the whole pagination logic to the paginator partial so that users can
132
+ touch it
133
+ Note: You need to update your _paginator.html.* if you've already customized
134
+ it. If you haven't overridden _paginator.html.* files, then probably
135
+ there're nothing you have to do.
136
+ See this commit for the example:
137
+ https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
138
+
139
+ == 0.9.10
140
+
141
+ * the per() method accepts String, zero and minus value now #7 [koic]
142
+ This enables you to do something like this:
143
+ Model.page(params[:page]).per(params[:per])
144
+
145
+ * Added support for Gem Testers (http://gem-testers.org/) #8 [joealba]
146
+
147
+ == 0.9.9
148
+
149
+ * :params option for the helper [yomukaku_memo]
150
+ You can override each link's url_for option by this option
151
+ Example:
152
+ = paginate @users, :params => {:controller => 'users', :action => 'index2'}
153
+
154
+ * refactor tags
155
+
156
+ == 0.9.8
157
+
158
+ * I18n for the partials
159
+ [:previous, :next, :truncate] are externalized to the I18n resource.
160
+
161
+ == 0.9.7
162
+
163
+ * moved template themes to another repo
164
+ https://github.com/amatsuda/kaminari_themes
165
+
166
+ == 0.9.6
167
+
168
+ * added paginates_per method for setting default per_page value for each model
169
+ in a declarative way
170
+ Example:
171
+ class Article < ActiveRecord::Base
172
+ paginates_per 10
173
+ end
174
+
175
+ == 0.9.5
176
+
177
+ * works on AR 3.0.0 and 3.0.1 now #4 [danillos]
178
+
179
+ == 0.9.4
180
+
181
+ * introduced module based tags
182
+ As a side effect of this internal change, I have to confess that this
183
+ version brings you a slight backward incompatibility on template API.
184
+ If you're using custom templates, be sure to update your existing templates.
185
+ To catch up the new API, you need to update %w[next_url prev_url page_url]
186
+ local variables to simple 'url' like this.
187
+ https://github.com/amatsuda/kaminari/commit/da88729
188
+
189
+ == 0.9.3
190
+
191
+ * improved template detection logic
192
+ When a template for a tag could not be found in the app/views/kaminari/
193
+ directory, it searches the tag's ancestor template files before falling back
194
+ to engine's default template. This may help keeping your custom templates DRY.
195
+
196
+ * simplified bundled template themes
197
+
198
+ == 0.9.2
199
+
200
+ * stop adding extra LF between templates when joining
201
+
202
+ * githubish template theme [maztomo]
203
+
204
+ == 0.9.1
205
+
206
+ * googlish template theme [maztomo]
207
+
208
+ == 0.9.0
209
+
210
+ * added "per_page" to the template local variables #3 [hsbt]
211
+
212
+ * show no contents when the current page is the only page (in other words,
213
+ num_pages == 1) #2 [hsbt]
214
+
215
+ == 0.8.0
216
+
217
+ * using HTML5 <nav> tag rather than <div> for the container tag
218
+
219
+ == 0.7.0
220
+
221
+ * Ajaxified paginator templates
222
+
223
+ == 0.6.0
224
+
225
+ * Hamlized paginator templates
226
+
227
+ == 0.5.0
228
+
229
+ * reset content_for :kaminari_paginator_tags before rendering #1 [hsbt]
230
+
231
+ == 0.4.0
232
+
233
+ * partialize the outer div
234
+
235
+ == 0.3.0
236
+
237
+ * suppress logging when rendering each partial
238
+
239
+ == 0.2.0
240
+
241
+ * default PER_PAGE to 25 [hsbt]
242
+
243
+ == 0.1.0
244
+
245
+ * First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kaminari.gemspec
4
+ gemspec
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,217 @@
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, MongoMapper) 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
37
+
38
+ * MongoMapper 0.9
39
+
40
+ == Install
41
+
42
+ Put this line in your Gemfile:
43
+ gem 'kaminari'
44
+
45
+ Then bundle:
46
+ % bundle
47
+
48
+
49
+ == Usage
50
+
51
+ === Query Basics
52
+
53
+ * the +page+ scope
54
+
55
+ To fetch the 7th page of users (default +per_page+ is 25)
56
+ User.page(7)
57
+
58
+ * the +per+ scope
59
+
60
+ To show a lot more users per each page (change the +per_page+ value)
61
+ User.page(7).per(50)
62
+ 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.
63
+
64
+ === General configuration options
65
+
66
+ You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
67
+ default_per_page # 25 by default
68
+ window # 4 by default
69
+ outer_window # 0 by default
70
+ left # 0 by default
71
+ right # 0 by default
72
+
73
+ There's a handy generator that generates the default configuration file into config/initializers directory.
74
+ Run the following generator command, then edit the generated file.
75
+ % rails g kaminari:config
76
+
77
+ === Configuring default +per_page+ value for each model
78
+
79
+ * +paginates_per+
80
+
81
+ You can specify default +per_page+ value per each model using the following declarative DSL.
82
+ class User < ActiveRecord::Base
83
+ paginates_per 50
84
+ end
85
+
86
+ === Controllers
87
+
88
+ * the page parameter is in <tt>params[:page]</tt>
89
+
90
+ Typically, your controller code will look like this:
91
+ @users = User.order(:name).page params[:page]
92
+
93
+ === Views
94
+
95
+ * the same old helper method
96
+
97
+ Just call the +paginate+ helper:
98
+ <%= paginate @users %>
99
+
100
+ This will render several <tt>?page=N</tt> pagination links surrounded by an HTML5 <+nav+> tag.
101
+
102
+ === Helper Options
103
+
104
+ * specifing the "inner window" size (4 by default)
105
+
106
+ <%= paginate @users, :window => 2 %>
107
+ This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
108
+
109
+ * specifing the "outer window" size (0 by default)
110
+
111
+ <%= paginate @users, :outer_window => 3 %>
112
+ This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
113
+
114
+ * outer window can be separetely specified by +left+, +right+ (0 by default)
115
+
116
+ <%= paginate @users, :left => 1, :right => 3 %>
117
+ This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
118
+
119
+ * changing the parameter name (:+param_name+) for the links
120
+
121
+ <%= paginate @users, :param_name => :pagina %>
122
+ This would modify the query parameter name on each links.
123
+
124
+ * extra parameters (:+params+) for the links
125
+
126
+ <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'} %>
127
+ This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
128
+
129
+ * Ajax links (crazy simple, but works perfectly!)
130
+
131
+ <%= paginate @users, :remote => true %>
132
+ This would add <tt>data-remote="true"</tt> to all the links inside.
133
+
134
+ === I18n and labels
135
+
136
+ 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.
137
+ 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.
138
+
139
+ en:
140
+ views:
141
+ pagination:
142
+ previous: "&laquo; Prev"
143
+ next: "Next &raquo;"
144
+ truncate: "..."
145
+
146
+ === Customizing the pagination helper
147
+
148
+ Kaminari includes a handy template generator.
149
+
150
+ * to edit your paginator
151
+
152
+ Run the generator first,
153
+ % rails g kaminari:views default
154
+
155
+ then edit the partials in your app's <tt>app/views/kaminari/</tt> directory.
156
+
157
+ * for Haml users
158
+
159
+ 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).
160
+
161
+ % rails g kaminari:views default -e haml
162
+
163
+ * themes
164
+
165
+ The generator has the ability to fetch several sample template themes from
166
+ the external repository (https://github.com/amatsuda/kaminari_themes) in
167
+ addition to the bundled "default" one, which will help you creating a nice
168
+ looking paginator.
169
+ % rails g kaminari:views THEME
170
+
171
+ To see the full list of avaliable themes, take a look at the themes repository,
172
+ or just hit the generator without specifying +THEME+ argument.
173
+ % rails g kaminari:views
174
+
175
+ * multiple themes
176
+
177
+ 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.
178
+ % rails g kaminari:views default (skip if you have existing kaminari views)
179
+ % cd app/views/kaminari
180
+ % mkdir my_custom_theme
181
+ % cp _*.html.* my_custom_theme/
182
+
183
+ Next reference that directory when calling the paginate method:
184
+
185
+ <%= paginate @users, :theme => 'my_custom_theme' %>
186
+
187
+ Customize away!
188
+
189
+ Note: if the theme isn't present or none is specified, kaminari will default back to the views included within the gem.
190
+
191
+ === Paginating a generic Array object
192
+
193
+ Kaminari provides an Array wrapper class that adapts a generic Array object to the <tt>paginate</tt> view helper.
194
+ However, the <tt>paginate</tt> helper doesn't automatically handle your Array object (this is an intensional design).
195
+ <tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
196
+ Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
197
+
198
+
199
+ == For more information
200
+
201
+ Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques.
202
+ https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
203
+
204
+
205
+ == Questions, Feedback
206
+
207
+ Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
208
+
209
+
210
+ == Contributing to Kaminari
211
+
212
+ * Fork, fix, then send me a pull request.
213
+
214
+
215
+ == Copyright
216
+
217
+ Copyright (c) 2011 Akira Matsuda. See LICENSE.txt for further details.