kaminari 0.9.12 → 0.9.13

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,8 @@
1
+ == 0.9.13
2
+
3
+ * Added Mongoid support #5 [juno, hibariya]
4
+ This means, Kaminari is now *ORM agnostic* ☇3☇3☇3
5
+
1
6
  == 0.9.12
2
7
 
3
8
  * Moved the whole pagination logic to the paginator partial so that users can
data/Gemfile CHANGED
@@ -20,4 +20,6 @@ group :development do
20
20
  gem 'rspec-rails', '>= 2.5.0'
21
21
  gem 'sqlite3', '>= 1.3.3'
22
22
  gem 'ruby-debug'
23
+ gem 'mongoid', '2.0.0.rc.7'
24
+ gem 'bson_ext', '~> 1.2'
23
25
  end
data/Gemfile.lock CHANGED
@@ -61,6 +61,8 @@ GEM
61
61
  specs:
62
62
  abstract (1.0.0)
63
63
  bcrypt-ruby (2.1.4)
64
+ bson (1.2.2)
65
+ bson_ext (1.2.2)
64
66
  builder (3.0.0)
65
67
  capybara (0.4.1.2)
66
68
  celerity (>= 0.7.9)
@@ -96,6 +98,13 @@ GEM
96
98
  mime-types (~> 1.16)
97
99
  treetop (~> 1.4.8)
98
100
  mime-types (1.16)
101
+ mongo (1.2.2)
102
+ bson (>= 1.2.2)
103
+ mongoid (2.0.0.rc.7)
104
+ activemodel (~> 3.0)
105
+ mongo (~> 1.2)
106
+ tzinfo (~> 0.3.22)
107
+ will_paginate (~> 3.0.pre)
99
108
  nokogiri (1.4.4)
100
109
  polyglot (0.3.1)
101
110
  rack-cache (1.0)
@@ -138,6 +147,7 @@ GEM
138
147
  treetop (1.4.9)
139
148
  polyglot (>= 0.3.1)
140
149
  tzinfo (0.3.24)
150
+ will_paginate (3.0.pre2)
141
151
  xpath (0.1.3)
142
152
  nokogiri (~> 1.3)
143
153
 
@@ -146,9 +156,11 @@ PLATFORMS
146
156
 
147
157
  DEPENDENCIES
148
158
  arel!
159
+ bson_ext (~> 1.2)
149
160
  bundler (>= 1.0.0)
150
161
  capybara (>= 0.4.1.1)
151
162
  jeweler (>= 1.5.2)
163
+ mongoid (= 2.0.0.rc.7)
152
164
  rack!
153
165
  rails!
154
166
  rcov
data/README.rdoc CHANGED
@@ -18,14 +18,22 @@ No special collection class or something for the paginated values but uses a gen
18
18
  * Engine based I18n aware customizable helper
19
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.
20
20
 
21
+ * ORM, template engine agnostic
22
+ Kaminari supports multiple ORMs (ActiveRecord, Mongoid) and multiple template engines (ERB, Haml).
23
+
21
24
  * Modern
22
25
  The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports the Rails 3 unobtrusive Ajax.
23
26
 
24
27
 
25
- == Rails versions
28
+ == Supported versions
29
+
30
+ * Ruby 1.8.7 and 1.9.2 and 1.9.3
31
+
32
+ * Rails 3.0.x and 3.1
26
33
 
27
- 3.0.x and 3.1
34
+ * Haml 3
28
35
 
36
+ * Mongoid 2 (beta)
29
37
 
30
38
  == Install
31
39
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.12
1
+ 0.9.13
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.12"
8
+ s.version = "0.9.13"
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-17}
12
+ s.date = %q{2011-02-18}
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,9 +51,10 @@ 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.rb",
54
+ "lib/kaminari/active_record_extension.rb",
55
55
  "lib/kaminari/engine.rb",
56
56
  "lib/kaminari/helpers.rb",
57
+ "lib/kaminari/mongoid_extension.rb",
57
58
  "lib/kaminari/railtie.rb",
58
59
  "lib/kaminari/tags.rb",
59
60
  "spec/acceptance/acceptance_helper.rb",
@@ -64,6 +65,7 @@ Gem::Specification.new do |s|
64
65
  "spec/helpers/helpers_spec.rb",
65
66
  "spec/helpers/tags_spec.rb",
66
67
  "spec/models/default_per_page_spec.rb",
68
+ "spec/models/mongoid_spec.rb",
67
69
  "spec/models/scopes_spec.rb",
68
70
  "spec/spec_helper.rb",
69
71
  "spec/support/matchers.rb"
@@ -82,6 +84,7 @@ Gem::Specification.new do |s|
82
84
  "spec/helpers/helpers_spec.rb",
83
85
  "spec/helpers/tags_spec.rb",
84
86
  "spec/models/default_per_page_spec.rb",
