kaminari 0.9.13 → 0.10.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.

data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ == 0.10.0
2
+
3
+ * Railtie initializer name is "kaminari" from now
4
+ * Changed bundler settings to work both on 1.9.2 and 1.8.7 #12 [l15n]
5
+ * Fixed bugs encountered when running specs on Ruby 1.9.2 #12 [l15n]
6
+ * Clean up documentation (formatting and editing) #12 [l15n]
7
+ * Use Proc.new instead of lambda for scoped_options #13 [l15n]
8
+ * Use AS hooks for loading AR #14 [hasimo]
9
+ * Refactor scope definition with Concerns #15 [l15n]
10
+ * Ensure output_buffer is always initialized #11 [kichiro]
11
+
1
12
  == 0.9.13
2
13
 
3
14
  * Added Mongoid support #5 [juno, hibariya]
data/Gemfile CHANGED
@@ -19,7 +19,12 @@ group :development do
19
19
  gem 'arel', :git => 'git://github.com/rails/arel.git'
20
20
  gem 'rspec-rails', '>= 2.5.0'
21
21
  gem 'sqlite3', '>= 1.3.3'
22
- gem 'ruby-debug'
23
22
  gem 'mongoid', '2.0.0.rc.7'
24
23
  gem 'bson_ext', '~> 1.2'
24
+ # platforms :mri_18 do
25
+ # gem 'ruby-debug'
26
+ # end
27
+ # platforms :mri_19 do
28
+ # gem 'ruby-debug19'
29
+ # end
25
30
  end
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
 
13
13
  GIT
14
14
  remote: git://github.com/rails/rails.git
15
- revision: 829de9d98e59f9b083ed96a9031cd9841c83ae47
15
+ revision: 289cc15f1a89a179116f67e5f666f4ff6d645f03
16
16
  specs:
17
17
  actionmailer (3.1.0.beta)
18
18
  actionpack (= 3.1.0.beta)
@@ -73,10 +73,9 @@ GEM
73
73
  rack-test (>= 0.5.4)
74
74
  selenium-webdriver (>= 0.0.27)
75
75
  xpath (~> 0.1.3)
76
- celerity (0.8.7)
76
+ celerity (0.8.8)
77
77
  childprocess (0.1.7)
78
78
  ffi (~> 0.6.3)
79
- columnize (0.3.2)
80
79
  culerity (0.2.15)
81
80
  diff-lcs (1.1.2)
82
81
  erubis (2.6.6)
@@ -89,9 +88,7 @@ GEM
89
88
  bundler (~> 1.0.0)
90
89
  git (>= 1.2.5)
91
90
  rake
92
- ruby-debug
93
91
  json_pure (1.5.1)
94
- linecache (0.43)
95
92
  mail (2.2.15)
96
93
  activesupport (>= 2.3.6)
97
94
  i18n (>= 0.4.0)
@@ -129,13 +126,8 @@ GEM
129
126
  activesupport (~> 3.0)
130
127
  railties (~> 3.0)
131
128
  rspec (~> 2.5.0)
132
- ruby-debug (0.10.4)
133
- columnize (>= 0.1)
134
- ruby-debug-base (~> 0.10.4.0)
135
- ruby-debug-base (0.10.4)
136
- linecache (>= 0.3)
137
129
  rubyzip (0.9.4)
138
- selenium-webdriver (0.1.2)
130
+ selenium-webdriver (0.1.3)
139
131
  childprocess (~> 0.1.5)
140
132
  ffi (~> 0.6.3)
141
133
  json_pure
@@ -167,6 +159,5 @@ DEPENDENCIES
167
159
  rr (>= 1.0.2)
168
160
  rspec (>= 2.5.0)
169
161
  rspec-rails (>= 2.5.0)
170
- ruby-debug
171
162
  sqlite3 (>= 1.3.3)
172
163
  steak (>= 1.1.0)
data/README.rdoc CHANGED
@@ -1,35 +1,35 @@
1
1
  = Kaminari
2
2
 
3
- A Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3
3
+ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails 3
4
4
 
5
5
 
6
6
  == Features
7
7
 
