kaminari 0.9.9 → 0.9.10

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/.gemtest ADDED
File without changes
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.9.10
2
+
3
+ * the per() method accepts String, zero and minus value now #7 [koic]
4
+ This enables you to do something like this:
5
+ Model.page(params[:page]).per(params[:per])
6
+
7
+ * Added support for Gem Testers (http://gem-testers.org/) #8 [joealba]
8
+
1
9
  == 0.9.9
2
10
 
3
11
  * :params option for the helper [yomukaku_memo]
data/README.rdoc CHANGED
@@ -86,7 +86,7 @@ This would output something like 1 ...(snip)... 18 19 20 while having 20 pages i
86
86
  <%= paginate @users, :left => 0, :right => 2 %>
87
87
 
88
88
  * extra parameters (:params) for the links
89
- This would modify each link's url_option. :controller and :action would be the usual keys.
89
+ This would modify each link's url_option. :controller and :action might be the keys in common.
90
90
  <%= paginate @users, :params => {:controller => 'foo', :action => 'bar'}
91
91
 
92
92
  * Ajax links (crazy simple, but works perfectly!)
data/Rakefile CHANGED
@@ -50,3 +50,7 @@ Rake::RDocTask.new do |rdoc|
50
50
  rdoc.rdoc_files.include('README*')
51
51
  rdoc.rdoc_files.include('lib/**/*.rb')
52
52
  end
53
+
54
+ task :test do
55
+ Rake::Task[:spec].invoke
56
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.9
1
+ 0.9.10
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.9"
8
+ s.version = "0.9.10"
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-13}
12
+ s.date = %q{2011-02-17}
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 = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".gemtest",
21
22
  ".rspec",
22
23
  "CHANGELOG",
23
24
  "Gemfile",
@@ -4,7 +4,7 @@ module Kaminari
4
4
  DEFAULT_PER_PAGE = 25
5
5
 
6
6
  included do
7
- def self.inherited(kls)
7
+ def self.inherited(kls) #:nodoc:
8
8
  # TERRIBLE HORRIBLE NO GOOD VERY BAD HACK: inheritable_attributes is not yet set here on AR 3.0
9
9
  unless kls.default_scoping
