kaminari 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

Files changed (87) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +8 -1
  3. data/CHANGELOG +46 -10
  4. data/README.rdoc +14 -3
  5. data/Rakefile +22 -2
  6. data/app/views/kaminari/_first_page.html.erb +1 -1
  7. data/app/views/kaminari/_first_page.html.haml +1 -1
  8. data/app/views/kaminari/_first_page.html.slim +1 -1
  9. data/app/views/kaminari/_gap.html.erb +1 -1
  10. data/app/views/kaminari/_gap.html.haml +1 -1
  11. data/app/views/kaminari/_gap.html.slim +1 -1
  12. data/app/views/kaminari/_last_page.html.erb +1 -1
  13. data/app/views/kaminari/_last_page.html.haml +1 -1
  14. data/app/views/kaminari/_last_page.html.slim +1 -1
  15. data/app/views/kaminari/_next_page.html.erb +1 -1
  16. data/app/views/kaminari/_next_page.html.haml +1 -1
  17. data/app/views/kaminari/_next_page.html.slim +1 -1
  18. data/app/views/kaminari/_page.html.erb +2 -2
  19. data/app/views/kaminari/_page.html.haml +1 -1
  20. data/app/views/kaminari/_page.html.slim +1 -1
  21. data/app/views/kaminari/_paginator.html.erb +1 -1
  22. data/app/views/kaminari/_paginator.html.haml +1 -1
  23. data/app/views/kaminari/_paginator.html.slim +1 -1
  24. data/app/views/kaminari/_prev_page.html.erb +1 -1
  25. data/app/views/kaminari/_prev_page.html.haml +1 -1
  26. data/app/views/kaminari/_prev_page.html.slim +1 -1
  27. data/config/locales/kaminari.yml +9 -0
  28. data/gemfiles/active_record_30.gemfile +7 -0
  29. data/gemfiles/active_record_31.gemfile +7 -0
  30. data/gemfiles/active_record_32.gemfile +7 -0
  31. data/gemfiles/data_mapper_12.gemfile +12 -0
  32. data/gemfiles/mongo_mapper.gemfile +7 -0
  33. data/gemfiles/mongoid_24.gemfile +7 -0
  34. data/gemfiles/mongoid_30.gemfile +7 -0
  35. data/gemfiles/sinatra.gemfile +10 -0
  36. data/kaminari.gemspec +6 -18
  37. data/lib/generators/kaminari/templates/kaminari_config.rb +1 -0
  38. data/lib/kaminari.rb +22 -57
  39. data/lib/kaminari/config.rb +7 -1
  40. data/lib/kaminari/grape.rb +4 -0
  41. data/lib/kaminari/helpers/action_view_extension.rb +84 -13
  42. data/lib/kaminari/helpers/paginator.rb +8 -5
  43. data/lib/kaminari/helpers/sinatra_helpers.rb +25 -6
  44. data/lib/kaminari/helpers/tags.rb +1 -1
  45. data/lib/kaminari/hooks.rb +12 -10
  46. data/lib/kaminari/models/active_record_relation_methods.rb +0 -3
  47. data/lib/kaminari/models/configuration_methods.rb +15 -1
  48. data/lib/kaminari/models/page_scope_methods.rb +6 -2
  49. data/lib/kaminari/models/plucky_criteria_methods.rb +3 -0
  50. data/lib/kaminari/railtie.rb +2 -2
  51. data/lib/kaminari/sinatra.rb +2 -10
  52. data/lib/kaminari/version.rb +1 -1
  53. data/spec/config/config_spec.rb +15 -0
  54. data/spec/fake_app/active_record/config.rb +3 -0
  55. data/spec/{fake_app.rb → fake_app/active_record/models.rb} +7 -34
  56. data/spec/fake_app/data_mapper/config.rb +1 -0
  57. data/spec/fake_app/data_mapper/models.rb +27 -0
  58. data/spec/fake_app/mongo_mapper/config.rb +2 -0
  59. data/spec/fake_app/mongo_mapper/models.rb +9 -0
  60. data/spec/fake_app/mongoid/config.rb +16 -0
  61. data/spec/fake_app/mongoid/models.rb +22 -0
  62. data/spec/fake_app/rails_app.rb +55 -0
  63. data/spec/fake_app/sinatra_app.rb +22 -0
  64. data/spec/fake_gem.rb +0 -2
  65. data/spec/helpers/action_view_extension_spec.rb +192 -45
  66. data/spec/helpers/helpers_spec.rb +8 -8
  67. data/spec/helpers/sinatra_helpers_spec.rb +129 -133
  68. data/spec/helpers/tags_spec.rb +8 -8
  69. data/spec/models/active_record/active_record_relation_methods_spec.rb +30 -0
  70. data/spec/models/active_record/default_per_page_spec.rb +32 -0
  71. data/spec/models/active_record/max_per_page_spec.rb +32 -0
  72. data/spec/models/active_record/scopes_spec.rb +166 -0
  73. data/spec/models/array_spec.rb +7 -7
  74. data/spec/models/data_mapper/data_mapper_spec.rb +155 -0
  75. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +72 -0
  76. data/spec/models/mongoid/mongoid_spec.rb +110 -0
  77. data/spec/requests/users_spec.rb +0 -1
  78. data/spec/spec_helper.rb +20 -18
  79. data/spec/spec_helper_for_sinatra.rb +22 -0
  80. data/spec/support/database_cleaner.rb +4 -1
  81. metadata +93 -141
  82. data/spec/models/active_record_relation_methods_spec.rb +0 -28
  83. data/spec/models/data_mapper_spec.rb +0 -181
  84. data/spec/models/default_per_page_spec.rb +0 -29
  85. data/spec/models/mongo_mapper_spec.rb +0 -82
  86. data/spec/models/mongoid_spec.rb +0 -129
  87. data/spec/models/scopes_spec.rb +0 -163