8
- * Clean
9
- Does not globally pollute Array, Hash, Object or AR::Base.
8
+ === Clean
9
+ Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
10
10
 
11
- * Easy to use
12
- Just bundle the gem, then your models are ready to be paginated. No configuration. Don't have to define anything in your models or helpers.
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
13
 
14
- * Scope based simple API
14
+ === Simple scope-based API
15
15
  Everything is method chainable with less "Hasheritis". You know, that's the Rails 3 way.
16
- No special collection class or something for the paginated values but uses a general AR::Relation instance. So, of course you can chain any other conditions before or after the paginator scope.
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
17
 
18
- * Engine based I18n aware customizable 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 or style or whatever by overriding partial templates.
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
20
 
21
- * ORM, template engine agnostic
21
+ === ORM & template engine agnostic
22
22
  Kaminari supports multiple ORMs (ActiveRecord, Mongoid) and multiple template engines (ERB, Haml).
23
23
 
24
- * Modern
25
- The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports the Rails 3 unobtrusive Ajax.
24
+ === Modern
25
+ The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
26
26
 
27
27
 
28
28
  == Supported versions
29
29
 
30
- * Ruby 1.8.7 and 1.9.2 and 1.9.3
30
+ * Ruby 1.8.7, 1.9.2, 1.9.3
31
31
 
32
- * Rails 3.0.x and 3.1
32
+ * Rails 3.0.x, 3.1
33
33
 
34
34
  * Haml 3
35
35
 
@@ -43,68 +43,77 @@ Put this line in your Gemfile:
43
43
  Then bundle:
44
44
  % bundle
45
45
 
46
-
47
46
  == Usage
48
47
 
49
48
  === Query Basics
50
49
 
51
- * the :page scope
52
- To fetch the 7th page of the users (per_page = 25 by default)
53
- User.page(7)
50
+ * the +:page+ scope
51
+
52
+ To fetch the 7th page of users (default +per_page+ is 25)
53
+ User.page(7)
54
+
55
+ * the +:per+ scope
56
+
57
+ To show a lot more users per each page (change the +per_page+ value)
58
+ User.page(7).per(50)
59
+ Note that the +:per+ scope is not directly defined on the models but is just a method defined on the page scope. This is absolutely reasonable because you will never actually use +per_page+ without specifying the +page+ number.
54
60
 
55
- * the :per scope
56
- To show a lot more users per each page (change the per_page value)
57
- User.page(7).per(50)
58
- 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.
61
+ === Configuring default +per_page+ value for each model
59
62
 
60
- === Configuring default per_page value for each model
63
+ * +paginates_per+
61
64
 
62
- * paginates_per
63
- You can specify default per_page value per each model using the following declarative DSL.
64
- class User < ActiveRecord::Base
65
- paginates_per 50
66
- end
65
+ You can specify default +per_page+ value per each model using the following declarative DSL.
66
+ class User < ActiveRecord::Base
67
+ paginates_per 50
68
+ end
67
69
 
68
70
  === Controllers
69
71
 
70
- * the page parameter is in params[:page]
71
- Typically, your controller code will look like this:
72
- @users = User.order(:name).page params[:page]
72
+ * the page parameter is in <tt>params[:page]</tt>
73
+
74
+ Typically, your controller code will look like this:
75
+ @users = User.order(:name).page params[:page]
73
76
 
74
77
  === Views
75
78
 
76
79
  * the same old helper method
77
- Just call the "paginate" helper:
78
- <%= paginate @users %>
79
80
 
80
- This will render several "?page=N" pagination links surrounded by an HTML5 <nav> tag.
81
+ Just call the +paginate+ helper:
82
+ <%= paginate @users %>
83
+
84
+ This will render several <tt>?page=N</tt> pagination links surrounded by an HTML5 <+nav+> tag.
81
85
 
82
86
  === Helper Options
83
87
 
84
88
  * specifing the "inner window" size (4 by default)
85
- This would output something like ... 5 6 7 8 9 ... when 7 is the current page.
86
- <%= paginate @users, :window => 2 %>
89
+
90
+ This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
91
+ <%= paginate @users, :window => 2 %>
87
92
 
88
93
  * specifing the "outer window" size (1 by default)
