kaminari 0.9.5 → 0.9.6
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 +9 -0
- data/README.rdoc +8 -0
- data/VERSION +1 -1
- data/kaminari.gemspec +8 -10
- data/lib/kaminari/active_record.rb +12 -2
- data/spec/{support/fake_app.rb → fake_app.rb} +19 -0
- data/spec/models/default_per_page_spec.rb +24 -0
- data/spec/spec_helper.rb +2 -2
- metadata +8 -10
- data/spec/support/20110128122508_create_users.rb +0 -8
- data/spec/support/user.rb +0 -3
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -49,6 +49,14 @@ To show a lot more users per each page (change the per_page value)
|
|
49
49
|
User.page(7).per(50)
|
50
50
|
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.
|
51
51
|
|
52
|
+
=== Configuring default per_page value for each model
|
53
|
+
|
54
|
+
* paginates_per
|
55
|
+
You can specify default per_page value per each model using the following declarative DSL.
|
56
|
+
class User
|
57
|
+
paginates_per 50
|
58
|
+
end
|
59
|
+
|
52
60
|
=== Controllers
|
53
61
|
|
54
62
|
* the page parameter is in params[:page]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.6
|
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.
|
8
|
+
s.version = "0.9.6"
|
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-
|
12
|
+
s.date = %q{2011-02-12}
|
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 = [
|
@@ -91,14 +91,13 @@ Gem::Specification.new do |s|
|
|
91
91
|
"spec/acceptance/support/helpers.rb",
|
92
92
|
"spec/acceptance/support/paths.rb",
|
93
93
|
"spec/acceptance/users_spec.rb",
|
94
|
+
"spec/fake_app.rb",
|
94
95
|
"spec/helpers/helpers_spec.rb",
|
95
96
|
"spec/helpers/tags_spec.rb",
|
97
|
+
"spec/models/default_per_page_spec.rb",
|
96
98
|
"spec/models/scopes_spec.rb",
|
97
99
|
"spec/spec_helper.rb",
|
98
|
-
"spec/support/
|
99
|
-
"spec/support/fake_app.rb",
|
100
|
-
"spec/support/matchers.rb",
|
101
|
-
"spec/support/user.rb"
|
100
|
+
"spec/support/matchers.rb"
|
102
101
|
]
|
103
102
|
s.homepage = %q{http://github.com/amatsuda/kaminari}
|
104
103
|
s.licenses = ["MIT"]
|
@@ -110,14 +109,13 @@ Gem::Specification.new do |s|
|
|
110
109
|
"spec/acceptance/support/helpers.rb",
|
111
110
|
"spec/acceptance/support/paths.rb",
|
112
111
|
"spec/acceptance/users_spec.rb",
|
112
|
+
"spec/fake_app.rb",
|
113
113
|
"spec/helpers/helpers_spec.rb",
|
114
114
|
"spec/helpers/tags_spec.rb",
|
115
|
+
"spec/models/default_per_page_spec.rb",
|
115
116
|
"spec/models/scopes_spec.rb",
|
116
117
|
"spec/spec_helper.rb",
|
117
|
-
"spec/support/
|
118
|
-
"spec/support/fake_app.rb",
|
119
|
-
"spec/support/matchers.rb",
|
120
|
-
"spec/support/user.rb"
|
118
|
+
"spec/support/matchers.rb"
|
121
119
|
]
|
122
120
|
|
123
121
|
if s.respond_to? :specification_version then
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Kaminari
|
2
2
|
module ActiveRecord
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
4
|
+
DEFAULT_PER_PAGE = 25
|
5
5
|
|
6
6
|
included do
|
7
7
|
def self.inherited(kls)
|
@@ -12,10 +12,12 @@ module Kaminari
|
|
12
12
|
end]
|
13
13
|
kls.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
|
14
14
|
end
|
15
|
+
|
15
16
|
kls.class_eval do
|
16
17
|
# page(5)
|
17
18
|
scope :page, lambda {|num|
|
18
|
-
|
19
|
+
per_page = @_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
|
20
|
+
limit(per_page).offset(per_page * ([num.to_i, 1].max - 1))
|
19
21
|
} do
|
20
22
|
# page(3).per(10)
|
21
23
|
def per(num)
|
@@ -30,6 +32,14 @@ module Kaminari
|
|
30
32
|
(offset_value / limit_value) + 1
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
36
|
+
# overrides the default per_page value per model
|
37
|
+
# class Article < ActiveRecord::Base
|
38
|
+
# paginates_per 10
|
39
|
+
# end
|
40
|
+
def self.paginates_per(val)
|
41
|
+
@_default_per_page = val
|
42
|
+
end
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -2,19 +2,29 @@ require 'active_record'
|
|
2
2
|
require 'action_controller/railtie'
|
3
3
|
require 'action_view/railtie'
|
4
4
|
|
5
|
+
# database
|
5
6
|
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
6
7
|
ActiveRecord::Base.establish_connection('test')
|
7
8
|
|
9
|
+
# config
|
8
10
|
app = Class.new(Rails::Application)
|
9
11
|
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
|
10
12
|
app.config.session_store :cookie_store, :key => "_myapp_session"
|
11
13
|
app.config.active_support.deprecation = :log
|
12
14
|
app.initialize!
|
13
15
|
|
16
|
+
# routes
|
14
17
|
app.routes.draw do
|
15
18
|
resources :users
|
16
19
|
end
|
17
20
|
|
21
|
+
# models
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
default_scope order(:name)
|
24
|
+
end
|
25
|
+
class Book < ActiveRecord::Base; end
|
26
|
+
|
27
|
+
# controllers
|
18
28
|
class ApplicationController < ActionController::Base; end
|
19
29
|
class UsersController < ApplicationController
|
20
30
|
def index
|
@@ -26,4 +36,13 @@ ERB
|
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
39
|
+
# helpers
|
29
40
|
Object.const_set(:ApplicationHelper, Module.new)
|
41
|
+
|
42
|
+
#migrations
|
43
|
+
class CreateAllTables < ActiveRecord::Migration
|
44
|
+
def self.up
|
45
|
+
create_table(:users) {|t| t.string :name }
|
46
|
+
create_table(:books) {|t| t.string :title }
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'default per_page' do
|
4
|
+
subject { User.page 0 }
|
5
|
+
|
6
|
+
context 'by default' do
|
7
|
+
its(:limit_value) { should == 25 }
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when explicitly set via paginates_per' do
|
11
|
+
before { User.paginates_per 1326 }
|
12
|
+
its(:limit_value) { should == 1326 }
|
13
|
+
after { User.paginates_per nil }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "default per_page value's independency per model" do
|
17
|
+
context "when User's default per_page was changed" do
|
18
|
+
before { User.paginates_per 1326 }
|
19
|
+
subject { Book.page 0 }
|
20
|
+
its(:limit_value) { should == 25 }
|
21
|
+
after { User.paginates_per nil }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'rails'
|
4
4
|
require 'kaminari'
|
5
5
|
|
6
|
-
require File.join(File.dirname(__FILE__), '
|
6
|
+
require File.join(File.dirname(__FILE__), 'fake_app')
|
7
7
|
|
8
8
|
require 'rspec/rails'
|
9
9
|
# Requires supporting files with custom matchers and macros, etc,
|
@@ -14,6 +14,6 @@ RSpec.configure do |config|
|
|
14
14
|
config.mock_with :rr
|
15
15
|
config.before :all do
|
16
16
|
# ActiveRecord::Base.connection.execute 'CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255))' unless ActiveRecord::Base.connection.table_exists? 'users'
|
17
|
-
|
17
|
+
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
|
18
18
|
end
|
19
19
|
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:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 6
|
10
|
+
version: 0.9.6
|
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
|
+
date: 2011-02-12 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -317,14 +317,13 @@ files:
|
|
317
317
|
- spec/acceptance/support/helpers.rb
|
318
318
|
- spec/acceptance/support/paths.rb
|
319
319
|
- spec/acceptance/users_spec.rb
|
320
|
+
- spec/fake_app.rb
|
320
321
|
- spec/helpers/helpers_spec.rb
|
321
322
|
- spec/helpers/tags_spec.rb
|
323
|
+
- spec/models/default_per_page_spec.rb
|
322
324
|
- spec/models/scopes_spec.rb
|
323
325
|
- spec/spec_helper.rb
|
324
|
-
- spec/support/20110128122508_create_users.rb
|
325
|
-
- spec/support/fake_app.rb
|
326
326
|
- spec/support/matchers.rb
|
327
|
-
- spec/support/user.rb
|
328
327
|
has_rdoc: true
|
329
328
|
homepage: http://github.com/amatsuda/kaminari
|
330
329
|
licenses:
|
@@ -364,11 +363,10 @@ test_files:
|
|
364
363
|
- spec/acceptance/support/helpers.rb
|
365
364
|
- spec/acceptance/support/paths.rb
|
366
365
|
- spec/acceptance/users_spec.rb
|
366
|
+
- spec/fake_app.rb
|
367
367
|
- spec/helpers/helpers_spec.rb
|
368
368
|
- spec/helpers/tags_spec.rb
|
369
|
+
- spec/models/default_per_page_spec.rb
|
369
370
|
- spec/models/scopes_spec.rb
|
370
371
|
- spec/spec_helper.rb
|
371
|
-
- spec/support/20110128122508_create_users.rb
|
372
|
-
- spec/support/fake_app.rb
|
373
372
|
- spec/support/matchers.rb
|
374
|
-
- spec/support/user.rb
|
data/spec/support/user.rb
DELETED