rails_paginate 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -4
- data/VERSION +1 -1
- data/lib/rails_paginate/helpers/action_view.rb +1 -1
- data/lib/rails_paginate/pagers/base.rb +3 -2
- data/lib/rails_paginate/pagers/slider.rb +11 -3
- data/lib/rails_paginate/renderers/base.rb +3 -11
- data/lib/rails_paginate/renderers/html_default.rb +67 -20
- data/rails_paginate.gemspec +5 -1
- data/spec/helpers/action_view_spec.rb +1 -2
- data/spec/pagers/base_spec.rb +21 -0
- data/spec/pagers/slider_spec.rb +147 -0
- metadata +6 -2
data/README.rdoc
CHANGED
@@ -8,10 +8,12 @@ a new rails 3 paginate plugin as will_paginate replacement
|
|
8
8
|
* -> Array - 100%
|
9
9
|
* -> ActiveRecord - 100%
|
10
10
|
* -> Rspec - 100%
|
11
|
-
* ViewHelper -
|
12
|
-
* -> HtmlDefault
|
13
|
-
* ->
|
14
|
-
*
|
11
|
+
* ViewHelper - 70%
|
12
|
+
* -> HtmlDefault 80%
|
13
|
+
* -> Rspec 5%
|
14
|
+
* Pager - 100%
|
15
|
+
* -> Slider - 100%
|
16
|
+
* -> Rspec - 100%
|
15
17
|
|
16
18
|
== Installation
|
17
19
|
Add the following line to your Gemfile
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -8,7 +8,7 @@ module RailsPaginate::Helpers
|
|
8
8
|
def paginate(*args)
|
9
9
|
options = args.extract_options!
|
10
10
|
|
11
|
-
raise ArgumentError, "first argument
|
11
|
+
raise ArgumentError, "first argument must be a RailsPaginate::Collection" unless args.first.is_a? RailsPaginate::Collection
|
12
12
|
|
13
13
|
collection = args.first
|
14
14
|
# p @controller
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module RailsPaginate::Pagers
|
2
2
|
# base method
|
3
3
|
class Base
|
4
|
-
attr_reader :collection
|
5
|
-
def initialize(collection)
|
4
|
+
attr_reader :collection, :options
|
5
|
+
def initialize(collection, options = {})
|
6
6
|
@collection = collection
|
7
|
+
@options = options
|
7
8
|
end
|
8
9
|
|
9
10
|
def current_page
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RailsPaginate::Pagers
|
2
2
|
# slider method
|
3
3
|
class Slider < Base
|
4
|
-
|
5
|
-
@@inner =
|
6
|
-
@@outer =
|
4
|
+
cattr_accessor :inner, :outer
|
5
|
+
@@inner = 3
|
6
|
+
@@outer = 1
|
7
7
|
|
8
8
|
def visible_pages
|
9
9
|
visible = []
|
@@ -47,5 +47,13 @@ module RailsPaginate::Pagers
|
|
47
47
|
false
|
48
48
|
end
|
49
49
|
|
50
|
+
def inner
|
51
|
+
options[:inner] || self.class.inner
|
52
|
+
end
|
53
|
+
|
54
|
+
def outer
|
55
|
+
options[:outer] || self.class.outer
|
56
|
+
end
|
57
|
+
|
50
58
|
end
|
51
59
|
end
|
@@ -4,9 +4,9 @@ module RailsPaginate::Renderers
|
|
4
4
|
attr_reader :view, :collection, :options, :pager
|
5
5
|
|
6
6
|
def initialize(view, collection, pager, options = {})
|
7
|
-
raise ArgumentError, "first argument
|
8
|
-
raise ArgumentError, "second argument
|
9
|
-
raise ArgumentError, "third argument
|
7
|
+
raise ArgumentError, "first argument must be a RailsPaginate::Collection" unless collection.is_a? RailsPaginate::Collection
|
8
|
+
raise ArgumentError, "second argument must be a Hash" unless options.is_a? Hash
|
9
|
+
raise ArgumentError, "third argument must be an instance of RailsPaginate::Pagers::Base" unless pager.is_a? RailsPaginate::Pagers::Base
|
10
10
|
@options = options
|
11
11
|
@collection = collection
|
12
12
|
@view = view
|
@@ -56,13 +56,5 @@ module RailsPaginate::Renderers
|
|
56
56
|
view.t(*args)
|
57
57
|
end
|
58
58
|
|
59
|
-
def inner_window
|
60
|
-
self.class.inner_window
|
61
|
-
end
|
62
|
-
|
63
|
-
def outer_window
|
64
|
-
self.class.outer_window
|
65
|
-
end
|
66
|
-
|
67
59
|
end
|
68
60
|
end
|
@@ -1,46 +1,93 @@
|
|
1
1
|
module RailsPaginate::Renderers
|
2
2
|
# normale renderer
|
3
3
|
class HtmlDefault < Base
|
4
|
+
# show first page item
|
5
|
+
cattr_accessor :show_first_page
|
6
|
+
@@show_first_page = true
|
4
7
|
|
8
|
+
# show last page item
|
9
|
+
cattr_accessor :show_last_page
|
10
|
+
@@show_last_page = true
|
11
|
+
|
12
|
+
# show next page item
|
13
|
+
cattr_accessor :show_next_page
|
14
|
+
@@show_next_page = true
|
15
|
+
|
16
|
+
# show previous page item
|
17
|
+
cattr_accessor :show_previous_page
|
18
|
+
@@show_previous_page = true
|
5
19
|
|
6
20
|
def render
|
7
|
-
|
21
|
+
content_tag(:ul) do
|
8
22
|
html = "\n"
|
9
|
-
|
10
|
-
|
23
|
+
|
24
|
+
if show_first_page?
|
25
|
+
html += content_tag(:li, :class => "first_page") do
|
26
|
+
link_to_page collection.first_page, 'paginate.first_page_label'
|
27
|
+
end
|
28
|
+
html += "\n"
|
11
29
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
30
|
+
|
31
|
+
if show_previous_page?
|
32
|
+
html += content_tag(:li, :class => "previous_page") do
|
33
|
+
link_to_page collection.previous_page, 'paginate.previous_page_label'
|
34
|
+
end
|
35
|
+
html += "\n"
|
15
36
|
end
|
16
37
|
|
17
|
-
html +=
|
38
|
+
html += render_pager
|
18
39
|
|
19
|
-
|
20
|
-
|
21
|
-
|
40
|
+
if show_next_page?
|
41
|
+
html += content_tag(:li, :class => "next_page") do
|
42
|
+
link_to_page collection.next_page, 'paginate.next_page_label'
|
43
|
+
end
|
44
|
+
html += "\n"
|
22
45
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
46
|
+
|
47
|
+
if show_last_page?
|
48
|
+
html += content_tag(:li, :class => "last_page") do
|
49
|
+
link_to_page collection.last_page, 'paginate.last_page_label'
|
50
|
+
end
|
51
|
+
html += "\n"
|
26
52
|
end
|
27
|
-
html += "\n"
|
28
53
|
html.html_safe
|
29
54
|
end
|
30
55
|
end
|
31
56
|
|
32
|
-
|
33
|
-
|
57
|
+
# render pager
|
58
|
+
def render_pager
|
59
|
+
view.reset_cycle(:paginate)
|
34
60
|
|
35
|
-
|
36
|
-
|
37
|
-
|
61
|
+
html = ""
|
62
|
+
visible_pages = pager.visible_pages
|
63
|
+
visible_pages.each do |page|
|
64
|
+
html += content_tag(:li, :class => "pager #{visible_pages.first == page ? 'first_pager' : ''} #{visible_pages.last == page ? 'last_pager' : ''} #{view.cycle("pager_even", "pager_odd", :name => :paginate)}") do
|
38
65
|
link_to_page page, page.nil? ? nil : 'paginate.pager'
|
39
66
|
end
|
67
|
+
html += "\n"
|
40
68
|
end
|
41
|
-
html += "\n"
|
42
69
|
html.html_safe
|
43
70
|
end
|
44
71
|
|
72
|
+
# show first page item?
|
73
|
+
def show_first_page?
|
74
|
+
options[:show_first_page] || self.class.show_first_page
|
75
|
+
end
|
76
|
+
|
77
|
+
# show last page item?
|
78
|
+
def show_last_page?
|
79
|
+
options[:show_last_page] || self.class.show_last_page
|
80
|
+
end
|
81
|
+
|
82
|
+
# show next page item?
|
83
|
+
def show_next_page?
|
84
|
+
options[:show_next_page] || self.class.show_next_page
|
85
|
+
end
|
86
|
+
|
87
|
+
# show previous page item?
|
88
|
+
def show_previous_page?
|
89
|
+
options[:show_previous_page] || self.class.show_previous_page
|
90
|
+
end
|
91
|
+
|
45
92
|
end
|
46
93
|
end
|
data/rails_paginate.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_paginate}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marco Scholl"]
|
@@ -43,6 +43,8 @@ Gem::Specification.new do |s|
|
|
43
43
|
"spec/helpers/action_view_spec.rb",
|
44
44
|
"spec/helpers/active_record_spec.rb",
|
45
45
|
"spec/helpers/array_spec.rb",
|
46
|
+
"spec/pagers/base_spec.rb",
|
47
|
+
"spec/pagers/slider_spec.rb",
|
46
48
|
"spec/rails_paginate_spec.rb",
|
47
49
|
"spec/renderers/base_spec.rb",
|
48
50
|
"spec/renderers/html_default_spec.rb",
|
@@ -59,6 +61,8 @@ Gem::Specification.new do |s|
|
|
59
61
|
"spec/helpers/action_view_spec.rb",
|
60
62
|
"spec/helpers/active_record_spec.rb",
|
61
63
|
"spec/helpers/array_spec.rb",
|
64
|
+
"spec/pagers/base_spec.rb",
|
65
|
+
"spec/pagers/slider_spec.rb",
|
62
66
|
"spec/rails_paginate_spec.rb",
|
63
67
|
"spec/renderers/base_spec.rb",
|
64
68
|
"spec/renderers/html_default_spec.rb",
|
@@ -30,8 +30,7 @@ describe RailsPaginate::Helpers::ActionView do
|
|
30
30
|
context "#paginate with class => dummy" do
|
31
31
|
before { @pagination = action_view.paginate collection, :class => "dummy" }
|
32
32
|
subject { @pagination }
|
33
|
-
|
34
|
-
it { subject.should match(/^<div class="pagination dummy">(.*)<\/div>$/) }
|
33
|
+
it { subject.should match(/<div class="pagination dummy">/) }
|
35
34
|
end
|
36
35
|
|
37
36
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Pagers::Base do
|
4
|
+
let(:collection) { (1..12).to_a.paginate :page => 5 }
|
5
|
+
let(:options) { { :test => 1, :sowas => 2 } }
|
6
|
+
subject { RailsPaginate::Pagers::Base.new collection, options }
|
7
|
+
specify { should respond_to :visible_pages }
|
8
|
+
|
9
|
+
it "#visible_pages should raise StandardError" do
|
10
|
+
lambda { subject.visible_pages }.should raise_error(StandardError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#options should same as given options" do
|
14
|
+
subject.options.should eq options
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#collection should same as given collection" do
|
18
|
+
subject.collection.should eq collection
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Pagers::Slider do
|
4
|
+
|
5
|
+
it "#new without collection should raise StandardError" do
|
6
|
+
lambda { RailsPaginate::Pagers::Slider.new }.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
context :configure do
|
10
|
+
subject { RailsPaginate::Pagers::Slider }
|
11
|
+
context "#inner= 10" do
|
12
|
+
before { subject.inner = 10 }
|
13
|
+
its(:inner) { should eq 10 }
|
14
|
+
end
|
15
|
+
context "#outer= 10" do
|
16
|
+
before { subject.outer = 20 }
|
17
|
+
its(:outer) { should eq 20 }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "collection without items" do
|
22
|
+
before { @array = [] }
|
23
|
+
context "paginate page 1 with 10 per page" do
|
24
|
+
before { @collection = @array.paginate :page => 1, :per_page => 10 }
|
25
|
+
describe "pager with collection and inner 3 and outer 1" do
|
26
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 3, :outer => 1}) }
|
27
|
+
describe "#visible_pages" do
|
28
|
+
subject { @pager.visible_pages }
|
29
|
+
it { should include 1 }
|
30
|
+
it { should_not include 2 }
|
31
|
+
it("#count should equal 1") { subject.count.should eq 1 }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "collection with 500 items" do
|
38
|
+
before { @array = (1...500).to_a }
|
39
|
+
context "paginate page 8 with 10 per page" do
|
40
|
+
before { @collection = @array.paginate :page => 8, :per_page => 10 }
|
41
|
+
describe "pager with collection and inner 3 and outer 1" do
|
42
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 3, :outer => 1}) }
|
43
|
+
describe "#visible_pages" do
|
44
|
+
subject { @pager.visible_pages }
|
45
|
+
it { should include 1 }
|
46
|
+
it { should_not include 2 }
|
47
|
+
it { should include 5 }
|
48
|
+
it { should include 6 }
|
49
|
+
it { should include 7 }
|
50
|
+
it { should include 8 }
|
51
|
+
it { should include 9 }
|
52
|
+
it { should include 10 }
|
53
|
+
it { should include 11 }
|
54
|
+
it { should_not include 12 }
|
55
|
+
it { should_not include 49 }
|
56
|
+
it { should include 50 }
|
57
|
+
it("#count should equal 8") { subject.count.should eq 11 }
|
58
|
+
it("#at(1) should be nil") { subject.at(1).should be_nil }
|
59
|
+
it("#at(49) should be nil") { subject.at(49).should be_nil }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "paginate page 2 with 50 per page" do
|
65
|
+
before { @collection = @array.paginate :page => 2, :per_page => 50 }
|
66
|
+
describe "pager with collection and inner 3 and outer 2" do
|
67
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 3, :outer => 2}) }
|
68
|
+
describe "#visible_pages" do
|
69
|
+
subject { @pager.visible_pages }
|
70
|
+
it { should include 1 }
|
71
|
+
it { should include 2 }
|
72
|
+
it { should include 3 }
|
73
|
+
it { should include 4 }
|
74
|
+
it { should include 5 }
|
75
|
+
it { should_not include 6 }
|
76
|
+
it { should_not include 7 }
|
77
|
+
it { should_not include 8 }
|
78
|
+
it { should include 9 }
|
79
|
+
it { should include 10 }
|
80
|
+
it("#count should equal 8") { subject.count.should eq 8 }
|
81
|
+
it("#at(5) should be nil") { subject.at(5).should be_nil }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "paginate page 6 with 13 per page" do
|
87
|
+
before { @collection = @array.paginate :page => 6, :per_page => 13 }
|
88
|
+
describe "pager with collection and inner 4 and outer 0" do
|
89
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 4, :outer => 0}) }
|
90
|
+
describe "#visible_pages" do
|
91
|
+
subject { @pager.visible_pages }
|
92
|
+
it { should_not include 1 }
|
93
|
+
it { should include 2 }
|
94
|
+
it { should include 3 }
|
95
|
+
it { should include 4 }
|
96
|
+
it { should include 5 }
|
97
|
+
it { should include 6 }
|
98
|
+
it { should include 7 }
|
99
|
+
it { should include 8 }
|
100
|
+
it { should include 9 }
|
101
|
+
it { should include 10 }
|
102
|
+
it { should_not include 11 }
|
103
|
+
it("#count should equal 9") { subject.count.should eq 9 }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "paginate page 6 with 12 per page" do
|
109
|
+
before { @collection = @array.paginate :page => 6, :per_page => 12 }
|
110
|
+
describe "pager with collection and inner 0 and outer 2" do
|
111
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 0, :outer => 2}) }
|
112
|
+
describe "#visible_pages" do
|
113
|
+
subject { @pager.visible_pages }
|
114
|
+
it { should include 1 }
|
115
|
+
it { should include 2 }
|
116
|
+
it { should_not include 3 }
|
117
|
+
it { should_not include 7 }
|
118
|
+
it { should include 6 }
|
119
|
+
it { should_not include 8 }
|
120
|
+
it { should_not include 40 }
|
121
|
+
it { should include 41 }
|
122
|
+
it { should include 42 }
|
123
|
+
it { should_not include 43 }
|
124
|
+
it("#count should equal 7") { subject.count.should eq 7 }
|
125
|
+
it("#at(2) should be nil") { subject.at(2).should be_nil }
|
126
|
+
it("#at(40) should be nil") { subject.at(40).should be_nil }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "paginate page 3 with 100 per page" do
|
132
|
+
before { @collection = @array.paginate :page => 3, :per_page => 100 }
|
133
|
+
describe "pager with collection and inner 0 and outer 0" do
|
134
|
+
before { @pager = RailsPaginate::Pagers::Slider.new(@collection, {:inner => 0, :outer => 0}) }
|
135
|
+
describe "#visible_pages" do
|
136
|
+
subject { @pager.visible_pages }
|
137
|
+
it { should_not include 1 }
|
138
|
+
it { should_not include 2 }
|
139
|
+
it { should include 3 }
|
140
|
+
it { should_not include 4 }
|
141
|
+
it { should_not include 5 }
|
142
|
+
it("#count should equal 1") { subject.count.should eq 1 }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rails_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marco Scholl
|
@@ -137,6 +137,8 @@ files:
|
|
137
137
|
- spec/helpers/action_view_spec.rb
|
138
138
|
- spec/helpers/active_record_spec.rb
|
139
139
|
- spec/helpers/array_spec.rb
|
140
|
+
- spec/pagers/base_spec.rb
|
141
|
+
- spec/pagers/slider_spec.rb
|
140
142
|
- spec/rails_paginate_spec.rb
|
141
143
|
- spec/renderers/base_spec.rb
|
142
144
|
- spec/renderers/html_default_spec.rb
|
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
requirements:
|
158
160
|
- - ">="
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
hash: -
|
162
|
+
hash: -185373245493970734
|
161
163
|
segments:
|
162
164
|
- 0
|
163
165
|
version: "0"
|
@@ -178,6 +180,8 @@ test_files:
|
|
178
180
|
- spec/helpers/action_view_spec.rb
|
179
181
|
- spec/helpers/active_record_spec.rb
|
180
182
|
- spec/helpers/array_spec.rb
|
183
|
+
- spec/pagers/base_spec.rb
|
184
|
+
- spec/pagers/slider_spec.rb
|
181
185
|
- spec/rails_paginate_spec.rb
|
182
186
|
- spec/renderers/base_spec.rb
|
183
187
|
- spec/renderers/html_default_spec.rb
|