89
- This would output something like 1 2 3 4 ...(snip)... 17 18 19 20 while having 20 pages in total.
90
- <%= paginate @users, :outer_window => 3 %>
91
94
 
92
- * outer window can be separetely specified by "left", "right" (1 by default)
93
- This would output something like 1 ...(snip)... 18 19 20 while having 20 pages in total.
94
- <%= paginate @users, :left => 0, :right => 2 %>
95
+ This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
96
+ <%= paginate @users, :outer_window => 3 %>
95
97
 
96
- * extra parameters (:params) for the links
97
- This would modify each link's url_option. :controller and :action might be the keys in common.
98
- <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
98
+ * outer window can be separetely specified by +left+ +right+ (1 by default)
99
+
100
+ This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
101
+ <%= paginate @users, :left => 0, :right => 2 %>
102
+
103
+ * extra parameters (+:params+) for the links
104
+
105
+ This would modify each link's +url_option+. +:controller+ and +:action+ might be the keys in common.
106
+ <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
99
107
 
100
108
  * Ajax links (crazy simple, but works perfectly!)
101
- This would add data-remote="true" to all the links inside.
102
- <%= paginate @users, :remote => true %>
109
+
110
+ This would add <tt>data-remote="true"</tt> to all the links inside.
111
+ <%= paginate @users, :remote => true %>
103
112
 
104
113
  === I18n and labels
105
114
 
106
115
  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.
107
- 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.
116
+ 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.
108
117
 
109
118
  en:
110
119
  views:
@@ -118,22 +127,28 @@ Keys and the default values are the following. You can override them by adding t
118
127
  Kaminari includes a handy template generator.
119
128
 
120
129
  * to edit your paginator
121
- Run the generator first,
130
+
131
+ Run the generator first,
122
132
  % rails g kaminari:views default
123
133
 
124
- then edit the partials in your app's app/views/kaminari/ directory.
134
+ then edit the partials in your app's <tt>app/views/kaminari/</tt> directory.
125
135
 
126
136
  * for Haml users
127
- Haml templates generator is also available by adding "-e haml" option (this would actually be automatically invoked while the default template_engine is set to Haml).
137
+ 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).
128
138
 
129
139
  % rails g kaminari:views default -e haml
130
140
 
131
141
  * themes
132
- 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.
133
- % rails g kaminari:views THEME
134
142
 
135
- To see the full list of avaliable themes, take a look at the themes repository, or just hit the generator without specifying THEME argument.
136
- % rails g kaminari:views
143
+ The generator has the ability to fetch several sample template themes from
144
+ the external repository (https://github.com/amatsuda/kaminari_themes) in
145
+ addition to the bundled "default" one, which will help you creating a nice
146
+ looking paginator.
147
+ % rails g kaminari:views THEME
148
+
149
+ To see the full list of avaliable themes, take a look at the themes repository,
150
+ or just hit the generator without specifying +THEME+ argument.
151
+ % rails g kaminari:views
137
152
 
138
153
 
139
154
  == For more information
@@ -141,7 +156,7 @@ To see the full list of avaliable themes, take a look at the themes repository,
141
156
  Check out Kaminari recipes on the GitHub Wiki for more advanced tips and techniques.
142
157
  https://github.com/amatsuda/kaminari/wiki/Kaminari-recipes
143
158
 
144
- == Questions, Feedbacks
159
+ == Questions, Feedback
145
160
 
146
161
  Feel free to message me on Github (amatsuda) or Twitter (@a_matsuda) ☇☇☇ :)
147
162
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "kaminari"
18
18
  gem.homepage = "http://github.com/amatsuda/kaminari"
19
19
  gem.license = "MIT"
20
- gem.summary = 'A pagnation engine plugin for Rails 3'
20
+ gem.summary = 'A pagination engine plugin for Rails 3'
21
21
  gem.description = 'Kaminari is a Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3'
22
22
  gem.email = "ronnie@dio.jp"
23
23
  gem.authors = ["Akira Matsuda"]
@@ -51,6 +51,6 @@ Rake::RDocTask.new do |rdoc|
51
51
  rdoc.rdoc_files.include('lib/**/*.rb')
52
52
  end
53
53
 