10
10
  new_inheritable_attributes = Hash[inheritable_attributes.map do |key, value|
@@ -14,32 +14,45 @@ module Kaminari
14
14
  end
15
15
 
16
16
  kls.class_eval do
17
- # page(5)
17
+ # Fetch the values at the specified page number
18
+ # Model.page(5)
18
19
  scope :page, lambda {|num|
19
- per_page = @_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
20
- limit(per_page).offset(per_page * ([num.to_i, 1].max - 1))
20
+ limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
21
21
  } do
22
- # page(3).per(10)
22
+ # Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
23
+ # Model.page(3).per(10)
23
24
  def per(num)
24
- limit(num).offset(offset_value / limit_value * num)
25
+ if (n = num.to_i) <= 0
26
+ self
27
+ else
28
+ limit(n).offset(offset_value / limit_value * n)
29
+ end
25
30
  end
26
31
 
32
+ # Total number of pages
27
33
  def num_pages
28
34
  (except(:offset, :limit).count.to_f / limit_value).ceil
29
35
  end
30
36
 
37
+ # Current page number
31
38
  def current_page
32
39
  (offset_value / limit_value) + 1
33
40
  end
34
41
  end
35
42
 
36
- # overrides the default per_page value per model
43
+ # Overrides the default per_page value per model
37
44
  # class Article < ActiveRecord::Base
38
45
  # paginates_per 10
39
46
  # end
40
47
  def self.paginates_per(val)
41
48
  @_default_per_page = val
42
49
  end
50
+
51
+ # This model's default per_page value
52
+ # returns 25 unless explicitly overridden via <tt>paginates_per</tt>
53
+ def self.default_per_page
54
+ @_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
55
+ end
43
56
  end
44
57
  end
45
58
  end
@@ -60,7 +60,7 @@ module Kaminari
60
60
  method.call name, 'kaminari', true
61
61
  else
62
62
  # 3.1
63
- method.call name, 'kaminari', true, []
63
+ method.call name, ['kaminari'], true, []
64
64
  end
65
65
  end
66
66
 
data/lib/kaminari/tags.rb CHANGED
@@ -26,19 +26,24 @@ module Kaminari
26
26
  end
27
27
 
28
28
  private
29
+ def self.ancestor_renderables
30
+ arr = []
31
+ ancestors.each do |klass|
32
+ return arr if klass == Tag
33
+ arr << klass if klass != Renderable
34
+ end
35
+ end
36
+
29
37
  # OMG yet another super dirty hack
30
38
  # this method finds
31
39
  # 1. a template for the given class from app/views
32
40
  # 2. a template for its parent class from app/views
33
41
  # 3. the default one inside the engine
34
- def find_template(klass = self.class)
35
- if @renderer.partial_exists? klass.template_filename
36
- "kaminari/#{klass.template_filename}"
37
- elsif (parent = klass.ancestors[1]) == Renderable
38
- "kaminari/#{self.class.template_filename}"
39
- else
40
- find_template parent
42
+ def find_template
43
+ self.class.ancestor_renderables.each do |klass|
44
+ return "kaminari/#{klass.template_filename}" if @renderer.partial_exists? klass.template_filename
41
45
  end
46
+ "kaminari/#{self.class.template_filename}"
42
47
  end
43
48
 
44
49
  def page_url_for(page)
@@ -2,25 +2,46 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
  include Kaminari::Helpers
3
3
 
4
4
  describe 'Kaminari::Helpers' do
5
- let :renderer do
6
- stub(r = Object.new) do
7
- render.with_any_args
8
- options { {} }
9
- params { {} }
10
- partial_exists?.with_any_args {|a| puts a; false }
11
- url_for {|h| "/foo?page=#{h[:page]}"}
12
- end
13
- r
14
- end
15
- describe 'PageLink' do
16
- subject { PageLink.new renderer, :page => 3 }
17
- its('class.template_filename') { should == 'page_link' }
18
- describe 'template lookup rule' do
19
- before do
20
- pending "spies doesn't work on RSpec 2 ATM: https://github.com/btakita/rr/issues#issue/45"
21
- subject.to_s
22
- end
23
- specify { renderer.should have_received.partial_exists? PageLink }
5
+ describe 'template lookup rule' do
6
+ describe 'Paginator' do
7
+ subject { Paginator }
8
+ its(:ancestor_renderables) { should == [Paginator] }
9
+ end
10
+ describe 'PrevLink' do
11
+ subject { PrevLink }
12
+ its(:ancestor_renderables) { should == [PrevLink, Prev, Link, Page] }
13
+ end
14
+ describe 'PrevSpan' do
15
+ subject { PrevSpan }
16
+ its(:ancestor_renderables) { should == [PrevSpan, Prev, NonLink] }
17
+ end
18
+ describe 'FirstPageLink' do
19
+ subject { FirstPageLink }
20
+ its(:ancestor_renderables) { should == [FirstPageLink, PageLink, Link, Page] }
21
+ end
22
+ describe 'PageLink' do
23
+ subject { PageLink }
24
+ its(:ancestor_renderables) { should == [PageLink, Link, Page] }
25
+ end
26
+ describe 'CurrentPage' do
27
+ subject { CurrentPage }
28
+ its(:ancestor_renderables) { should == [CurrentPage, NonLink, Page] }
29
+ end
30
+ describe 'TruncatedSpan' do
31
+ subject { TruncatedSpan }
32
+ its(:ancestor_renderables) { should == [TruncatedSpan, NonLink] }
33
+ end
34
+ describe 'LastPageLink' do
35
+ subject { LastPageLink }
36
+ its(:ancestor_renderables) { should == [LastPageLink, PageLink, Link, Page] }
37
+ end
38
+ describe 'NextLink' do
39
+ subject { NextLink }
40
+ its(:ancestor_renderables) { should == [NextLink, Next, Link, Page] }
41
+ end
42
+ describe 'NextSpan' do
43
+ subject { NextSpan }
44
+ its(:ancestor_renderables) { should == [NextSpan, Next, NonLink] }
24
45
  end
25
46
  end
26
47
  end
@@ -66,6 +66,21 @@ describe Kaminari::ActiveRecord do
66
66
  subject { User.page(50).per(65536) }
67
67
  its(:num_pages) { should == 1 }
68
68
  end
69
+
70
+ context 'per 0 (using default)' do
71
+ subject { User.page(50).per(0) }
72
+ its(:num_pages) { should == 4 }
73
+ end
74
+
75
+ context 'per -1 (using default)' do
76
+ subject { User.page(5).per(-1) }
77
+ its(:num_pages) { should == 4 }
78
+ end
79
+
80
+ context 'per "String value that can not be converted into Number" (using default)' do
81
+ subject { User.page(5).per('aho') }
82
+ its(:num_pages) { should == 4 }
83
+ end
69
84
  end
70
85
 
71
86
  describe '#current_page' do
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: 41
4
+ hash: 47
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 9
10
- version: 0.9.9
9
+ - 10
10
+ version: 0.9.10
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-13 00:00:00 +09:00
18
+ date: 2011-02-17 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -244,6 +244,7 @@ extra_rdoc_files:
244
244
  - README.rdoc
245
245
  files:
246
246
  - .document
247
+ - .gemtest
247
248
  - .rspec
248
249
  - CHANGELOG
249
250
  - Gemfile