data/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
1
  *.gem
2
2
  .bundle
3
+ .idea
3
4
  Gemfile.lock
5
+ gemfiles/*.lock
4
6
  pkg/*
5
7
 
6
8
  doc
@@ -1,6 +1,13 @@
1
+ script: "bundle exec rake spec"
2
+
1
3
  rvm:
2
4
  - 1.8.7
3
5
  - 1.9.3
4
6
  - ruby-head
5
7
 
6
- script: bundle exec rake spec
8
+ gemfile:
9
+ - gemfiles/active_record_32.gemfile
10
+ - gemfiles/data_mapper_12.gemfile
11
+ - gemfiles/mongo_mapper.gemfile
12
+ - gemfiles/mongoid_24.gemfile
13
+ - gemfiles/sinatra.gemfile
data/CHANGELOG CHANGED
@@ -1,3 +1,39 @@
1
+ == 0.14.0
2
+
3
+ * Grape framework support! #218 [mrplum]
4
+
5
+ * Mongoid 3 ready! #238 [shingara]
6
+
7
+ * Added link_to_previous_page helper #191 [timgremore]
8
+
9
+ * Added helper to generate rel="next" and rel="prev" link tags for SEO #200
10
+ [joe1chen]
11
+
12
+ * Added `max_per_page` configuration option #274 [keiko0713]
13
+ This would be useful for the case when you are using user input `per_page`
14
+ value but want to impose the upper bound.
15
+
16
+ * Added I18n to page_entries_info #207 [plribeiro3000]
17
+
18
+ * Changed method name "num_pages" to "total_pages"
19
+ num_pages" is still available as an alias of "total_pages", but will be
20
+ deprecated or removed in some future version.
21
+
22
+ * Changed the way page_entries_info behave so it can show appropriate names
23
+ for models with namespace #207 [plribeiro3000]
24
+
25
+ * Added html_safe to page_entries_info helper #190 [lucapette]
26
+
27
+ * Fixed displayed number of items on each page w/ Mongoid 2.4.x and
28
+ MongoMapper #194 [dblock]
29
+
30
+ * Removed a unused local variable from templates from default tamplate #245 [juno]
31
+
32
+ * Fixed page_entry_info to use the value of `entry_name` option when given
33
+ collection is empty or a PaginatableArray #265, #277 [eitoball]
34
+
35
+ * Added require 'dm-aggregates' in DataMapper hook #259 [shingara]
36
+
1
37
  == 0.13.0
2
38
 
3
39
  * Rails 3.2 ready! #180 [slbug]
@@ -23,7 +59,7 @@ windows #154 [cbeer]
23
59
  * Added `link_to_next_page` helper method that simply links to the next page
24
60
  Example:
25
61
  <%= link_to_next_page @posts, 'More' %>
26
- #=> <a href="/posts?page=7" rel="next">More</a>
62
+ #=> <a href="/posts?page=7" rel="next">More</a>
27
63
 
28
64
  * Let one override the `rel` attribute for 'link_to_next_page` helper #177
29
65
  [webmat]
@@ -33,7 +69,7 @@ RSolr #141 [samdalton]
33
69
 
34
70
  * Changed `Kaminari.paginate_array` API to take a Hash `options`
35
71
  And specifying :limit & :offset immediately builds a pagination ready object
36
- Example:
72
+ Example:
37
73
  # the following two are equivalent. Use whichever you like
38
74
  Kaminari.paginate_array((1..100).to_a, limit: 10, offset: 10)
39
75
  Kaminari.paginate_array((1..100).to_a).page(2).per(10)
@@ -45,8 +81,8 @@ RSolr #141 [samdalton]
45
81
  * Made the pagination method name (defaulted to `page`) configurable #57, #162
46
82
  Example:
47
83
  # you can use the config file and its generator for this
48
- Kaminari.config.page_method_name = :paging
49
- Article.paging(3).per(30)
84
+ Kaminari.config.page_method_name = :paging
85
+ Article.paging(3).per(30)
50
86
 
51
87
  * Only add extensions to direct descendents of ActiveRecord::Base #108
52
88
  [seejohnrun]
@@ -193,10 +229,10 @@ from ActiveRecord::Base.inherited #34 [rolftimmermans]
193
229
  * Moved the whole pagination logic to the paginator partial so that users can
194
230
  touch it
195
231
  Note: You need to update your _paginator.html.* if you've already customized
196
- it. If you haven't overridden _paginator.html.* files, then probably
197
- there're nothing you have to do.
198
- See this commit for the example:
199
- https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
232
+ it. If you haven't overridden _paginator.html.* files, then probably
233
+ there're nothing you have to do.
234
+ See this commit for the example:
235
+ https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
200
236
 
201
237
  == 0.9.10
202
238
 
@@ -210,8 +246,8 @@ touch it
210
246
 
211
247
  * :params option for the helper [yomukaku_memo]
212
248
  You can override each link's url_for option by this option
213
- Example:
214
- = paginate @users, :params => {:controller => 'users', :action => 'index2'}
249
+ Example:
250
+ = paginate @users, :params => {:controller => 'users', :action => 'index2'}
215
251
 
216
252
  * refactor tags
217
253
 
@@ -73,6 +73,7 @@ Then bundle:
73
73
 
74
74
  You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
75
75
  default_per_page # 25 by default
76
+ max_per_page # nil by default
76
77
  window # 4 by default
77
78
  outer_window # 0 by default
78
79
  left # 0 by default
@@ -98,6 +99,16 @@ Run the following generator command, then edit the generated file.
98
99
  paginates_per 50
99
100
  end
100
101
 
102
+ === Configuring max +per_page+ value for each model
103
+
104
+ * +max_paginates_per+
105
+
106
+ You can specify max +per_page+ value per each model using the following declarative DSL.
107
+ If the variable that specified via +per+ scope is more than this variable, max +paginates_per+ is used instead of it. Default value is nil, which means you are not imposing any max +per_page+ value.
108
+ class User < ActiveRecord::Base
109
+ max_paginates_per 100
110
+ end
111
+
101
112
  === Controllers
102
113
 
103
114
  * the page parameter is in <tt>params[:page]</tt>
@@ -151,7 +162,7 @@ Run the following generator command, then edit the generated file.
151
162
  <%= paginate @users, :remote => true %>
152
163
  This would add <tt>data-remote="true"</tt> to all the links inside.
153
164
 
154
- * the +link_to_next_page+ helper method
165
+ * the +link_to_next_page+ and +link_to_previous_page+ helper method
155
166
 
156
167
  <%= link_to_next_page @items, 'Next Page' %>
157
168
  This simply renders a link to the next page. This would be helpful for creating "Twitter like" pagination feature.
@@ -227,8 +238,8 @@ However, the <tt>paginate</tt> helper doesn't automatically handle your Array ob
227
238
  <tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
228
239
  Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
229
240
 
230
- 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.
231
-
241
+ 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:
242
+ Kaminari.paginate_array([], total_count: 145).page(params[:page]).per(10)
232
243
 
233
244
  == Creating friendly URLs and caching
234
245
 
data/Rakefile CHANGED
@@ -5,13 +5,33 @@ Bundler::GemHelper.install_tasks
5
5
 
6
6
  require 'rspec/core'
7
7
  require 'rspec/core/rake_task'
8
+
8
9
  RSpec::Core::RakeTask.new(:spec) do |spec|
9
10
  spec.pattern = FileList['spec/**/*_spec.rb']