54
- task :test do
55
- Rake::Task[:spec].invoke
56
- end
54
+ task :test do
55
+ Rake::Task[:spec].invoke
56
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.13
1
+ 0.10.0
data/kaminari.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kaminari}
8
- s.version = "0.9.13"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Akira Matsuda"]
12
- s.date = %q{2011-02-18}
12
+ s.date = %q{2011-02-21}
13
13
  s.description = %q{Kaminari is a Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3}
14
14
  s.email = %q{ronnie@dio.jp}
15
15
  s.extra_rdoc_files = [
@@ -51,12 +51,17 @@ Gem::Specification.new do |s|
51
51
  "kaminari.gemspec",
52
52
  "lib/generators/kaminari/views_generator.rb",
53
53
  "lib/kaminari.rb",
54
- "lib/kaminari/active_record_extension.rb",
55
54
  "lib/kaminari/engine.rb",
56
- "lib/kaminari/helpers.rb",
57
- "lib/kaminari/mongoid_extension.rb",
55
+ "lib/kaminari/helpers/action_view_extension.rb",
56
+ "lib/kaminari/helpers/helpers.rb",
57
+ "lib/kaminari/helpers/tags.rb",
58
+ "lib/kaminari/models/active_record_extension.rb",
59
+ "lib/kaminari/models/active_record_relation_methods.rb",
60
+ "lib/kaminari/models/configuration_methods.rb",
61
+ "lib/kaminari/models/mongoid_criteria_methods.rb",
62
+ "lib/kaminari/models/mongoid_extension.rb",
63
+ "lib/kaminari/models/page_scope_methods.rb",
58
64
  "lib/kaminari/railtie.rb",
59
- "lib/kaminari/tags.rb",
60
65
  "spec/acceptance/acceptance_helper.rb",
61
66
  "spec/acceptance/support/helpers.rb",
62
67
  "spec/acceptance/support/paths.rb",
@@ -74,7 +79,7 @@ Gem::Specification.new do |s|
74
79
  s.licenses = ["MIT"]
75
80
  s.require_paths = ["lib"]
76
81
  s.rubygems_version = %q{1.5.2}
77
- s.summary = %q{A pagnation engine plugin for Rails 3}
82
+ s.summary = %q{A pagination engine plugin for Rails 3}
78
83
  s.test_files = [
79
84
  "spec/acceptance/acceptance_helper.rb",
80
85
  "spec/acceptance/support/helpers.rb",
@@ -106,7 +111,6 @@ Gem::Specification.new do |s|
106
111
  s.add_development_dependency(%q<arel>, [">= 0"])
107
112
  s.add_development_dependency(%q<rspec-rails>, [">= 2.5.0"])
108
113
  s.add_development_dependency(%q<sqlite3>, [">= 1.3.3"])
109
- s.add_development_dependency(%q<ruby-debug>, [">= 0"])
110
114
  s.add_development_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
111
115
  s.add_development_dependency(%q<bson_ext>, ["~> 1.2"])
112
116
  s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
@@ -123,7 +127,6 @@ Gem::Specification.new do |s|
123
127
  s.add_dependency(%q<arel>, [">= 0"])
124
128
  s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
125
129
  s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
126
- s.add_dependency(%q<ruby-debug>, [">= 0"])
127
130
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
128
131
  s.add_dependency(%q<bson_ext>, ["~> 1.2"])
129
132
  s.add_dependency(%q<rails>, [">= 3.0.0"])
@@ -141,7 +144,6 @@ Gem::Specification.new do |s|
141
144
  s.add_dependency(%q<arel>, [">= 0"])
142
145
  s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
143
146
  s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
144
- s.add_dependency(%q<ruby-debug>, [">= 0"])
145
147
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
146
148
  s.add_dependency(%q<bson_ext>, ["~> 1.2"])
147
149
  s.add_dependency(%q<rails>, [">= 3.0.0"])
@@ -0,0 +1,24 @@
1
+ module Kaminari
2
+ module ActionViewExtension
3
+ extend ActiveSupport::Concern
4
+ module InstanceMethods
5
+ # = Helpers
6
+ #
7
+ # A helper that renders the pagination links.
8
+ #
9
+ # <%= paginate @articles %>
10
+ #
11
+ # ==== Options
12
+ # * <tt>:window</tt> - The "inner window" size (2 by default).
13
+ # * <tt>:outer_window</tt> - The "outer window" size (1 by default).
14
+ # * <tt>:left</tt> - The "left outer window" size (1 by default).
15
+ # * <tt>:right</tt> - The "right outer window" size (1 by default).
16
+ # * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
17
+ # * <tt>:remote</tt> - Ajax? (false by default)
18
+ # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
19
+ def paginate(scope, options = {}, &block)
20
+ Kaminari::Helpers::PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :remote => false)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -75,23 +75,5 @@ module Kaminari
75
75
  end
76
76
  end
77
77
  end
78
-
79
- # = Helpers
80
- #
81
- # A helper that renders the pagination links.
82
- #
83
- # <%= paginate @articles %>
84
- #
85
- # ==== Options
86
- # * <tt>:window</tt> - The "inner window" size (2 by default).
87
- # * <tt>:outer_window</tt> - The "outer window" size (1 by default).
88
- # * <tt>:left</tt> - The "left outer window" size (1 by default).
89
- # * <tt>:right</tt> - The "right outer window" size (1 by default).
90
- # * <tt>:params</tt> - url_for parameters for the links (:controller, :action, etc.)
91
- # * <tt>:remote</tt> - Ajax? (false by default)
92
- # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
93
- def paginate(scope, options = {}, &block)
94
- PaginationRenderer.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :remote => false)
95
- end
96
78
  end