87
+ "spec/models/mongoid_spec.rb",
85
88
  "spec/models/scopes_spec.rb",
86
89
  "spec/spec_helper.rb",
87
90
  "spec/support/matchers.rb"
@@ -104,6 +107,8 @@ Gem::Specification.new do |s|
104
107
  s.add_development_dependency(%q<rspec-rails>, [">= 2.5.0"])
105
108
  s.add_development_dependency(%q<sqlite3>, [">= 1.3.3"])
106
109
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
110
+ s.add_development_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
111
+ s.add_development_dependency(%q<bson_ext>, ["~> 1.2"])
107
112
  s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
108
113
  else
109
114
  s.add_dependency(%q<rspec>, [">= 2.5.0"])
@@ -119,6 +124,8 @@ Gem::Specification.new do |s|
119
124
  s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
120
125
  s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
121
126
  s.add_dependency(%q<ruby-debug>, [">= 0"])
127
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
128
+ s.add_dependency(%q<bson_ext>, ["~> 1.2"])
122
129
  s.add_dependency(%q<rails>, [">= 3.0.0"])
123
130
  end
124
131
  else
@@ -135,6 +142,8 @@ Gem::Specification.new do |s|
135
142
  s.add_dependency(%q<rspec-rails>, [">= 2.5.0"])
136
143
  s.add_dependency(%q<sqlite3>, [">= 1.3.3"])
137
144
  s.add_dependency(%q<ruby-debug>, [">= 0"])
145
+ s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
146
+ s.add_dependency(%q<bson_ext>, ["~> 1.2"])
138
147
  s.add_dependency(%q<rails>, [">= 3.0.0"])
139
148
  end
140
149
  end
@@ -1,7 +1,8 @@
1
1
  module Kaminari
2
- module ActiveRecord
2
+ DEFAULT_PER_PAGE = 25 unless defined? ::Kaminari::DEFAULT_PER_PAGE
3
+
4
+ module ActiveRecordExtension
3
5
  extend ActiveSupport::Concern
4
- DEFAULT_PER_PAGE = 25
5
6
 
6
7
  included do
7
8
  def self.inherited(kls) #:nodoc:
@@ -51,7 +52,7 @@ module Kaminari
51
52
  # This model's default per_page value
52
53
  # returns 25 unless explicitly overridden via <tt>paginates_per</tt>
53
54
  def self.default_per_page
54
- @_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
55
+ @_default_per_page || Kaminari::DEFAULT_PER_PAGE
55
56
  end
56
57
  end
57
58
  end
@@ -0,0 +1,63 @@
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
@@ -1,13 +1,23 @@
1
1
  require 'rails'
2
- require 'active_record'
3
2
  require 'action_view'
4
- require File.join(File.dirname(__FILE__), 'active_record')
3
+ # ensure ORMs are loaded *before* initializing Kaminari
4
+ begin; require 'active_record'; rescue LoadError; end
5
+ begin; require 'mongoid'; rescue LoadError; end
6
+
5
7
  require File.join(File.dirname(__FILE__), 'helpers')
6
8
 
7
9
  module Kaminari
8
10
  class Railtie < ::Rails::Railtie #:nodoc:
9
11
  initializer 'paginatablize' do |app|
10
- ::ActiveRecord::Base.send :include, Kaminari::ActiveRecord
12
+ if defined? ::ActiveRecord
13
+ require File.join(File.dirname(__FILE__), 'active_record_extension')
14
+ ::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension
15
+ end
16
+ if defined? ::Mongoid
17
+ require File.join(File.dirname(__FILE__), 'mongoid_extension')
18
+ ::Mongoid::Document.send :include, Kaminari::MongoidExtension::Document
19
+ ::Mongoid::Criteria.send :include, Kaminari::MongoidExtension::Criteria
20
+ end
11
21
  ::ActionView::Base.send :include, Kaminari::Helpers
12
22
  end
13
23
  end
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require 'mongoid'
3
+ require File.expand_path('../../lib/kaminari/mongoid_extension', File.dirname(__FILE__))
4
+
5
+ describe Kaminari::MongoidExtension do
6
+ before :all do
7
+ class Developer
8
+ include ::Mongoid::Document
9
+ end
10
+ end
11
+ before do
12
+ stub(subject).count { 300 } # in order to avoid DB access...
13
+ end
14
+
15
+ describe '#page' do
16
+ context 'page 1' do
17
+ subject { Developer.page 1 }
18
+ it { should be_a Mongoid::Criteria }
19
+ its(:current_page) { should == 1 }
20
+ its(:limit_value) { should == 25 }
21
+ its(:num_pages) { should == 12 }
22
+ it { should skip(0) }
23
+ end
24
+
25
+ context 'page 2' do
26
+ subject { Developer.page 2 }
27
+ it { should be_a Mongoid::Criteria }
28
+ its(:current_page) { should == 2 }
29
+ its(:limit_value) { should == 25 }
30
+ its(:num_pages) { should == 12 }
31
+ it { should skip 25 }
32
+ end
33
+
34
+ context 'page "foobar"' do
35
+ subject { Developer.page 'foobar' }
36
+ it { should be_a Mongoid::Criteria }
37
+ its(:current_page) { should == 1 }
38
+ its(:limit_value) { should == 25 }
39
+ its(:num_pages) { should == 12 }
40
+ it { should skip 0 }
41
+ end
42
+ end
43
+
44
+ describe '#per' do
45
+ subject { Developer.page(2).per(10) }
46
+ it { should be_a Mongoid::Criteria }
47
+ its(:current_page) { should == 2 }
48
+ its(:limit_value) { should == 10 }
49
+ its(:num_pages) { should == 30 }
50
+ it { should skip 10 }
51
+ end
52
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
- describe Kaminari::ActiveRecord do
3
+ describe Kaminari::ActiveRecordExtension do
4
4
  before :all do