10
11
  end
11
12
 
12
- task :default => :spec
13
+ task :default => "spec:all"
14
+
15
+ namespace :spec do
16
+ %w(active_record_32 active_record_31 active_record_30 data_mapper_12 mongoid_30 mongoid_24 mongo_mapper sinatra).each do |gemfile|
17
+ desc "Run Tests against #{gemfile}"
18
+ task gemfile do
19
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
20
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
21
+ end
22
+ end
23
+
24
+ desc "Run Tests against all ORMs"
25
+ task :all do
26
+ %w(active_record_32 active_record_31 active_record_30 data_mapper_12 mongoid_30 mongoid_24 mongo_mapper sinatra).each do |gemfile|
27
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
28
+ sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
29
+ end
30
+ end
31
+ end
32
+
33
+ require 'rdoc/task'
13
34
 
14
- require 'rake/rdoctask'
15
35
  Rake::RDocTask.new do |rdoc|
16
36
  require 'kaminari/version'
17
37
 
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url: url to the first page
4
4
  current_page: a page object for the currently displayed page
5
- num_pages: total number of pages
5
+ total_pages: total number of pages
6
6
  per_page: number of items to fetch per page
7
7
  remote: data-remote
8
8
  -%>
@@ -2,7 +2,7 @@
2
2
  -# available local variables