97
79
  end
@@ -73,7 +73,7 @@ module Kaminari
73
73
  def initialize(template, window_options) #:nodoc:
74
74
  @template, @options = template, window_options.reverse_merge(template.options)
75
75
  # so that this instance can actually "render". Black magic?
76
- @output_buffer = @template.output_buffer
76
+ @output_buffer = @template.output_buffer || ActionView::OutputBuffer.new
77
77
  end
78
78
 
79
79
  # render given block as a view template
@@ -174,6 +174,7 @@ module Kaminari
174
174
  module Link
175
175
  include Renderable
176
176
  include Page
177
+ # the link's href
177
178
  def url
178
179
  page_url_for page
179
180
  end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), 'active_record_relation_methods')
2
+ module Kaminari
3
+ module ActiveRecordExtension
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ def self.inherited(kls) #:nodoc:
7
+ # TERRIBLE HORRIBLE NO GOOD VERY BAD HACK: inheritable_attributes is not yet set here on AR 3.0
8
+ unless kls.default_scoping
9
+ new_inheritable_attributes = Hash[inheritable_attributes.map do |key, value|
10
+ [key, value.duplicable? ? value.dup : value]
11
+ end]
12
+ kls.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
13
+ end
14
+
15
+ kls.class_eval do
16
+ include Kaminari::ConfigurationMethods
17
+
18
+ # Fetch the values at the specified page number
19
+ # Model.page(5)
20
+ scope :page, Proc.new {|num|
21
+ limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
22
+ } do
23
+ include Kaminari::ActiveRecordRelationMethods
24
+ include Kaminari::PageScopeMethods
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module Kaminari
2
+ module ActiveRecordRelationMethods
3
+ extend ActiveSupport::Concern
4
+ module InstanceMethods
5
+ def total_count #:nodoc:
6
+ except(:offset, :limit).count
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Kaminari
2
+ module ConfigurationMethods
3
+ extend ActiveSupport::Concern
4
+ module ClassMethods
5
+ # Overrides the default per_page value per model
6
+ # class Article < ActiveRecord::Base
7
+ # paginates_per 10
8
+ # end
9
+ def paginates_per(val)
10
+ @_default_per_page = val
11
+ end
12
+
13
+ # This model's default per_page value
14
+ # returns 25 unless explicitly overridden via <tt>paginates_per</tt>
15
+ def default_per_page
16
+ @_default_per_page || Kaminari::DEFAULT_PER_PAGE
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Kaminari
2
+ module MongoidCriteriaMethods
3
+ extend ActiveSupport::Concern
4
+ module InstanceMethods
5
+ def limit_value #:nodoc:
6
+ options[:limit]
7
+ end
8
+
9
+ def offset_value #:nodoc:
10
+ options[:skip]
11
+ end
12
+
13
+ def total_count #:nodoc:
14
+ count
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'mongoid_criteria_methods')
2
+ module Kaminari
3
+ module MongoidExtension
4
+ module Criteria
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ delegate :page, :per, :num_pages, :current_page, :limit_value, :offset_value, :pagination_count, :to => '@klass'
9
+ end
10
+ end
11
+
12
+ module Document
13
+ extend ActiveSupport::Concern
14
+ include Kaminari::ConfigurationMethods
15
+
16
+ included do
17
+ # Fetch the values at the specified page number
18
+ # Model.page(5)
19
+ scope :page, Proc.new {|num|
20
+ limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
21
+ } do
22
+ include Kaminari::MongoidCriteriaMethods
23
+ include Kaminari::PageScopeMethods
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Kaminari
2
+ module PageScopeMethods
3
+ extend ActiveSupport::Concern
4
+ module InstanceMethods
5
+ # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
6
+ # Model.page(3).per(10)
7
+ def per(num)
8
+ if (n = num.to_i) <= 0
9
+ self
10
+ else
11
+ limit(n).offset(offset_value / limit_value * n)
12
+ end
13
+ end
14
+
15
+ # Total number of pages
16
+ def num_pages
17
+ (total_count.to_f / limit_value).ceil
18
+ end
19
+
20
+ # Current page number
21
+ def current_page
22
+ (offset_value / limit_value) + 1
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,24 +1,28 @@
1
1
  require 'rails'
