rails_paginate 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -1
- data/README.rdoc +46 -15
- data/VERSION +1 -1
- data/lib/generators/rails_paginate/install_generator.rb +15 -0
- data/lib/generators/templates/config/initializers/paginate.rb +25 -0
- data/lib/generators/templates/config/locales/de.yml +7 -0
- data/lib/generators/templates/config/locales/en.yml +7 -0
- data/lib/rails_paginate.rb +11 -5
- data/lib/rails_paginate/collection.rb +6 -4
- data/lib/rails_paginate/helpers/action_view.rb +1 -0
- data/lib/rails_paginate/helpers/active_record.rb +5 -0
- data/lib/rails_paginate/helpers/array.rb +5 -0
- data/lib/rails_paginate/pagers/base.rb +6 -0
- data/lib/rails_paginate/pagers/slider.rb +10 -1
- data/lib/rails_paginate/rails.rb +4 -0
- data/lib/rails_paginate/renderers.rb +0 -1
- data/lib/rails_paginate/renderers/base.rb +13 -6
- data/lib/rails_paginate/renderers/html_default.rb +3 -1
- data/rails_paginate.gemspec +12 -6
- data/spec/helpers/action_view_spec.rb +3 -3
- data/spec/renderers/html_default_spec.rb +38 -5
- data/spec/spec_helper.rb +8 -17
- metadata +21 -7
- data/spec/support/20_action_controller.rb +0 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
ZenTest (4.
|
4
|
+
ZenTest (4.5.0)
|
5
5
|
abstract (1.0.0)
|
6
6
|
actionmailer (3.0.4)
|
7
7
|
actionpack (= 3.0.4)
|
@@ -37,6 +37,8 @@ GEM
|
|
37
37
|
erubis (2.6.6)
|
38
38
|
abstract (>= 1.0.0)
|
39
39
|
git (1.2.5)
|
40
|
+
hpricot (0.8.3)
|
41
|
+
hpricot (0.8.3-java)
|
40
42
|
i18n (0.5.0)
|
41
43
|
jeweler (1.5.2)
|
42
44
|
bundler (~> 1.0.0)
|
@@ -75,6 +77,8 @@ GEM
|
|
75
77
|
rspec-core (2.5.1)
|
76
78
|
rspec-expectations (2.5.0)
|
77
79
|
diff-lcs (~> 1.1.2)
|
80
|
+
rspec-hpricot-matchers (0.0.3)
|
81
|
+
hpricot
|
78
82
|
rspec-mocks (2.5.0)
|
79
83
|
simplecov (0.4.0)
|
80
84
|
simplecov-html (~> 0.4.0)
|
@@ -96,6 +100,7 @@ DEPENDENCIES
|
|
96
100
|
jeweler
|
97
101
|
rails (~> 3.0.0)
|
98
102
|
rspec
|
103
|
+
rspec-hpricot-matchers
|
99
104
|
simplecov
|
100
105
|
sqlite3
|
101
106
|
yard
|
data/README.rdoc
CHANGED
@@ -2,25 +2,52 @@
|
|
2
2
|
|
3
3
|
a new rails 3 paginate plugin as will_paginate replacement
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
* Collection
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
* -> Rspec - 100%
|
5
|
+
== Features
|
6
|
+
|
7
|
+
* Collection support
|
8
|
+
* - Array
|
9
|
+
* - ActiveRecord
|
10
|
+
* View helper for pagination
|
11
|
+
* Renderer
|
12
|
+
* - HTML list renderer (:html_default)
|
13
|
+
* Pager
|
14
|
+
* - Slider
|
15
|
+
* I18n support
|
17
16
|
|
18
17
|
== Installation
|
19
|
-
|
18
|
+
|
19
|
+
add to Gemfile
|
20
20
|
gem "rails_paginate"
|
21
21
|
|
22
|
-
|
23
|
-
rails
|
22
|
+
after bundle execute
|
23
|
+
rails g rails_paginate:install
|
24
|
+
|
25
|
+
== Configuration
|
26
|
+
|
27
|
+
RailsPaginate.setup do |config|
|
28
|
+
# config.per_page = 20
|
29
|
+
# config.page_param = :page
|
30
|
+
|
31
|
+
# configure default renderer
|
32
|
+
# config.default_renderer = :html_default
|
33
|
+
|
34
|
+
# configure renderer
|
35
|
+
# config.renderer :html_default do |renderer|
|
36
|
+
# renderer.show_first_page = false
|
37
|
+
# renderer.show_last_page = false
|
38
|
+
# renderer.show_next_page = false
|
39
|
+
# renderer.show_previous_page = false
|
40
|
+
# end
|
41
|
+
|
42
|
+
# configure default default_pager
|
43
|
+
# config.default_pager = :slider
|
44
|
+
|
45
|
+
# configure pager
|
46
|
+
# config.pager :slider do |pager|
|
47
|
+
# pager.inner = 3
|
48
|
+
# pager.outer = 1
|
49
|
+
# end
|
50
|
+
end
|
24
51
|
|
25
52
|
== Using
|
26
53
|
|
@@ -32,6 +59,10 @@ If you want to use it as plugin
|
|
32
59
|
|
33
60
|
(1..555).to_a.paginate :page => 1, :per_page => 10
|
34
61
|
|
62
|
+
== Requirements
|
63
|
+
|
64
|
+
* Rails 3 (http://github.com/rails/rails)
|
65
|
+
|
35
66
|
== Test environments
|
36
67
|
|
37
68
|
* ruby-1.9.2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RailsPaginate
|
2
|
+
module Generators # :nodoc:
|
3
|
+
# Install Generator
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
desc "Install the rails_paginate plugin"
|
8
|
+
def install
|
9
|
+
copy_file "config/initializers/paginate.rb", "config/initializers/paginate.rb"
|
10
|
+
copy_file "config/locales/en.yml", "config/locales/paginate.en.yml"
|
11
|
+
copy_file "config/locales/de.yml", "config/locales/paginate.de.yml"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# setup paginate
|
2
|
+
RailsPaginate.setup do |config|
|
3
|
+
# config.per_page = 20
|
4
|
+
# config.page_param = :page
|
5
|
+
|
6
|
+
# configure default renderer
|
7
|
+
# config.default_renderer = :html_default
|
8
|
+
|
9
|
+
# configure renderer
|
10
|
+
# config.renderer :html_default do |renderer|
|
11
|
+
# renderer.show_first_page = false
|
12
|
+
# renderer.show_last_page = false
|
13
|
+
# renderer.show_next_page = false
|
14
|
+
# renderer.show_previous_page = false
|
15
|
+
# end
|
16
|
+
|
17
|
+
# configure default default_pager
|
18
|
+
# config.default_pager = :slider
|
19
|
+
|
20
|
+
# configure pager
|
21
|
+
# config.pager :slider do |pager|
|
22
|
+
# pager.inner = 3
|
23
|
+
# pager.outer = 1
|
24
|
+
# end
|
25
|
+
end
|
data/lib/rails_paginate.rb
CHANGED
@@ -35,7 +35,11 @@ module RailsPaginate
|
|
35
35
|
raise ArgumentError, "renderer #{renderer} is not valid" unless (renderer.is_a? Symbol or renderer.is_a? String or renderer.is_a? Class)
|
36
36
|
renderer = renderer.to_s if renderer.is_a? Symbol
|
37
37
|
renderer = "rails_paginate/renderers/#{renderer}".camelize.constantize if renderer.is_a? String
|
38
|
-
|
38
|
+
if block_given?
|
39
|
+
yield renderer
|
40
|
+
else
|
41
|
+
renderer
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
# return pager
|
@@ -43,18 +47,20 @@ module RailsPaginate
|
|
43
47
|
raise ArgumentError, "pager #{pager} is not valid" unless (pager.is_a? Symbol or pager.is_a? String or pager.is_a? Class)
|
44
48
|
pager = pager.to_s if pager.is_a? Symbol
|
45
49
|
pager = "rails_paginate/pagers/#{pager}".camelize.constantize if pager.is_a? String
|
46
|
-
|
50
|
+
if block_given?
|
51
|
+
yield pager
|
52
|
+
else
|
53
|
+
pager
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
# init rails paginate
|
50
58
|
def init
|
59
|
+
require 'rails_paginate/rails' if defined?(::Rails::Engine)
|
51
60
|
::Array.send(:include, Helpers::Array)
|
52
61
|
::ActiveRecord::Base.send(:extend, Helpers::ActiveRecord) if defined?(::ActiveRecord::Base)
|
53
62
|
::ActiveRecord::Relation.send(:include, Helpers::ActiveRecord) if defined?(::ActiveRecord::Relation)
|
54
63
|
::ActionView::Base.send(:include, Helpers::ActionView) if defined?(::ActionView::Base)
|
55
|
-
|
56
|
-
# set default method
|
57
|
-
renderer :html_default
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
@@ -50,10 +50,12 @@ module RailsPaginate
|
|
50
50
|
self.replace result.nil? ? [] : result
|
51
51
|
end
|
52
52
|
|
53
|
+
# total count of array or relation
|
53
54
|
def total
|
54
55
|
@total ||= array_or_relation.count
|
55
56
|
end
|
56
57
|
|
58
|
+
# count of pages
|
57
59
|
def pages
|
58
60
|
@pages ||= total == 0 ? 1 : (total / per_page.to_f).ceil
|
59
61
|
end
|
@@ -68,12 +70,12 @@ module RailsPaginate
|
|
68
70
|
total > per_page
|
69
71
|
end
|
70
72
|
|
71
|
-
#
|
73
|
+
# first page
|
72
74
|
def first_page
|
73
75
|
1
|
74
76
|
end
|
75
77
|
|
76
|
-
#
|
78
|
+
# last page
|
77
79
|
def last_page
|
78
80
|
pages
|
79
81
|
end
|
@@ -88,12 +90,12 @@ module RailsPaginate
|
|
88
90
|
current_page == first_page
|
89
91
|
end
|
90
92
|
|
91
|
-
#
|
93
|
+
# next page
|
92
94
|
def next_page
|
93
95
|
current_page < pages ? (current_page + 1) : nil
|
94
96
|
end
|
95
97
|
|
96
|
-
#
|
98
|
+
# previous page
|
97
99
|
def previous_page
|
98
100
|
current_page > 1 ? (current_page - 1) : nil
|
99
101
|
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module RailsPaginate::Helpers
|
2
|
+
# ActiveRecord extension for create paginate collection
|
2
3
|
module ActiveRecord
|
4
|
+
# paginate with options
|
5
|
+
#
|
6
|
+
# page = active page
|
7
|
+
# per_page = how much entries per page
|
3
8
|
def paginate(*args)
|
4
9
|
options = args.extract_options!
|
5
10
|
per_page = options.delete(:per_page)
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module RailsPaginate::Helpers
|
2
|
+
# Array extension for create paginate collection
|
2
3
|
module Array
|
4
|
+
# paginate with options
|
5
|
+
#
|
6
|
+
# page = active page
|
7
|
+
# per_page = how much entries per page
|
3
8
|
def paginate(*args)
|
4
9
|
options = args.extract_options!
|
5
10
|
per_page = options.delete(:per_page)
|
@@ -1,20 +1,26 @@
|
|
1
1
|
module RailsPaginate::Pagers
|
2
2
|
# base method
|
3
3
|
class Base
|
4
|
+
# default reader
|
4
5
|
attr_reader :collection, :options
|
6
|
+
|
7
|
+
# set default collection and options
|
5
8
|
def initialize(collection, options = {})
|
6
9
|
@collection = collection
|
7
10
|
@options = options
|
8
11
|
end
|
9
12
|
|
13
|
+
# current_page
|
10
14
|
def current_page
|
11
15
|
collection.current_page
|
12
16
|
end
|
13
17
|
|
18
|
+
# total count
|
14
19
|
def pages
|
15
20
|
collection.pages
|
16
21
|
end
|
17
22
|
|
23
|
+
# abstract
|
18
24
|
def visible_pages
|
19
25
|
raise StandardError, "render is not implemented"
|
20
26
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
module RailsPaginate::Pagers
|
2
2
|
# slider method
|
3
3
|
class Slider < Base
|
4
|
-
|
4
|
+
|
5
|
+
# how much pages should display around current_page
|
6
|
+
cattr_accessor :inner
|
5
7
|
@@inner = 3
|
8
|
+
|
9
|
+
# how much pages should display at start and end
|
10
|
+
cattr_accessor :outer
|
6
11
|
@@outer = 1
|
7
12
|
|
13
|
+
# build array with all visible pages
|
8
14
|
def visible_pages
|
9
15
|
visible = []
|
10
16
|
last_inserted = 0
|
@@ -26,6 +32,7 @@ module RailsPaginate::Pagers
|
|
26
32
|
visible
|
27
33
|
end
|
28
34
|
|
35
|
+
# build dummy inner range
|
29
36
|
def inner_range
|
30
37
|
@inner_range ||= (current_page - inner)..(current_page + inner)
|
31
38
|
end
|
@@ -47,10 +54,12 @@ module RailsPaginate::Pagers
|
|
47
54
|
false
|
48
55
|
end
|
49
56
|
|
57
|
+
# get option of inner
|
50
58
|
def inner
|
51
59
|
options[:inner] || self.class.inner
|
52
60
|
end
|
53
61
|
|
62
|
+
# get option of out
|
54
63
|
def outer
|
55
64
|
options[:outer] || self.class.outer
|
56
65
|
end
|
@@ -3,6 +3,7 @@ module RailsPaginate::Renderers
|
|
3
3
|
class Base
|
4
4
|
attr_reader :view, :collection, :options, :pager
|
5
5
|
|
6
|
+
# setup rails_paginate collection
|
6
7
|
def initialize(view, collection, pager, options = {})
|
7
8
|
raise ArgumentError, "first argument must be a RailsPaginate::Collection" unless collection.is_a? RailsPaginate::Collection
|
8
9
|
raise ArgumentError, "second argument must be a Hash" unless options.is_a? Hash
|
@@ -13,21 +14,19 @@ module RailsPaginate::Renderers
|
|
13
14
|
@pager = pager
|
14
15
|
end
|
15
16
|
|
17
|
+
# build url
|
16
18
|
def url_for_page(page)
|
17
|
-
|
18
|
-
begin
|
19
|
-
view.url_for(view.default_url_options.merge({:page => page}))
|
20
|
-
rescue
|
21
|
-
"?page=#{page}"
|
22
|
-
end
|
19
|
+
view.url_for(view.default_url_options.merge({page_param.to_sym => page}))
|
23
20
|
end
|
24
21
|
|
22
|
+
# abstrack renderer
|
25
23
|
def render
|
26
24
|
raise StandardError, "render is not implemented"
|
27
25
|
end
|
28
26
|
|
29
27
|
protected
|
30
28
|
|
29
|
+
# link to page with i18n support
|
31
30
|
def link_to_page(page, key, options = {})
|
32
31
|
css_class = "#{options[:class]} #{page == current_page ? 'current' : ''}"
|
33
32
|
if key.nil?
|
@@ -39,19 +38,27 @@ module RailsPaginate::Renderers
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
41
|
+
#
|
42
|
+
def page_param
|
43
|
+
options[:page_param] || RailsPaginate.page_param
|
44
|
+
end
|
45
|
+
|
42
46
|
# helper
|
43
47
|
def current_page
|
44
48
|
collection.current_page
|
45
49
|
end
|
46
50
|
|
51
|
+
# map to view helper
|
47
52
|
def content_tag(*args, &block)
|
48
53
|
view.content_tag(*args, &block)
|
49
54
|
end
|
50
55
|
|
56
|
+
# map to view helper
|
51
57
|
def link_to(*args, &block)
|
52
58
|
view.link_to(*args, &block)
|
53
59
|
end
|
54
60
|
|
61
|
+
# map to view helper
|
55
62
|
def t(*args)
|
56
63
|
view.t(*args)
|
57
64
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module RailsPaginate::Renderers
|
2
|
-
#
|
2
|
+
# default html renderer
|
3
3
|
class HtmlDefault < Base
|
4
|
+
|
4
5
|
# show first page item
|
5
6
|
cattr_accessor :show_first_page
|
6
7
|
@@show_first_page = true
|
@@ -17,6 +18,7 @@ module RailsPaginate::Renderers
|
|
17
18
|
cattr_accessor :show_previous_page
|
18
19
|
@@show_previous_page = true
|
19
20
|
|
21
|
+
# render html for pagination
|
20
22
|
def render
|
21
23
|
content_tag(:ul) do
|
22
24
|
html = "\n"
|
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.5"
|
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-19}
|
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 = [
|
@@ -27,6 +27,10 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"init.rb",
|
30
|
+
"lib/generators/rails_paginate/install_generator.rb",
|
31
|
+
"lib/generators/templates/config/initializers/paginate.rb",
|
32
|
+
"lib/generators/templates/config/locales/de.yml",
|
33
|
+
"lib/generators/templates/config/locales/en.yml",
|
30
34
|
"lib/rails_paginate.rb",
|
31
35
|
"lib/rails_paginate/collection.rb",
|
32
36
|
"lib/rails_paginate/helpers.rb",
|
@@ -36,6 +40,7 @@ Gem::Specification.new do |s|
|
|
36
40
|
"lib/rails_paginate/pagers.rb",
|
37
41
|
"lib/rails_paginate/pagers/base.rb",
|
38
42
|
"lib/rails_paginate/pagers/slider.rb",
|
43
|
+
"lib/rails_paginate/rails.rb",
|
39
44
|
"lib/rails_paginate/renderers.rb",
|
40
45
|
"lib/rails_paginate/renderers/base.rb",
|
41
46
|
"lib/rails_paginate/renderers/html_default.rb",
|
@@ -49,8 +54,7 @@ Gem::Specification.new do |s|
|
|
49
54
|
"spec/renderers/base_spec.rb",
|
50
55
|
"spec/renderers/html_default_spec.rb",
|
51
56
|
"spec/spec_helper.rb",
|
52
|
-
"spec/support/10_active_record.rb"
|
53
|
-
"spec/support/20_action_controller.rb"
|
57
|
+
"spec/support/10_active_record.rb"
|
54
58
|
]
|
55
59
|
s.homepage = %q{http://github.com/phatworx/rails_paginate}
|
56
60
|
s.licenses = ["MIT"]
|
@@ -67,8 +71,7 @@ Gem::Specification.new do |s|
|
|
67
71
|
"spec/renderers/base_spec.rb",
|
68
72
|
"spec/renderers/html_default_spec.rb",
|
69
73
|
"spec/spec_helper.rb",
|
70
|
-
"spec/support/10_active_record.rb"
|
71
|
-
"spec/support/20_action_controller.rb"
|
74
|
+
"spec/support/10_active_record.rb"
|
72
75
|
]
|
73
76
|
|
74
77
|
if s.respond_to? :specification_version then
|
@@ -81,6 +84,7 @@ Gem::Specification.new do |s|
|
|
81
84
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
82
85
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
83
86
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
87
|
+
s.add_development_dependency(%q<rspec-hpricot-matchers>, [">= 0"])
|
84
88
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
85
89
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
86
90
|
else
|
@@ -90,6 +94,7 @@ Gem::Specification.new do |s|
|
|
90
94
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
91
95
|
s.add_dependency(%q<rspec>, [">= 0"])
|
92
96
|
s.add_dependency(%q<yard>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rspec-hpricot-matchers>, [">= 0"])
|
93
98
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
94
99
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
95
100
|
end
|
@@ -100,6 +105,7 @@ Gem::Specification.new do |s|
|
|
100
105
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
101
106
|
s.add_dependency(%q<rspec>, [">= 0"])
|
102
107
|
s.add_dependency(%q<yard>, [">= 0"])
|
108
|
+
s.add_dependency(%q<rspec-hpricot-matchers>, [">= 0"])
|
103
109
|
s.add_dependency(%q<simplecov>, [">= 0"])
|
104
110
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
105
111
|
end
|
@@ -28,9 +28,9 @@ describe RailsPaginate::Helpers::ActionView do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context "#paginate with class => dummy" do
|
31
|
-
|
32
|
-
|
33
|
-
it { subject.should
|
31
|
+
subject { action_view.paginate collection, :class => "dummy" }
|
32
|
+
it("should have one div.pagination.dummy") { subject.should have_tag('div.pagination.dummy', :count => 1) }
|
33
|
+
it("should have one div with ul") { subject.should have_tag('div > ul', :count => 1) }
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -1,12 +1,45 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
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
4
|
|
8
|
-
|
9
|
-
|
5
|
+
|
6
|
+
context "empty collection" do
|
7
|
+
let(:collection) { [].paginate }
|
8
|
+
context "pager type slider" do
|
9
|
+
subject { RailsPaginate::Renderers::HtmlDefault.new action_view, collection, RailsPaginate.pager(:slider).new(collection) }
|
10
|
+
specify { should respond_to :render }
|
11
|
+
it "#render should not raise StandardError" do
|
12
|
+
lambda { subject.render }.should_not raise_error(StandardError)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "collection with 100 items" do
|
18
|
+
let(:collection) { (1..100).to_a.paginate }
|
19
|
+
context "pager type slider" do
|
20
|
+
before { @renderer = RailsPaginate::Renderers::HtmlDefault.new action_view, collection, RailsPaginate.pager(:slider).new(collection) }
|
21
|
+
subject { @renderer }
|
22
|
+
specify { should respond_to :render }
|
23
|
+
it "#render should not raise StandardError" do
|
24
|
+
lambda { subject.render }.should_not raise_error(StandardError)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "result of #render" do
|
28
|
+
subject { @renderer.render }
|
29
|
+
specify { should be_an String }
|
30
|
+
|
31
|
+
it("should not have the div at first") { subject.should_not have_tag('> div', :count => 1) }
|
32
|
+
it("should have one ul") { subject.should have_tag('ul') }
|
33
|
+
it("should have one li") { subject.should have_tag('ul > li', :count => 9) }
|
34
|
+
[:first_page, :previous_page, :first_pager, :last_pager, :next_page, :last_page].each do |class_attr|
|
35
|
+
it("should have one li.#{class_attr}") { subject.should have_tag("ul > li.#{class_attr}", :count => 1) }
|
36
|
+
end
|
37
|
+
it("should have 5 li.pager") { subject.should have_tag('ul > li.pager', :count => 5) }
|
38
|
+
it("should have 8 ul > li > a") { subject.should have_tag('ul > li > a', :count => 8) }
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
10
43
|
end
|
11
44
|
|
12
45
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,7 @@ require 'active_support/test_case'
|
|
13
13
|
require 'action_controller'
|
14
14
|
require 'action_controller/test_case'
|
15
15
|
require 'action_dispatch'
|
16
|
+
require 'rspec-hpricot-matchers'
|
16
17
|
require 'rails_paginate'
|
17
18
|
|
18
19
|
# Requires supporting files with custom matchers and macros, etc,
|
@@ -20,30 +21,20 @@ require 'rails_paginate'
|
|
20
21
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
21
22
|
|
22
23
|
RSpec.configure do |config|
|
24
|
+
config.include(HpricotSpec::Matchers)
|
25
|
+
|
23
26
|
def action_view
|
24
27
|
x = ActionView::Base.new
|
25
28
|
x.controller = action_controller
|
26
|
-
x.
|
29
|
+
x.stub!(:url_for).and_return do |*args|
|
30
|
+
options = args.extract_options!
|
31
|
+
"?page=#{options[:page]}"
|
32
|
+
end
|
27
33
|
x
|
28
34
|
end
|
29
35
|
|
30
36
|
def action_controller
|
31
|
-
|
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
|
37
|
+
ActionController::Base.new
|
47
38
|
end
|
48
39
|
|
49
40
|
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.5
|
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-19 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: *id006
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: rspec-hpricot-matchers
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: *id007
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: simplecov
|
95
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
@@ -101,6 +101,17 @@ dependencies:
|
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
103
|
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: sqlite3
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id009
|
104
115
|
description: a new rails 3 paginate plugin as will_paginate replacement
|
105
116
|
email: develop@marco-scholl.de
|
106
117
|
executables: []
|
@@ -121,6 +132,10 @@ files:
|
|
121
132
|
- Rakefile
|
122
133
|
- VERSION
|
123
134
|
- init.rb
|
135
|
+
- lib/generators/rails_paginate/install_generator.rb
|
136
|
+
- lib/generators/templates/config/initializers/paginate.rb
|
137
|
+
- lib/generators/templates/config/locales/de.yml
|
138
|
+
- lib/generators/templates/config/locales/en.yml
|
124
139
|
- lib/rails_paginate.rb
|
125
140
|
- lib/rails_paginate/collection.rb
|
126
141
|
- lib/rails_paginate/helpers.rb
|
@@ -130,6 +145,7 @@ files:
|
|
130
145
|
- lib/rails_paginate/pagers.rb
|
131
146
|
- lib/rails_paginate/pagers/base.rb
|
132
147
|
- lib/rails_paginate/pagers/slider.rb
|
148
|
+
- lib/rails_paginate/rails.rb
|
133
149
|
- lib/rails_paginate/renderers.rb
|
134
150
|
- lib/rails_paginate/renderers/base.rb
|
135
151
|
- lib/rails_paginate/renderers/html_default.rb
|
@@ -144,7 +160,6 @@ files:
|
|
144
160
|
- spec/renderers/html_default_spec.rb
|
145
161
|
- spec/spec_helper.rb
|
146
162
|
- spec/support/10_active_record.rb
|
147
|
-
- spec/support/20_action_controller.rb
|
148
163
|
has_rdoc: true
|
149
164
|
homepage: http://github.com/phatworx/rails_paginate
|
150
165
|
licenses:
|
@@ -159,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
174
|
requirements:
|
160
175
|
- - ">="
|
161
176
|
- !ruby/object:Gem::Version
|
162
|
-
hash: -
|
177
|
+
hash: -152789811183962972
|
163
178
|
segments:
|
164
179
|
- 0
|
165
180
|
version: "0"
|
@@ -187,4 +202,3 @@ test_files:
|
|
187
202
|
- spec/renderers/html_default_spec.rb
|
188
203
|
- spec/spec_helper.rb
|
189
204
|
- spec/support/10_active_record.rb
|
190
|
-
- spec/support/20_action_controller.rb
|