5
5
  User.delete_all
6
6
  1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rails'
4
+ require 'mongoid'
4
5
  require 'kaminari'
5
6
 
6
7
  require File.join(File.dirname(__FILE__), 'fake_app')
@@ -38,3 +38,9 @@ RSpec::Matchers.define :contain_tag_old do |count|
38
38
  "expected #{count || 'any'} instance(s) of #{@klass.name} but was #{@count}"
39
39
  end
40
40
  end
41
+
42
+ RSpec::Matchers.define :skip do |num|
43
+ match do |criteria|
44
+ criteria.instance_variable_get('@options')[:skip] == num
45
+ end
46
+ end
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: 35
4
+ hash: 33
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 12
10
- version: 0.9.12
9
+ - 13
10
+ version: 0.9.13
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-17 00:00:00 +09:00
18
+ date: 2011-02-18 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -218,8 +218,41 @@ dependencies:
218
218
  type: :development
219
219
  requirement: *id013
220
220
  - !ruby/object:Gem::Dependency
221
- name: rails
221
+ name: mongoid
222
222
  version_requirements: &id014 !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - "="
226
+ - !ruby/object:Gem::Version
227
+ hash: 15424091
228
+ segments:
229
+ - 2
230
+ - 0
231
+ - 0
232
+ - rc
233
+ - 7
234
+ version: 2.0.0.rc.7
235
+ prerelease: false
236
+ type: :development
237
+ requirement: *id014
238
+ - !ruby/object:Gem::Dependency
239
+ name: bson_ext
240
+ version_requirements: &id015 !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ~>
244
+ - !ruby/object:Gem::Version
245
+ hash: 11
246
+ segments:
247
+ - 1
248
+ - 2
249
+ version: "1.2"
250
+ prerelease: false
251
+ type: :development
252
+ requirement: *id015
253
+ - !ruby/object:Gem::Dependency
254
+ name: rails
255
+ version_requirements: &id016 !ruby/object:Gem::Requirement
223
256
  none: false
224
257
  requirements:
225
258
  - - ">="
@@ -232,7 +265,7 @@ dependencies:
232
265
  version: 3.0.0
233
266
  prerelease: false
234
267
  type: :runtime
235
- requirement: *id014
268
+ requirement: *id016
236
269
  description: Kaminari is a Scope & Engine based clean and powerful and customizable and sophisticated paginator for Rails 3
237
270
  email: ronnie@dio.jp
238
271
  executables: []
@@ -277,9 +310,10 @@ files:
277
310
  - kaminari.gemspec
278
311
  - lib/generators/kaminari/views_generator.rb
279
312
  - lib/kaminari.rb
280
- - lib/kaminari/active_record.rb
313
+ - lib/kaminari/active_record_extension.rb
281
314
  - lib/kaminari/engine.rb
282
315
  - lib/kaminari/helpers.rb
316
+ - lib/kaminari/mongoid_extension.rb
283
317
  - lib/kaminari/railtie.rb
284
318
  - lib/kaminari/tags.rb
285
319
  - spec/acceptance/acceptance_helper.rb
@@ -290,6 +324,7 @@ files:
290
324
  - spec/helpers/helpers_spec.rb
291
325
  - spec/helpers/tags_spec.rb
292
326
  - spec/models/default_per_page_spec.rb
327
+ - spec/models/mongoid_spec.rb
293
328
  - spec/models/scopes_spec.rb
294
329
  - spec/spec_helper.rb
295
330
  - spec/support/matchers.rb
@@ -336,6 +371,7 @@ test_files:
336
371
  - spec/helpers/helpers_spec.rb
337
372
  - spec/helpers/tags_spec.rb
338
373
  - spec/models/default_per_page_spec.rb
374
+ - spec/models/mongoid_spec.rb
339
375
  - spec/models/scopes_spec.rb
340
376
  - spec/spec_helper.rb
341
377
  - spec/support/matchers.rb