2
- require 'action_view'
3
2
  # ensure ORMs are loaded *before* initializing Kaminari
4
- begin; require 'active_record'; rescue LoadError; end
5
3
  begin; require 'mongoid'; rescue LoadError; end
6
4
 
7
- require File.join(File.dirname(__FILE__), 'helpers')
5
+ require File.join(File.dirname(__FILE__), 'helpers/action_view_extension')
6
+ require File.join(File.dirname(__FILE__), 'helpers/helpers')
7
+ require File.join(File.dirname(__FILE__), 'models/page_scope_methods')
8
+ require File.join(File.dirname(__FILE__), 'models/configuration_methods')
8
9
 
9
10
  module Kaminari
11
+ DEFAULT_PER_PAGE = 25 unless defined? ::Kaminari::DEFAULT_PER_PAGE
10
12
  class Railtie < ::Rails::Railtie #:nodoc:
11
- initializer 'paginatablize' do |app|
12
- if defined? ::ActiveRecord
13
- require File.join(File.dirname(__FILE__), 'active_record_extension')
13
+ initializer 'kaminari' do |app|
14
+ ActiveSupport.on_load(:active_record) do
15
+ require File.join(File.dirname(__FILE__), 'models/active_record_extension')
14
16
  ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
15
17
  end
16
18
  if defined? ::Mongoid
17
- require File.join(File.dirname(__FILE__), 'mongoid_extension')
19
+ require File.join(File.dirname(__FILE__), 'models/mongoid_extension')
18
20
  ::Mongoid::Document.send :include, Kaminari::MongoidExtension::Document
19
21
  ::Mongoid::Criteria.send :include, Kaminari::MongoidExtension::Criteria
20
22
  end
21
- ::ActionView::Base.send :include, Kaminari::Helpers
23
+ ActiveSupport.on_load(:action_view) do
24
+ ::ActionView::Base.send :include, Kaminari::ActionViewExtension
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
2
3
 
3
4
  feature 'Users' do
@@ -1,6 +1,11 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe 'default per_page' do
4
+ describe 'AR::Base' do
5
+ subject { ActiveRecord::Base }
6
+ it { should_not respond_to :paginates_per }
7
+ end
8
+
4
9
  subject { User.page 0 }
5
10
 
6
11
  context 'by default' do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
  require 'mongoid'
3
- require File.expand_path('../../lib/kaminari/mongoid_extension', File.dirname(__FILE__))
3
+ require File.expand_path('../../lib/kaminari/models/mongoid_extension', File.dirname(__FILE__))
4
4
 