3
3
  -# url: url to the first page
4
4
  -# current_page: a page object for the currently displayed page
5
- -# num_pages: total number of pages
5
+ -# total_pages: total number of pages
6
6
  -# per_page: number of items to fetch per page
7
7
  -# remote: data-remote
8
8
  %span.first
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url : url to the first page
4
4
  current_page : a page object for the currently displayed page
5
- num_pages : total number of pages
5
+ total_pages : total number of pages
6
6
  per_page : number of items to fetch per page
7
7
  remote : data-remote
8
8
  span.first
@@ -1,7 +1,7 @@
1
1
  <%# Non-link tag that stands for skipped pages...
2
2
  - available local variables
3
3
  current_page: a page object for the currently displayed page
4
- num_pages: total number of pages
4
+ total_pages: total number of pages
5
5
  per_page: number of items to fetch per page
6
6
  remote: data-remote
7
7
  -%>
@@ -1,7 +1,7 @@
1
1
  -# Non-link tag that stands for skipped pages...
2
2
  -# available local variables
3
3
  -# current_page: a page object for the currently displayed page
4
- -# num_pages: total number of pages
4
+ -# total_pages: total number of pages
5
5
  -# per_page: number of items to fetch per page
6
6
  -# remote: data-remote
7
7
  %span.page.gap
@@ -1,7 +1,7 @@
1
1
  / Non-link tag that stands for skipped pages...
2
2
  - available local variables
3
3
  current_page : a page object for the currently displayed page
4
- num_pages : total number of pages
4
+ total_pages : total number of pages
5
5
  per_page : number of items to fetch per page
6
6
  remote : data-remote
7
7
  span.page.gap
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url: url to the last page
4
4
  current_page: a page object for the currently displayed page
5
- num_pages: total number of pages
5
+ total_pages: total number of pages
6
6
  per_page: number of items to fetch per page
7
7
  remote: data-remote
8
8
  -%>
@@ -2,7 +2,7 @@
2
2
  -# available local variables
3
3
  -# url: url to the last page
4
4
  -# current_page: a page object for the currently displayed page
5
- -# num_pages: total number of pages
5
+ -# total_pages: total number of pages
6
6
  -# per_page: number of items to fetch per page
7
7
  -# remote: data-remote
8
8
  %span.last
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url : url to the last page
4
4
  current_page : a page object for the currently displayed page
5
- num_pages : total number of pages
5
+ total_pages : total number of pages
6
6
  per_page : number of items to fetch per page
7
7
  remote : data-remote
8
8
  span.last
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url: url to the next page
4
4
  current_page: a page object for the currently displayed page
5
- num_pages: total number of pages
5
+ total_pages: total number of pages
6
6
  per_page: number of items to fetch per page
7
7
  remote: data-remote
8
8
  -%>
@@ -2,7 +2,7 @@
2
2
  -# available local variables
3
3
  -# url: url to the next page
4
4
  -# current_page: a page object for the currently displayed page
5
- -# num_pages: total number of pages
5
+ -# total_pages: total number of pages
6
6
  -# per_page: number of items to fetch per page
7
7
  -# remote: data-remote
8
8
  %span.next
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url : url to the next page
4
4
  current_page : a page object for the currently displayed page
