rails_paginate 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rails_paginate/collection.rb +6 -1
- data/lib/rails_paginate/helpers/action_view.rb +34 -0
- data/lib/rails_paginate/helpers/active_record.rb +10 -0
- data/lib/rails_paginate/helpers/array.rb +10 -0
- data/lib/rails_paginate/helpers.rb +8 -0
- data/lib/rails_paginate/pagers/base.rb +21 -0
- data/lib/rails_paginate/pagers/slider.rb +51 -0
- data/lib/rails_paginate/pagers.rb +7 -0
- data/lib/rails_paginate/renderers/base.rb +68 -0
- data/lib/rails_paginate/renderers/html_default.rb +46 -0
- data/lib/rails_paginate/renderers.rb +8 -0
- data/lib/rails_paginate.rb +28 -22
- data/rails_paginate.gemspec +26 -18
- data/spec/helpers/action_view_spec.rb +38 -0
- data/spec/helpers/active_record_spec.rb +11 -0
- data/spec/helpers/array_spec.rb +11 -0
- data/spec/rails_paginate_spec.rb +8 -18
- data/spec/renderers/base_spec.rb +12 -0
- data/spec/renderers/html_default_spec.rb +12 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/{10_activerecord.rb → 10_active_record.rb} +6 -1
- data/spec/support/20_action_controller.rb +4 -0
- metadata +27 -19
- data/lib/rails_paginate/core_ext/active_record.rb +0 -9
- data/lib/rails_paginate/core_ext/array.rb +0 -8
- data/lib/rails_paginate/method/base.rb +0 -5
- data/lib/rails_paginate/method/jumping.rb +0 -6
- data/lib/rails_paginate/method/sliding.rb +0 -6
- data/lib/rails_paginate/method.rb +0 -8
- data/lib/rails_paginate/renderer/base.rb +0 -5
- data/lib/rails_paginate/renderer/html_default.rb +0 -6
- data/lib/rails_paginate/renderer/html_list.rb +0 -6
- data/lib/rails_paginate/renderer.rb +0 -8
- data/spec/db/migrate/20110215200000_create_items.rb +0 -7
- data/spec/renderer_html_default_spec.rb +0 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -13,11 +13,16 @@ module RailsPaginate
|
|
13
13
|
@array_or_relation = array_or_relation
|
14
14
|
|
15
15
|
# save meta data
|
16
|
-
@per_page = per_page || RailsPaginate.per_page
|
16
|
+
@per_page = per_page || relation_per_page || RailsPaginate.per_page
|
17
17
|
|
18
18
|
# load page with result
|
19
19
|
load_page(page) unless page.nil?
|
20
20
|
end
|
21
|
+
|
22
|
+
# check if the relation has a per_page
|
23
|
+
def relation_per_page
|
24
|
+
(array_or_relation.respond_to?(:per_page) ? array_or_relation.per_page : nil) unless array_or_relation.is_a? Array
|
25
|
+
end
|
21
26
|
|
22
27
|
# switch page
|
23
28
|
def load_page(page)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RailsPaginate::Helpers
|
2
|
+
module ActionView
|
3
|
+
# view_helper for paginate
|
4
|
+
#
|
5
|
+
# == Options
|
6
|
+
# :id
|
7
|
+
# :class
|
8
|
+
def paginate(*args)
|
9
|
+
options = args.extract_options!
|
10
|
+
|
11
|
+
raise ArgumentError, "first argument muss be a RailsPaginate::Collection" unless args.first.is_a? RailsPaginate::Collection
|
12
|
+
|
13
|
+
collection = args.first
|
14
|
+
# p @controller
|
15
|
+
# p url_for(:action => :index, :controller => :dummy)
|
16
|
+
|
17
|
+
# renderer
|
18
|
+
renderer = options[:renderer] || RailsPaginate.default_renderer
|
19
|
+
pager = options[:pager] || RailsPaginate.default_pager
|
20
|
+
|
21
|
+
attributes = {}
|
22
|
+
attributes[:class] = "pagination #{options[:class]}".strip
|
23
|
+
attributes[:id] = options[:id] unless options[:id].blank?
|
24
|
+
|
25
|
+
# load classes
|
26
|
+
renderer = RailsPaginate.renderer(renderer)
|
27
|
+
pager = RailsPaginate.pager(pager)
|
28
|
+
|
29
|
+
content_tag :div, attributes do
|
30
|
+
renderer.new(self, collection, pager.new(collection), options).render
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module RailsPaginate::Helpers
|
2
|
+
module Array
|
3
|
+
def paginate(*args)
|
4
|
+
options = args.extract_options!
|
5
|
+
per_page = options.delete(:per_page)
|
6
|
+
page = options.delete(:page) || 1
|
7
|
+
::RailsPaginate::Collection.new(self, args.first || page, per_page)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RailsPaginate::Pagers
|
2
|
+
# base method
|
3
|
+
class Base
|
4
|
+
attr_reader :collection
|
5
|
+
def initialize(collection)
|
6
|
+
@collection = collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_page
|
10
|
+
collection.current_page
|
11
|
+
end
|
12
|
+
|
13
|
+
def pages
|
14
|
+
collection.pages
|
15
|
+
end
|
16
|
+
|
17
|
+
def visible_pages
|
18
|
+
raise StandardError, "render is not implemented"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RailsPaginate::Pagers
|
2
|
+
# slider method
|
3
|
+
class Slider < Base
|
4
|
+
cattr_reader :inner, :outer
|
5
|
+
@@inner = 2
|
6
|
+
@@outer = 2
|
7
|
+
|
8
|
+
def visible_pages
|
9
|
+
visible = []
|
10
|
+
last_inserted = 0
|
11
|
+
splited = false
|
12
|
+
(1..pages).each do |page|
|
13
|
+
# insert
|
14
|
+
if visible? page
|
15
|
+
visible << page
|
16
|
+
last_inserted = page
|
17
|
+
splited = false
|
18
|
+
else
|
19
|
+
# need splitter
|
20
|
+
if not splited and outer > 0 and last_inserted < page
|
21
|
+
visible << nil
|
22
|
+
splited = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
visible
|
27
|
+
end
|
28
|
+
|
29
|
+
def inner_range
|
30
|
+
@inner_range ||= (current_page - inner)..(current_page + inner)
|
31
|
+
end
|
32
|
+
|
33
|
+
# looks should this page visible
|
34
|
+
def visible?(page)
|
35
|
+
# outer
|
36
|
+
if outer > 0
|
37
|
+
return true if outer >= page
|
38
|
+
return true if (pages - outer) < page
|
39
|
+
end
|
40
|
+
|
41
|
+
# current page
|
42
|
+
return true if current_page == page
|
43
|
+
|
44
|
+
# inner
|
45
|
+
return true if inner_range.include? page
|
46
|
+
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module RailsPaginate::Renderers
|
2
|
+
# base method
|
3
|
+
class Base
|
4
|
+
attr_reader :view, :collection, :options, :pager
|
5
|
+
|
6
|
+
def initialize(view, collection, pager, options = {})
|
7
|
+
raise ArgumentError, "first argument muss be a RailsPaginate::Collection" unless collection.is_a? RailsPaginate::Collection
|
8
|
+
raise ArgumentError, "second argument muss be a Hash" unless options.is_a? Hash
|
9
|
+
raise ArgumentError, "third argument muss be an instance of RailsPaginate::Pagers::Base" unless pager.is_a? RailsPaginate::Pagers::Base
|
10
|
+
@options = options
|
11
|
+
@collection = collection
|
12
|
+
@view = view
|
13
|
+
@pager = pager
|
14
|
+
end
|
15
|
+
|
16
|
+
def url_for_page(page)
|
17
|
+
# todo: fix url_for so did't neet fallback
|
18
|
+
begin
|
19
|
+
view.url_for(view.default_url_options.merge({:page => page}))
|
20
|
+
rescue
|
21
|
+
"?page=#{page}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def render
|
26
|
+
raise StandardError, "render is not implemented"
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def link_to_page(page, key, options = {})
|
32
|
+
css_class = "#{options[:class]} #{page == current_page ? 'current' : ''}"
|
33
|
+
if key.nil?
|
34
|
+
content_tag :span, "..", :class => "spacer"
|
35
|
+
elsif page.nil?
|
36
|
+
content_tag :span, t(key), :class => "#{css_class} unavailable"
|
37
|
+
else
|
38
|
+
link_to t(key, :page => page), url_for_page(page), :class => css_class, :alt => view.strip_tags(t(key, :page => page))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# helper
|
43
|
+
def current_page
|
44
|
+
collection.current_page
|
45
|
+
end
|
46
|
+
|
47
|
+
def content_tag(*args, &block)
|
48
|
+
view.content_tag(*args, &block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def link_to(*args, &block)
|
52
|
+
view.link_to(*args, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def t(*args)
|
56
|
+
view.t(*args)
|
57
|
+
end
|
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
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RailsPaginate::Renderers
|
2
|
+
# normale renderer
|
3
|
+
class HtmlDefault < Base
|
4
|
+
|
5
|
+
|
6
|
+
def render
|
7
|
+
view.content_tag(:ul) do
|
8
|
+
html = "\n"
|
9
|
+
html += content_tag(:li, :class => "first_page") do
|
10
|
+
link_to_page collection.first_page, 'paginate.first_page_label'
|
11
|
+
end
|
12
|
+
html += "\n"
|
13
|
+
html += content_tag(:li, :class => "previous_page") do
|
14
|
+
link_to_page collection.previous_page, 'paginate.previous_page_label'
|
15
|
+
end
|
16
|
+
|
17
|
+
html += render_pages
|
18
|
+
|
19
|
+
html += "\n"
|
20
|
+
html += content_tag(:li, :class => "next_page") do
|
21
|
+
link_to_page collection.next_page, 'paginate.next_page_label'
|
22
|
+
end
|
23
|
+
html += "\n"
|
24
|
+
html += content_tag(:li, :class => "last_page") do
|
25
|
+
link_to_page collection.last_page, 'paginate.last_page_label'
|
26
|
+
end
|
27
|
+
html += "\n"
|
28
|
+
html.html_safe
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render_pages
|
33
|
+
html = ""
|
34
|
+
|
35
|
+
pager.visible_pages.each do |page|
|
36
|
+
html += "\n"
|
37
|
+
html += content_tag(:li, :class => "pager") do
|
38
|
+
link_to_page page, page.nil? ? nil : 'paginate.pager'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
html += "\n"
|
42
|
+
html.html_safe
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/rails_paginate.rb
CHANGED
@@ -2,8 +2,10 @@ require 'active_support/all'
|
|
2
2
|
|
3
3
|
# nice rails paginate plugin
|
4
4
|
module RailsPaginate
|
5
|
-
autoload :
|
5
|
+
autoload :Renderers, 'rails_paginate/renderers'
|
6
6
|
autoload :Collection, 'rails_paginate/collection'
|
7
|
+
autoload :Helpers, 'rails_paginate/helpers'
|
8
|
+
autoload :Pagers, 'rails_paginate/pagers'
|
7
9
|
|
8
10
|
# page_param
|
9
11
|
mattr_accessor :page_param
|
@@ -13,9 +15,13 @@ module RailsPaginate
|
|
13
15
|
mattr_accessor :per_page
|
14
16
|
@@per_page = 20
|
15
17
|
|
16
|
-
#
|
17
|
-
mattr_accessor :
|
18
|
-
@@
|
18
|
+
# default_renderer
|
19
|
+
mattr_accessor :default_renderer
|
20
|
+
@@default_renderer = :html_default
|
21
|
+
|
22
|
+
# default_pager
|
23
|
+
mattr_accessor :default_pager
|
24
|
+
@@default_pager = :slider
|
19
25
|
|
20
26
|
class << self
|
21
27
|
# to configure rails_paginate
|
@@ -24,28 +30,28 @@ module RailsPaginate
|
|
24
30
|
yield self
|
25
31
|
end
|
26
32
|
|
27
|
-
# renderer
|
28
|
-
def renderer(renderer
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
33
|
+
# return renderer
|
34
|
+
def renderer(renderer)
|
35
|
+
raise ArgumentError, "renderer #{renderer} is not valid" unless (renderer.is_a? Symbol or renderer.is_a? String or renderer.is_a? Class)
|
36
|
+
renderer = renderer.to_s if renderer.is_a? Symbol
|
37
|
+
renderer = "rails_paginate/renderers/#{renderer}".camelize.constantize if renderer.is_a? String
|
38
|
+
renderer
|
39
|
+
end
|
40
|
+
|
41
|
+
# return pager
|
42
|
+
def pager(pager)
|
43
|
+
raise ArgumentError, "pager #{pager} is not valid" unless (pager.is_a? Symbol or pager.is_a? String or pager.is_a? Class)
|
44
|
+
pager = pager.to_s if pager.is_a? Symbol
|
45
|
+
pager = "rails_paginate/pagers/#{pager}".camelize.constantize if pager.is_a? String
|
46
|
+
pager
|
43
47
|
end
|
44
48
|
|
45
49
|
# init rails paginate
|
46
50
|
def init
|
47
|
-
|
48
|
-
|
51
|
+
::Array.send(:include, Helpers::Array)
|
52
|
+
::ActiveRecord::Base.send(:extend, Helpers::ActiveRecord) if defined?(::ActiveRecord::Base)
|
53
|
+
::ActiveRecord::Relation.send(:include, Helpers::ActiveRecord) if defined?(::ActiveRecord::Relation)
|
54
|
+
::ActionView::Base.send(:include, Helpers::ActionView) if defined?(::ActionView::Base)
|
49
55
|
|
50
56
|
# set default method
|
51
57
|
renderer :html_default
|
data/rails_paginate.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.3"
|
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"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-17}
|
13
13
|
s.description = %q{a new rails 3 paginate plugin as will_paginate replacement}
|
14
14
|
s.email = %q{develop@marco-scholl.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,22 +29,26 @@ Gem::Specification.new do |s|
|
|
29
29
|
"init.rb",
|
30
30
|
"lib/rails_paginate.rb",
|
31
31
|
"lib/rails_paginate/collection.rb",
|
32
|
-
"lib/rails_paginate/
|
33
|
-
"lib/rails_paginate/
|
34
|
-
"lib/rails_paginate/
|
35
|
-
"lib/rails_paginate/
|
36
|
-
"lib/rails_paginate/
|
37
|
-
"lib/rails_paginate/
|
38
|
-
"lib/rails_paginate/
|
39
|
-
"lib/rails_paginate/
|
40
|
-
"lib/rails_paginate/
|
41
|
-
"lib/rails_paginate/
|
32
|
+
"lib/rails_paginate/helpers.rb",
|
33
|
+
"lib/rails_paginate/helpers/action_view.rb",
|
34
|
+
"lib/rails_paginate/helpers/active_record.rb",
|
35
|
+
"lib/rails_paginate/helpers/array.rb",
|
36
|
+
"lib/rails_paginate/pagers.rb",
|
37
|
+
"lib/rails_paginate/pagers/base.rb",
|
38
|
+
"lib/rails_paginate/pagers/slider.rb",
|
39
|
+
"lib/rails_paginate/renderers.rb",
|
40
|
+
"lib/rails_paginate/renderers/base.rb",
|
41
|
+
"lib/rails_paginate/renderers/html_default.rb",
|
42
42
|
"rails_paginate.gemspec",
|
43
|
-
"spec/
|
43
|
+
"spec/helpers/action_view_spec.rb",
|
44
|
+
"spec/helpers/active_record_spec.rb",
|
45
|
+
"spec/helpers/array_spec.rb",
|
44
46
|
"spec/rails_paginate_spec.rb",
|
45
|
-
"spec/
|
47
|
+
"spec/renderers/base_spec.rb",
|
48
|
+
"spec/renderers/html_default_spec.rb",
|
46
49
|
"spec/spec_helper.rb",
|
47
|
-
"spec/support/
|
50
|
+
"spec/support/10_active_record.rb",
|
51
|
+
"spec/support/20_action_controller.rb"
|
48
52
|
]
|
49
53
|
s.homepage = %q{http://github.com/phatworx/rails_paginate}
|
50
54
|
s.licenses = ["MIT"]
|
@@ -52,11 +56,15 @@ Gem::Specification.new do |s|
|
|
52
56
|
s.rubygems_version = %q{1.5.0}
|
53
57
|
s.summary = %q{a new rails 3 paginate plugin}
|
54
58
|
s.test_files = [
|
55
|
-
"spec/
|
59
|
+
"spec/helpers/action_view_spec.rb",
|
60
|
+
"spec/helpers/active_record_spec.rb",
|
61
|
+
"spec/helpers/array_spec.rb",
|
56
62
|
"spec/rails_paginate_spec.rb",
|
57
|
-
"spec/
|
63
|
+
"spec/renderers/base_spec.rb",
|
64
|
+
"spec/renderers/html_default_spec.rb",
|
58
65
|
"spec/spec_helper.rb",
|
59
|
-
"spec/support/
|
66
|
+
"spec/support/10_active_record.rb",
|
67
|
+
"spec/support/20_action_controller.rb"
|
60
68
|
]
|
61
69
|
|
62
70
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Helpers::ActionView do
|
4
|
+
context "ActionView::Base.new" do
|
5
|
+
let(:collection) { (1..55).to_a.paginate }
|
6
|
+
subject { action_view }
|
7
|
+
specify { should respond_to :paginate }
|
8
|
+
|
9
|
+
it "#paginate should raise an error when no collection given" do
|
10
|
+
lambda { subject.paginate }.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
[
|
14
|
+
{:items => 100, :page => 1, :per_page => 15},
|
15
|
+
{:items => 300, :page => 2, :per_page => 50},
|
16
|
+
{:items => 11, :page => 5, :per_page => 15},
|
17
|
+
{:items => 0, :page => 1, :per_page => 15},
|
18
|
+
{:items => 12, :page => 1, :per_page => 15}
|
19
|
+
].each do |config|
|
20
|
+
context "#paginate an Array with #{config[:items]} items, page #{config[:page]}, per_page #{config[:per_page]}" do
|
21
|
+
before do
|
22
|
+
@collection = (1..config[:items]).to_a.paginate :page => config[:page], :per_page => config[:per_page]
|
23
|
+
@pagination = action_view.paginate @collection
|
24
|
+
end
|
25
|
+
subject { @pagination }
|
26
|
+
it("return should be a kind of String") { should be_a String }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#paginate with class => dummy" do
|
31
|
+
before { @pagination = action_view.paginate collection, :class => "dummy" }
|
32
|
+
subject { @pagination }
|
33
|
+
|
34
|
+
it { subject.should match(/^<div class="pagination dummy">(.*)<\/div>$/) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Helpers::ActiveRecord do
|
4
|
+
subject { Item }
|
5
|
+
specify { should respond_to :paginate }
|
6
|
+
|
7
|
+
describe "return of #paginate" do
|
8
|
+
subject { Item.paginate }
|
9
|
+
it { should be_a RailsPaginate::Collection }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Helpers::Array do
|
4
|
+
subject { Array.new }
|
5
|
+
specify { should respond_to :paginate }
|
6
|
+
|
7
|
+
describe "return of #paginate" do
|
8
|
+
subject { Array.new.paginate }
|
9
|
+
it { should be_a RailsPaginate::Collection }
|
10
|
+
end
|
11
|
+
end
|
data/spec/rails_paginate_spec.rb
CHANGED
@@ -14,24 +14,14 @@ describe RailsPaginate do
|
|
14
14
|
before { subject.page_param = :p }
|
15
15
|
its(:page_param) { should be :p }
|
16
16
|
end
|
17
|
+
end
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
describe :renderer, "set to :html_list" do
|
24
|
-
before { subject.renderer :html_list }
|
25
|
-
its(:renderer) { should be_a RailsPaginate::Renderer::HtmlList }
|
26
|
-
end
|
27
|
-
|
28
|
-
describe :renderer, "set with block" do
|
29
|
-
setup.renderer :html_list do |renderer_setup|
|
30
|
-
subject { renderer_setup }
|
31
|
-
its(:renderer) { should be_a RailsPaginate::Renderer::HtmlDefault }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
20
|
+
describe :renderer do
|
21
|
+
context ":html_default" do
|
22
|
+
before { @renderer = RailsPaginate.renderer :html_default }
|
23
|
+
subject { @renderer }
|
24
|
+
it { should eq RailsPaginate::Renderers::HtmlDefault }
|
35
25
|
end
|
36
26
|
end
|
37
27
|
end
|
@@ -45,7 +35,7 @@ describe RailsPaginate::Collection do
|
|
45
35
|
|
46
36
|
describe Item, "with 561 items" do
|
47
37
|
before(:all) do
|
48
|
-
|
38
|
+
561.times { |x| Item.create! :dummy => "Item #{x}" }
|
49
39
|
end
|
50
40
|
subject { Item }
|
51
41
|
specify { should respond_to :paginate }
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Renderers::Base do
|
4
|
+
let(:collection) { [].paginate }
|
5
|
+
subject { RailsPaginate::Renderers::Base.new action_view, collection, RailsPaginate.pager(:slider).new(collection) }
|
6
|
+
specify { should respond_to :render }
|
7
|
+
|
8
|
+
it "#render should raise StandardError" do
|
9
|
+
lambda { subject.render }.should raise_error(StandardError)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RailsPaginate::Renderers::HtmlDefault do
|
4
|
+
let(:collection) { [].paginate }
|
5
|
+
subject { RailsPaginate::Renderers::HtmlDefault.new action_view, collection, RailsPaginate.pager(:slider).new(collection) }
|
6
|
+
specify { should respond_to :render }
|
7
|
+
|
8
|
+
it "#render should not raise StandardError" do
|
9
|
+
lambda { subject.render }.should_not raise_error(StandardError)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,13 @@ unless defined? JRUBY_VERSION
|
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'rspec'
|
9
|
+
require 'active_record'
|
10
|
+
require 'action_view'
|
11
|
+
require 'active_support'
|
12
|
+
require 'active_support/test_case'
|
13
|
+
require 'action_controller'
|
14
|
+
require 'action_controller/test_case'
|
15
|
+
require 'action_dispatch'
|
9
16
|
require 'rails_paginate'
|
10
17
|
|
11
18
|
# Requires supporting files with custom matchers and macros, etc,
|
@@ -13,5 +20,30 @@ require 'rails_paginate'
|
|
13
20
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
14
21
|
|
15
22
|
RSpec.configure do |config|
|
23
|
+
def action_view
|
24
|
+
x = ActionView::Base.new
|
25
|
+
x.controller = action_controller
|
26
|
+
x.request = action_controller.request
|
27
|
+
x
|
28
|
+
end
|
29
|
+
|
30
|
+
def action_controller
|
31
|
+
x = DummyController.new
|
32
|
+
x.request = test_request
|
33
|
+
x.response = test_response
|
34
|
+
x
|
35
|
+
end
|
36
|
+
|
37
|
+
def routes
|
38
|
+
ActionDispatch::Routing::RouteSet.new.draw { root :to => "index#dummy" }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_request
|
42
|
+
ActionController::TestRequest.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_response
|
46
|
+
ActionController::TestResponse.new
|
47
|
+
end
|
16
48
|
|
17
49
|
end
|
@@ -2,7 +2,12 @@ ActiveRecord::Base.establish_connection({
|
|
2
2
|
:adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'),
|
3
3
|
:database => ":memory:"
|
4
4
|
})
|
5
|
-
|
5
|
+
|
6
|
+
ActiveRecord::Schema.define(:version => 0) do
|
7
|
+
create_table :items, :force => true do |t|
|
8
|
+
t.column :dummy, :string
|
9
|
+
end
|
10
|
+
end
|
6
11
|
|
7
12
|
class Item < ActiveRecord::Base
|
8
13
|
scope :reverse_sort, order("dummy DESC")
|
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.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Marco Scholl
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-17 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -123,22 +123,26 @@ files:
|
|
123
123
|
- init.rb
|
124
124
|
- lib/rails_paginate.rb
|
125
125
|
- lib/rails_paginate/collection.rb
|
126
|
-
- lib/rails_paginate/
|
127
|
-
- lib/rails_paginate/
|
128
|
-
- lib/rails_paginate/
|
129
|
-
- lib/rails_paginate/
|
130
|
-
- lib/rails_paginate/
|
131
|
-
- lib/rails_paginate/
|
132
|
-
- lib/rails_paginate/
|
133
|
-
- lib/rails_paginate/
|
134
|
-
- lib/rails_paginate/
|
135
|
-
- lib/rails_paginate/
|
126
|
+
- lib/rails_paginate/helpers.rb
|
127
|
+
- lib/rails_paginate/helpers/action_view.rb
|
128
|
+
- lib/rails_paginate/helpers/active_record.rb
|
129
|
+
- lib/rails_paginate/helpers/array.rb
|
130
|
+
- lib/rails_paginate/pagers.rb
|
131
|
+
- lib/rails_paginate/pagers/base.rb
|
132
|
+
- lib/rails_paginate/pagers/slider.rb
|
133
|
+
- lib/rails_paginate/renderers.rb
|
134
|
+
- lib/rails_paginate/renderers/base.rb
|
135
|
+
- lib/rails_paginate/renderers/html_default.rb
|
136
136
|
- rails_paginate.gemspec
|
137
|
-
- spec/
|
137
|
+
- spec/helpers/action_view_spec.rb
|
138
|
+
- spec/helpers/active_record_spec.rb
|
139
|
+
- spec/helpers/array_spec.rb
|
138
140
|
- spec/rails_paginate_spec.rb
|
139
|
-
- spec/
|
141
|
+
- spec/renderers/base_spec.rb
|
142
|
+
- spec/renderers/html_default_spec.rb
|
140
143
|
- spec/spec_helper.rb
|
141
|
-
- spec/support/
|
144
|
+
- spec/support/10_active_record.rb
|
145
|
+
- spec/support/20_action_controller.rb
|
142
146
|
has_rdoc: true
|
143
147
|
homepage: http://github.com/phatworx/rails_paginate
|
144
148
|
licenses:
|
@@ -153,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
157
|
requirements:
|
154
158
|
- - ">="
|
155
159
|
- !ruby/object:Gem::Version
|
156
|
-
hash: -
|
160
|
+
hash: -622289539687505724
|
157
161
|
segments:
|
158
162
|
- 0
|
159
163
|
version: "0"
|
@@ -171,8 +175,12 @@ signing_key:
|
|
171
175
|
specification_version: 3
|
172
176
|
summary: a new rails 3 paginate plugin
|
173
177
|
test_files:
|
174
|
-
- spec/
|
178
|
+
- spec/helpers/action_view_spec.rb
|
179
|
+
- spec/helpers/active_record_spec.rb
|
180
|
+
- spec/helpers/array_spec.rb
|
175
181
|
- spec/rails_paginate_spec.rb
|
176
|
-
- spec/
|
182
|
+
- spec/renderers/base_spec.rb
|
183
|
+
- spec/renderers/html_default_spec.rb
|
177
184
|
- spec/spec_helper.rb
|
178
|
-
- spec/support/
|
185
|
+
- spec/support/10_active_record.rb
|
186
|
+
- spec/support/20_action_controller.rb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
class ActiveRecord::Base
|
3
|
-
def self.paginate(*args)
|
4
|
-
options = args.extract_options!
|
5
|
-
per_page = options.delete(:per_page) || RailsPaginate.per_page
|
6
|
-
page = options.delete(:page) || 1
|
7
|
-
RailsPaginate::Collection.new(self, page, per_page)
|
8
|
-
end
|
9
|
-
end
|