5
5
  describe Kaminari::MongoidExtension do
6
6
  before :all do
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,14 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rails'
4
4
  require 'mongoid'
5
5
  require 'kaminari'
6
-
6
+ # Ensure we use 'syck' instead of 'psych' in 1.9.2
7
+ # RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
8
+ # Psych does not yet support YAML 1.1 merge keys.
9
+ # Merge keys is often used in mongoid.yml
10
+ # See: http://redmine.ruby-lang.org/issues/show/4300
11
+ if RUBY_VERSION >= '1.9.2'
12
+ YAML::ENGINE.yamler = 'syck'
13
+ end
7
14
  require File.join(File.dirname(__FILE__), 'fake_app')
8
15
 
9
16
  require 'rspec/rails'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 9
9
- - 13
10
- version: 0.9.13
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Akira Matsuda
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-18 00:00:00 +09:00
18
+ date: 2011-02-21 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -203,23 +203,9 @@ dependencies:
203
203
  prerelease: false
204
204
  type: :development
205
205
  requirement: *id012
206
- - !ruby/object:Gem::Dependency
207
- name: ruby-debug
208
- version_requirements: &id013 !ruby/object:Gem::Requirement
209
- none: false
210
- requirements:
211
- - - ">="
212
- - !ruby/object:Gem::Version
213
- hash: 3
214
- segments:
215
- - 0
216
- version: "0"
217
- prerelease: false
218
- type: :development
219
- requirement: *id013
220
206
  - !ruby/object:Gem::Dependency
221
207
  name: mongoid
222
- version_requirements: &id014 !ruby/object:Gem::Requirement
208
+ version_requirements: &id013 !ruby/object:Gem::Requirement
223
209
  none: false
224
210
  requirements:
225
211
  - - "="
@@ -234,10 +220,10 @@ dependencies:
234
220
  version: 2.0.0.rc.7
235
221
  prerelease: false
236
222
  type: :development
237
- requirement: *id014
223
+ requirement: *id013
238
224
  - !ruby/object:Gem::Dependency
239
225
  name: bson_ext
240
- version_requirements: &id015 !ruby/object:Gem::Requirement
226
+ version_requirements: &id014 !ruby/object:Gem::Requirement
241
227
  none: false
242
228
  requirements:
243
229
  - - ~>
@@ -249,10 +235,10 @@ dependencies:
249
235
  version: "1.2"
250
236
  prerelease: false
251
237
  type: :development
252
- requirement: *id015
238
+ requirement: *id014
253
239
  - !ruby/object:Gem::Dependency
254
240
  name: rails
255
- version_requirements: &id016 !ruby/object:Gem::Requirement
241
+ version_requirements: &id015 !ruby/object:Gem::Requirement
256
242
  none: false
257
243
  requirements:
258
244
  - - ">="
@@ -265,7 +251,7 @@ dependencies:
265
251
  version: 3.0.0
266
252
  prerelease: false
267
253
  type: :runtime
268
- requirement: *id016
254
+ requirement: *id015
269
255
  description: Kaminari is a Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3
270
256
  email: ronnie@dio.jp
271
257
  executables: []
@@ -310,12 +296,17 @@ files:
310
296
  - kaminari.gemspec
311
297
  - lib/generators/kaminari/views_generator.rb
312
298
  - lib/kaminari.rb
313
- - lib/kaminari/active_record_extension.rb
314
299
  - lib/kaminari/engine.rb
315
- - lib/kaminari/helpers.rb
316
- - lib/kaminari/mongoid_extension.rb
300
+ - lib/kaminari/helpers/action_view_extension.rb
301
+ - lib/kaminari/helpers/helpers.rb
302
+ - lib/kaminari/helpers/tags.rb
303
+ - lib/kaminari/models/active_record_extension.rb
304
+ - lib/kaminari/models/active_record_relation_methods.rb
305
+ - lib/kaminari/models/configuration_methods.rb
306
+ - lib/kaminari/models/mongoid_criteria_methods.rb
307
+ - lib/kaminari/models/mongoid_extension.rb
308
+ - lib/kaminari/models/page_scope_methods.rb
317
309
  - lib/kaminari/railtie.rb