5
- num_pages : total number of pages
5
+ total_pages : total number of pages
6
6
  per_page : number of items to fetch per page
7
7
  remote : data-remote
8
8
  span.next
@@ -3,10 +3,10 @@
3
3
  page: a page object for "this" page
4
4
  url: url to this page
5
5
  current_page: a page object for the currently displayed page
6
- num_pages: total number of pages
6
+ total_pages: total number of pages
7
7
  per_page: number of items to fetch per page
8
8
  remote: data-remote
9
9
  -%>
10
10
  <span class="page<%= ' current' if page.current? %>">
11
- <%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
11
+ <%= link_to_unless page.current?, page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
12
12
  </span>
@@ -3,7 +3,7 @@
3
3
  -# page: a page object for "this" page
4
4
  -# url: url to this page
5
5
  -# current_page: a page object for the currently displayed page
6
- -# num_pages: total number of pages
6
+ -# total_pages: total number of pages
7
7
  -# per_page: number of items to fetch per page
8
8
  -# remote: data-remote
9
9
  %span{:class => "page#{' current' if page.current?}"}
@@ -3,7 +3,7 @@
3
3
  page : a page object for "this" page
4
4
  url : url to this page
5
5
  current_page : a page object for the currently displayed page
6
- num_pages : total number of pages
6
+ total_pages : total number of pages
7
7
  per_page : number of items to fetch per page
8
8
  remote : data-remote
9
9
  span class="page#{' current' if page.current?}"
@@ -1,7 +1,7 @@
1
1
  <%# The container tag
2
2
  - available local variables
3
3
  current_page: a page object for the currently displayed page
4
- num_pages: total number of pages
4
+ total_pages: total number of pages
5
5
  per_page: number of items to fetch per page
6
6
  remote: data-remote
7
7
  paginator: the paginator that renders the pagination tags inside
@@ -1,7 +1,7 @@
1
1
  -# The container tag
2
2
  -# available local variables
3
3
  -# current_page: a page object for the currently displayed page
4
- -# num_pages: total number of pages
4
+ -# total_pages: total number of pages
5
5
  -# per_page: number of items to fetch per page
6
6
  -# remote: data-remote
7
7
  -# paginator: the paginator that renders the pagination tags inside
@@ -1,7 +1,7 @@
1
1
  / The container tag
2
2
  - available local variables
3
3
  current_page : a page object for the currently displayed page
4
- num_pages : total number of pages
4
+ total_pages : total number of pages
5
5
  per_page : number of items to fetch per page
6
6
  remote : data-remote
7
7
  paginator : the paginator that renders the pagination tags inside
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url: url to the previous page
4
4
  current_page: a page object for the currently displayed page
5
- num_pages: total number of pages
5
+ total_pages: total number of pages
6
6
  per_page: number of items to fetch per page
7
7
  remote: data-remote
8
8
  -%>
@@ -2,7 +2,7 @@
2
2
  -# available local variables
3
3
  -# url: url to the previous page
4
4
  -# current_page: a page object for the currently displayed page
5
- -# num_pages: total number of pages
5
+ -# total_pages: total number of pages
6
6
  -# per_page: number of items to fetch per page
7
7
  -# remote: data-remote
8
8
  %span.prev
@@ -2,7 +2,7 @@
2
2
  - available local variables
3
3
  url : url to the previous page
4
4
  current_page : a page object for the currently displayed page
5
- num_pages : total number of pages
5
+ total_pages : total number of pages
6
6
  per_page : number of items to fetch per page
7
7
  remote : data-remote
8
8
  span.prev
@@ -8,3 +8,12 @@ en:
8
8
  previous: "&lsaquo; Prev"
9
9
  next: "Next &rsaquo;"
10
10
  truncate: "..."
11
+ helpers:
12
+ page_entries_info:
13
+ one_page:
14
+ display_entries:
15
+ zero: "No %{entry_name} found"
16
+ one: "Displaying <b>1</b> %{entry_name}"
17
+ other: "Displaying <b>all %{count}</b> %{entry_name}"
18
+ more_pages:
19
+ display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'railties', '>= 3.0.13'
4
+ gem 'activerecord', '>= 3.0.13', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'railties', '>= 3.1.5'
4
+ gem 'activerecord', '>= 3.1.5', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'railties', '>= 3.2.3'
4
+ gem 'activerecord', '>= 3.2.3', :require => 'active_record'
5
+ gem 'rspec-rails', '>= 2.0'
6
+
7
+ gemspec :path => '../'