318
- - lib/kaminari/tags.rb
319
310
  - spec/acceptance/acceptance_helper.rb
320
311
  - spec/acceptance/support/helpers.rb
321
312
  - spec/acceptance/support/paths.rb
@@ -361,7 +352,7 @@ rubyforge_project:
361
352
  rubygems_version: 1.5.2
362
353
  signing_key:
363
354
  specification_version: 3
364
- summary: A pagnation engine plugin for Rails 3
355
+ summary: A pagination engine plugin for Rails 3
365
356
  test_files:
366
357
  - spec/acceptance/acceptance_helper.rb
367
358
  - spec/acceptance/support/helpers.rb
@@ -1,61 +0,0 @@
1
- module Kaminari
2
- DEFAULT_PER_PAGE = 25 unless defined? ::Kaminari::DEFAULT_PER_PAGE
3
-
4
- module ActiveRecordExtension
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- def self.inherited(kls) #:nodoc:
9
- # TERRIBLE HORRIBLE NO GOOD VERY BAD HACK: inheritable_attributes is not yet set here on AR 3.0
10
- unless kls.default_scoping
11
- new_inheritable_attributes = Hash[inheritable_attributes.map do |key, value|
12
- [key, value.duplicable? ? value.dup : value]
13
- end]
14
- kls.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
15
- end
16
-
17
- kls.class_eval do
18
- # Fetch the values at the specified page number
19
- # Model.page(5)
20
- scope :page, lambda {|num|
21
- limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
22
- } do
23
- # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
24
- # Model.page(3).per(10)
25
- def per(num)
26
- if (n = num.to_i) <= 0
27
- self
28
- else
29
- limit(n).offset(offset_value / limit_value * n)
30
- end
31
- end
32
-
33
- # Total number of pages
34
- def num_pages
35
- (except(:offset, :limit).count.to_f / limit_value).ceil
36
- end
37
-
38
- # Current page number
39
- def current_page
40
- (offset_value / limit_value) + 1
41
- end
42
- end
43
-
44
- # Overrides the default per_page value per model
45
- # class Article < ActiveRecord::Base
46
- # paginates_per 10
47
- # end
48
- def self.paginates_per(val)
49
- @_default_per_page = val
50
- end
51
-
52
- # This model's default per_page value
53
- # returns 25 unless explicitly overridden via <tt>paginates_per</tt>
54
- def self.default_per_page
55
- @_default_per_page || Kaminari::DEFAULT_PER_PAGE
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,63 +0,0 @@
1
- module Kaminari
2
- DEFAULT_PER_PAGE = 25 unless defined? ::Kaminari::DEFAULT_PER_PAGE
3
-
4
- module MongoidExtension
5
- module Criteria
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- delegate :page, :per, :num_pages, :current_page, :limit_value, :to => '@klass'
10
- end
11
- end
12
-
13
- module Document
14
- extend ActiveSupport::Concern
15
-
16
- included do
17
- # Fetch the values at the specified page number
18
- # Model.page(5)
19
- scope :page, lambda {|num|
20
- limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
21
- } do
22
- # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
23
- # Model.page(3).per(10)
24
- def per(num)
25
- if (n = num.to_i) <= 0
26
- self
27
- else
28
- limit(n).offset(options[:skip] / options[:limit] * n)
29
- end
30
- end
31
-
32
- # Total number of pages
33
- def num_pages
34
- (count.to_f / options[:limit]).ceil
35
- end
36
-
37
- # Current page number
38
- def current_page
39
- (options[:skip] / options[:limit]) + 1
40
- end
41
-
42
- def limit_value
43
- options[:limit]
44
- end
45
- end
46
-
47
- # Overrides the default per_page value per model
48
- # class Article < ActiveRecord::Base
49
- # paginates_per 10
50
- # end
51
- def self.paginates_per(val)
52
- @_default_per_page = val
53
- end
54
-
55
- # This model's default per_page value
56
- # returns 25 unless explicitly overridden via <tt>paginates_per</tt>
57
- def self.default_per_page
58
- @_default_per_page || Kaminari::DEFAULT_PER_PAGE
59
- end
60
- end
61
- end
62
- end
63
- end