will_paginate 3.0.4 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +7 -10
- data/lib/will_paginate/active_record.rb +18 -17
- data/lib/will_paginate/deprecation.rb +3 -3
- data/lib/will_paginate/i18n.rb +3 -3
- data/lib/will_paginate/locale/en.yml +4 -0
- data/lib/will_paginate/mongoid.rb +48 -0
- data/lib/will_paginate/page_number.rb +7 -11
- data/lib/will_paginate/railtie.rb +19 -13
- data/lib/will_paginate/version.rb +2 -2
- data/lib/will_paginate/view_helpers/action_view.rb +12 -5
- data/lib/will_paginate/view_helpers/hanami.rb +41 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +23 -17
- data/lib/will_paginate/view_helpers/link_renderer_base.rb +1 -1
- data/lib/will_paginate/view_helpers.rb +3 -1
- data/lib/will_paginate.rb +0 -12
- metadata +29 -58
- data/Rakefile +0 -25
- data/lib/will_paginate/data_mapper.rb +0 -95
- data/lib/will_paginate/view_helpers/merb.rb +0 -26
- data/spec/ci.rb +0 -29
- data/spec/collection_spec.rb +0 -139
- data/spec/console +0 -12
- data/spec/console_fixtures.rb +0 -28
- data/spec/database.yml +0 -22
- data/spec/finders/active_record_spec.rb +0 -556
- data/spec/finders/activerecord_test_connector.rb +0 -115
- data/spec/finders/data_mapper_spec.rb +0 -103
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/sequel_spec.rb +0 -67
- data/spec/finders/sequel_test_connector.rb +0 -15
- data/spec/fixtures/admin.rb +0 -3
- data/spec/fixtures/developer.rb +0 -13
- data/spec/fixtures/developers_projects.yml +0 -13
- data/spec/fixtures/project.rb +0 -15
- data/spec/fixtures/projects.yml +0 -6
- data/spec/fixtures/replies.yml +0 -29
- data/spec/fixtures/reply.rb +0 -9
- data/spec/fixtures/schema.rb +0 -38
- data/spec/fixtures/topic.rb +0 -7
- data/spec/fixtures/topics.yml +0 -30
- data/spec/fixtures/user.rb +0 -2
- data/spec/fixtures/users.yml +0 -35
- data/spec/page_number_spec.rb +0 -65
- data/spec/per_page_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -71
- data/spec/view_helpers/action_view_spec.rb +0 -423
- data/spec/view_helpers/base_spec.rb +0 -130
- data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
- data/spec/view_helpers/view_example_group.rb +0 -121
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95d6a838948c59686c5768a47e8e7e52b99c55868775645285022bc0d7c0e280
|
4
|
+
data.tar.gz: c92449392a8191a656e19d5e722314a2f2c1c50d646f5d98359b0d8193539dd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4511c22cbbf023ab6e32fc457c487ec393c2fdf6f8a3910ee0c0d8385061a98307b6a8a8f02a25af33f9f648f735c5d20d942412b3a7ff5a40d2d7ba67491917
|
7
|
+
data.tar.gz: a062b0bce8e25a24b818b926957b98f970e86b79f89fbb1e2cdfbce382a030d02b3f02800cce6dd1671d84d3251e33879095a1bbe669a7348df90a3664be95ec
|
data/README.md
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
# will_paginate
|
2
2
|
|
3
|
-
will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra,
|
4
|
-
|
5
|
-
Installation:
|
3
|
+
will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, and Sequel.
|
6
4
|
|
7
5
|
``` ruby
|
8
|
-
|
9
|
-
gem 'will_paginate', '~> 3.0'
|
6
|
+
gem 'will_paginate', '~> 3.3'
|
10
7
|
```
|
11
8
|
|
12
9
|
See [installation instructions][install] on the wiki for more info.
|
13
10
|
|
11
|
+
ℹ️ will_paginate is now in _maintenance mode_ and it will not be receiving new features. [See alternatives](https://www.ruby-toolbox.com/categories/pagination)
|
14
12
|
|
15
13
|
## Basic will_paginate use
|
16
14
|
|
17
15
|
``` ruby
|
18
16
|
## perform a paginated query:
|
19
|
-
@posts = Post.paginate(:
|
17
|
+
@posts = Post.paginate(page: params[:page])
|
20
18
|
|
21
19
|
# or, use an explicit "per page" limit:
|
22
|
-
Post.paginate(:
|
20
|
+
Post.paginate(page: params[:page], per_page: 30)
|
23
21
|
|
24
22
|
## render page links in the view:
|
25
23
|
<%= will_paginate @posts %>
|
@@ -49,13 +47,12 @@ Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')
|
|
49
47
|
Post.page(params[:page]).order('created_at DESC')
|
50
48
|
```
|
51
49
|
|
52
|
-
See [the wiki][wiki] for more documentation. [
|
50
|
+
See [the wiki][wiki] for more documentation. [Report bugs][issues] on GitHub.
|
53
51
|
|
54
52
|
Happy paginating.
|
55
53
|
|
56
54
|
|
57
55
|
[wiki]: https://github.com/mislav/will_paginate/wiki
|
58
56
|
[install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"
|
59
|
-
[group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"
|
60
57
|
[issues]: https://github.com/mislav/will_paginate/issues
|
61
|
-
[css]: http://mislav.
|
58
|
+
[css]: http://mislav.github.io/will_paginate/
|
@@ -21,7 +21,7 @@ module WillPaginate
|
|
21
21
|
include WillPaginate::CollectionMethods
|
22
22
|
|
23
23
|
attr_accessor :current_page
|
24
|
-
attr_writer :total_entries
|
24
|
+
attr_writer :total_entries
|
25
25
|
|
26
26
|
def per_page(value = nil)
|
27
27
|
if value.nil? then limit_value
|
@@ -51,8 +51,8 @@ module WillPaginate
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# fix for Rails 3.0
|
54
|
-
def find_last
|
55
|
-
if !loaded?
|
54
|
+
def find_last(*args)
|
55
|
+
if !loaded? && args.empty? && (offset_value || limit_value)
|
56
56
|
@last ||= to_a.last
|
57
57
|
else
|
58
58
|
super
|
@@ -78,16 +78,18 @@ module WillPaginate
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
def count
|
81
|
+
def count(*args)
|
82
82
|
if limit_value
|
83
|
-
excluded = [:order, :limit, :offset]
|
83
|
+
excluded = [:order, :limit, :offset, :reorder]
|
84
84
|
excluded << :includes unless eager_loading?
|
85
85
|
rel = self.except(*excluded)
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
column_name = if rel.select_values.present?
|
87
|
+
select = rel.select_values.join(", ")
|
88
|
+
select if select !~ /[,*]/
|
89
|
+
end || :all
|
90
|
+
rel.count(column_name)
|
89
91
|
else
|
90
|
-
super
|
92
|
+
super(*args)
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
@@ -103,9 +105,7 @@ module WillPaginate
|
|
103
105
|
# overloaded to be pagination-aware
|
104
106
|
def empty?
|
105
107
|
if !loaded? and offset_value
|
106
|
-
|
107
|
-
result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
|
108
|
-
result <= offset_value
|
108
|
+
total_entries <= offset_value
|
109
109
|
else
|
110
110
|
super
|
111
111
|
end
|
@@ -135,7 +135,6 @@ module WillPaginate
|
|
135
135
|
def copy_will_paginate_data(other)
|
136
136
|
other.current_page = current_page unless other.current_page
|
137
137
|
other.total_entries = nil if defined? @total_entries_queried
|
138
|
-
other.wp_count_options = @wp_count_options if defined? @wp_count_options
|
139
138
|
other
|
140
139
|
end
|
141
140
|
end
|
@@ -144,15 +143,15 @@ module WillPaginate
|
|
144
143
|
def paginate(options)
|
145
144
|
options = options.dup
|
146
145
|
pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
|
146
|
+
options.delete(:page)
|
147
147
|
per_page = options.delete(:per_page) || self.per_page
|
148
148
|
total = options.delete(:total_entries)
|
149
149
|
|
150
|
-
|
151
|
-
|
150
|
+
if options.any?
|
151
|
+
raise ArgumentError, "unsupported parameters: %p" % options.keys
|
152
|
+
end
|
152
153
|
|
153
154
|
rel = limit(per_page.to_i).page(pagenum)
|
154
|
-
rel = rel.apply_finder_options(options) if options.any?
|
155
|
-
rel.wp_count_options = count_options if count_options
|
156
155
|
rel.total_entries = total.to_i unless total.blank?
|
157
156
|
rel
|
158
157
|
end
|
@@ -211,6 +210,8 @@ module WillPaginate
|
|
211
210
|
WHERE rownum <= #{pager.offset + pager.per_page}
|
212
211
|
) WHERE rnum >= #{pager.offset}
|
213
212
|
SQL
|
213
|
+
elsif (self.connection.adapter_name =~ /^sqlserver/i)
|
214
|
+
query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
|
214
215
|
else
|
215
216
|
query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
|
216
217
|
end
|
@@ -10,7 +10,7 @@ module WillPaginate::Deprecation
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def rails_logger
|
13
|
-
defined?(Rails) && Rails.logger
|
13
|
+
defined?(Rails.logger) && Rails.logger
|
14
14
|
end
|
15
15
|
|
16
16
|
def origin_of_call(stack)
|
@@ -31,8 +31,8 @@ module WillPaginate::Deprecation
|
|
31
31
|
super
|
32
32
|
end
|
33
33
|
|
34
|
-
def deprecate_key(*keys)
|
35
|
-
message = block_given? ?
|
34
|
+
def deprecate_key(*keys, &block)
|
35
|
+
message = block_given? ? block : keys.pop
|
36
36
|
Array(keys).each { |key| @deprecated[key] = message }
|
37
37
|
end
|
38
38
|
|
data/lib/will_paginate/i18n.rb
CHANGED
@@ -8,11 +8,11 @@ module WillPaginate
|
|
8
8
|
Dir["#{locale_dir}/*.{rb,yml}"]
|
9
9
|
end
|
10
10
|
|
11
|
-
def will_paginate_translate(keys, options = {})
|
11
|
+
def will_paginate_translate(keys, options = {}, &block)
|
12
12
|
if defined? ::I18n
|
13
13
|
defaults = Array(keys).dup
|
14
|
-
defaults <<
|
15
|
-
::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
|
14
|
+
defaults << block if block_given?
|
15
|
+
::I18n.translate(defaults.shift, **options.merge(:default => defaults, :scope => :will_paginate))
|
16
16
|
else
|
17
17
|
key = Array === keys ? keys.first : keys
|
18
18
|
yield key, options
|
@@ -1,8 +1,12 @@
|
|
1
1
|
en:
|
2
2
|
will_paginate:
|
3
3
|
previous_label: "← Previous"
|
4
|
+
previous_aria_label: "Previous page"
|
4
5
|
next_label: "Next →"
|
6
|
+
next_aria_label: "Next page"
|
5
7
|
page_gap: "…"
|
8
|
+
container_aria_label: "Pagination"
|
9
|
+
page_aria_label: "Page %{page}"
|
6
10
|
|
7
11
|
page_entries_info:
|
8
12
|
single_page:
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
require 'will_paginate/collection'
|
3
|
+
|
4
|
+
module WillPaginate
|
5
|
+
module Mongoid
|
6
|
+
module CriteriaMethods
|
7
|
+
def paginate(options = {})
|
8
|
+
extend CollectionMethods
|
9
|
+
@current_page = WillPaginate::PageNumber(options[:page] || @current_page || 1)
|
10
|
+
@page_multiplier = current_page - 1
|
11
|
+
@total_entries = options.delete(:total_entries)
|
12
|
+
|
13
|
+
pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i
|
14
|
+
limit(pp).skip(@page_multiplier * pp)
|
15
|
+
end
|
16
|
+
|
17
|
+
def per_page(value = :non_given)
|
18
|
+
if value == :non_given
|
19
|
+
options[:limit] == 0 ? nil : options[:limit] # in new Mongoid versions a nil limit is saved as 0
|
20
|
+
else
|
21
|
+
limit(value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def page(page)
|
26
|
+
paginate(:page => page)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module CollectionMethods
|
31
|
+
attr_reader :current_page
|
32
|
+
|
33
|
+
def total_entries
|
34
|
+
@total_entries ||= count
|
35
|
+
end
|
36
|
+
|
37
|
+
def total_pages
|
38
|
+
(total_entries / per_page.to_f).ceil
|
39
|
+
end
|
40
|
+
|
41
|
+
def offset
|
42
|
+
@page_multiplier * per_page
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
::Mongoid::Criteria.send(:include, CriteriaMethods)
|
47
|
+
end
|
48
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'delegate'
|
2
1
|
require 'forwardable'
|
3
2
|
|
4
3
|
module WillPaginate
|
@@ -6,7 +5,7 @@ module WillPaginate
|
|
6
5
|
module InvalidPage; end
|
7
6
|
|
8
7
|
# integer representing a page number
|
9
|
-
class PageNumber <
|
8
|
+
class PageNumber < Numeric
|
10
9
|
# a value larger than this is not supported in SQL queries
|
11
10
|
BIGINT = 9223372036854775807
|
12
11
|
|
@@ -18,13 +17,17 @@ module WillPaginate
|
|
18
17
|
raise RangeError, "invalid #{name}: #{value.inspect}"
|
19
18
|
end
|
20
19
|
@name = name
|
21
|
-
|
20
|
+
@value = value
|
22
21
|
rescue ArgumentError, TypeError, RangeError => error
|
23
22
|
error.extend InvalidPage
|
24
23
|
raise error
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
def to_i
|
27
|
+
@value
|
28
|
+
end
|
29
|
+
|
30
|
+
def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/, :to_json
|
28
31
|
|
29
32
|
def inspect
|
30
33
|
"#{@name} #{to_i}"
|
@@ -40,13 +43,6 @@ module WillPaginate
|
|
40
43
|
alias is_a? kind_of?
|
41
44
|
end
|
42
45
|
|
43
|
-
# Ultrahax: makes `Fixnum === current_page` checks pass
|
44
|
-
Numeric.extend Module.new {
|
45
|
-
def ===(obj)
|
46
|
-
obj.instance_of? PageNumber or super
|
47
|
-
end
|
48
|
-
}
|
49
|
-
|
50
46
|
# An idemptotent coercion method
|
51
47
|
def self.PageNumber(value, name = 'page')
|
52
48
|
case value
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'will_paginate'
|
2
1
|
require 'will_paginate/page_number'
|
3
2
|
require 'will_paginate/collection'
|
4
3
|
require 'will_paginate/i18n'
|
@@ -18,8 +17,6 @@ module WillPaginate
|
|
18
17
|
require 'will_paginate/view_helpers/action_view'
|
19
18
|
end
|
20
19
|
|
21
|
-
self.class.add_locale_path config
|
22
|
-
|
23
20
|
# early access to ViewHelpers.pagination_options
|
24
21
|
require 'will_paginate/view_helpers'
|
25
22
|
end
|
@@ -31,19 +28,24 @@ module WillPaginate
|
|
31
28
|
ActionController::Base.extend ControllerRescuePatch
|
32
29
|
end
|
33
30
|
|
34
|
-
def self.add_locale_path(config)
|
35
|
-
config.i18n.railties_load_path.unshift(*WillPaginate::I18n.load_path)
|
36
|
-
end
|
37
|
-
|
38
31
|
# Extending the exception handler middleware so it properly detects
|
39
32
|
# WillPaginate::InvalidPage regardless of it being a tag module.
|
40
33
|
module ShowExceptionsPatch
|
41
34
|
extend ActiveSupport::Concern
|
42
|
-
included
|
35
|
+
included do
|
36
|
+
alias_method :status_code_without_paginate, :status_code
|
37
|
+
alias_method :status_code, :status_code_with_paginate
|
38
|
+
end
|
43
39
|
def status_code_with_paginate(exception = @exception)
|
44
|
-
if exception.
|
45
|
-
|
46
|
-
|
40
|
+
actual_exception = if exception.respond_to?(:cause)
|
41
|
+
exception.cause || exception
|
42
|
+
elsif exception.respond_to?(:original_exception)
|
43
|
+
exception.original_exception
|
44
|
+
else
|
45
|
+
exception
|
46
|
+
end
|
47
|
+
|
48
|
+
if actual_exception.is_a?(WillPaginate::InvalidPage)
|
47
49
|
Rack::Utils.status_code(:not_found)
|
48
50
|
else
|
49
51
|
original_method = method(:status_code_without_paginate)
|
@@ -57,12 +59,16 @@ module WillPaginate
|
|
57
59
|
end
|
58
60
|
|
59
61
|
module ControllerRescuePatch
|
60
|
-
def rescue_from(*args, &block)
|
62
|
+
def rescue_from(*args, **kwargs, &block)
|
61
63
|
if idx = args.index(WillPaginate::InvalidPage)
|
62
64
|
args[idx] = args[idx].name
|
63
65
|
end
|
64
|
-
super(*args, &block)
|
66
|
+
super(*args, **kwargs, &block)
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
71
|
+
|
72
|
+
ActiveSupport.on_load :i18n do
|
73
|
+
I18n.load_path.concat(WillPaginate::I18n.load_path)
|
74
|
+
end
|
@@ -30,7 +30,7 @@ module WillPaginate
|
|
30
30
|
options = options.symbolize_keys
|
31
31
|
options[:renderer] ||= LinkRenderer
|
32
32
|
|
33
|
-
super(collection, options)
|
33
|
+
super(collection, options)
|
34
34
|
end
|
35
35
|
|
36
36
|
def page_entries_info(collection = nil, options = {}) #:nodoc:
|
@@ -43,7 +43,7 @@ module WillPaginate
|
|
43
43
|
# Wrapper for rendering pagination links at both top and bottom of a block
|
44
44
|
# of content.
|
45
45
|
#
|
46
|
-
#
|
46
|
+
# <%= paginated_section @posts do %>
|
47
47
|
# <ol id="posts">
|
48
48
|
# <% for post in @posts %>
|
49
49
|
# <li> ... </li>
|
@@ -80,7 +80,7 @@ module WillPaginate
|
|
80
80
|
defaults = nil
|
81
81
|
key = keys
|
82
82
|
end
|
83
|
-
translate(key, options.merge(:default => defaults, :scope => :will_paginate))
|
83
|
+
translate(key, **options.merge(:default => defaults, :scope => :will_paginate))
|
84
84
|
else
|
85
85
|
super
|
86
86
|
end
|
@@ -99,6 +99,8 @@ module WillPaginate
|
|
99
99
|
class LinkRenderer < ViewHelpers::LinkRenderer
|
100
100
|
protected
|
101
101
|
|
102
|
+
GET_PARAMS_BLACKLIST = [:script_name, :original_script_name]
|
103
|
+
|
102
104
|
def default_url_params
|
103
105
|
{}
|
104
106
|
end
|
@@ -106,6 +108,7 @@ module WillPaginate
|
|
106
108
|
def url(page)
|
107
109
|
@base_url_params ||= begin
|
108
110
|
url_params = merge_get_params(default_url_params)
|
111
|
+
url_params[:only_path] = true
|
109
112
|
merge_optional_params(url_params)
|
110
113
|
end
|
111
114
|
|
@@ -116,8 +119,12 @@ module WillPaginate
|
|
116
119
|
end
|
117
120
|
|
118
121
|
def merge_get_params(url_params)
|
119
|
-
if @template.respond_to?
|
120
|
-
|
122
|
+
if @template.respond_to?(:request) and @template.request
|
123
|
+
if @template.request.get?
|
124
|
+
symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
|
125
|
+
elsif @template.request.respond_to?(:query_parameters)
|
126
|
+
symbolized_update(url_params, @template.request.query_parameters, GET_PARAMS_BLACKLIST)
|
127
|
+
end
|
121
128
|
end
|
122
129
|
url_params
|
123
130
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'hanami/view'
|
2
|
+
require 'will_paginate/view_helpers'
|
3
|
+
require 'will_paginate/view_helpers/link_renderer'
|
4
|
+
|
5
|
+
module WillPaginate
|
6
|
+
module Hanami
|
7
|
+
module Helpers
|
8
|
+
include ViewHelpers
|
9
|
+
|
10
|
+
def will_paginate(collection, options = {}) #:nodoc:
|
11
|
+
options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
|
12
|
+
str = super(collection, options)
|
13
|
+
str && raw(str)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class LinkRenderer < ViewHelpers::LinkRenderer
|
18
|
+
protected
|
19
|
+
|
20
|
+
def url(page)
|
21
|
+
str = File.join(request_env['SCRIPT_NAME'].to_s, request_env['PATH_INFO'])
|
22
|
+
params = request_env['rack.request.query_hash'].merge(param_name.to_s => page.to_s)
|
23
|
+
params.update @options[:params] if @options[:params]
|
24
|
+
str << '?' << build_query(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_env
|
28
|
+
@template.params.env
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_query(params)
|
32
|
+
Rack::Utils.build_nested_query params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.included(base)
|
37
|
+
base.include Helpers
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -24,7 +24,7 @@ module WillPaginate
|
|
24
24
|
# method as you see fit.
|
25
25
|
def to_html
|
26
26
|
html = pagination.map do |item|
|
27
|
-
item.is_a?(
|
27
|
+
item.is_a?(Integer) ?
|
28
28
|
page_number(item) :
|
29
29
|
send(item)
|
30
30
|
end.join(@options[:link_separator])
|
@@ -35,16 +35,20 @@ module WillPaginate
|
|
35
35
|
# Returns the subset of +options+ this instance was initialized with that
|
36
36
|
# represent HTML attributes for the container element of pagination links.
|
37
37
|
def container_attributes
|
38
|
-
@container_attributes ||=
|
38
|
+
@container_attributes ||= {
|
39
|
+
:role => 'navigation',
|
40
|
+
:"aria-label" => @template.will_paginate_translate(:container_aria_label) { 'Pagination' }
|
41
|
+
}.update @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
|
39
42
|
end
|
40
43
|
|
41
44
|
protected
|
42
45
|
|
43
46
|
def page_number(page)
|
44
|
-
|
45
|
-
|
47
|
+
aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" }
|
48
|
+
if page == current_page
|
49
|
+
tag(:em, page, :class => 'current', :"aria-label" => aria_label, :"aria-current" => 'page')
|
46
50
|
else
|
47
|
-
|
51
|
+
link(page, page, :rel => rel_value(page), :"aria-label" => aria_label)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
@@ -55,19 +59,21 @@ module WillPaginate
|
|
55
59
|
|
56
60
|
def previous_page
|
57
61
|
num = @collection.current_page > 1 && @collection.current_page - 1
|
58
|
-
|
62
|
+
aria_label = @template.will_paginate_translate(:previous_aria_label) { "Previous page" }
|
63
|
+
previous_or_next_page(num, @options[:previous_label], 'previous_page', aria_label)
|
59
64
|
end
|
60
65
|
|
61
66
|
def next_page
|
62
67
|
num = @collection.current_page < total_pages && @collection.current_page + 1
|
63
|
-
|
68
|
+
aria_label = @template.will_paginate_translate(:next_aria_label) { "Next page" }
|
69
|
+
previous_or_next_page(num, @options[:next_label], 'next_page', aria_label)
|
64
70
|
end
|
65
71
|
|
66
|
-
def previous_or_next_page(page, text, classname)
|
72
|
+
def previous_or_next_page(page, text, classname, aria_label = nil)
|
67
73
|
if page
|
68
|
-
link(text, page, :class => classname)
|
74
|
+
link(text, page, :class => classname, :'aria-label' => aria_label)
|
69
75
|
else
|
70
|
-
tag(:span, text, :class => classname + ' disabled')
|
76
|
+
tag(:span, text, :class => classname + ' disabled', :'aria-label' => aria_label)
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -88,7 +94,7 @@ module WillPaginate
|
|
88
94
|
end
|
89
95
|
|
90
96
|
def link(text, target, attributes = {})
|
91
|
-
if target.is_a?
|
97
|
+
if target.is_a?(Integer)
|
92
98
|
attributes[:rel] = rel_value(target)
|
93
99
|
target = url(target)
|
94
100
|
end
|
@@ -108,18 +114,18 @@ module WillPaginate
|
|
108
114
|
|
109
115
|
def rel_value(page)
|
110
116
|
case page
|
111
|
-
when @collection.current_page - 1; 'prev'
|
117
|
+
when @collection.current_page - 1; 'prev'
|
112
118
|
when @collection.current_page + 1; 'next'
|
113
|
-
when 1; 'start'
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
117
|
-
def symbolized_update(target, other)
|
118
|
-
other.
|
122
|
+
def symbolized_update(target, other, blacklist = nil)
|
123
|
+
other.each_pair do |key, value|
|
119
124
|
key = key.to_sym
|
120
125
|
existing = target[key]
|
121
|
-
|
122
|
-
|
126
|
+
next if blacklist && blacklist.include?(key)
|
127
|
+
|
128
|
+
if value.respond_to?(:each_pair) and (existing.is_a?(Hash) or existing.nil?)
|
123
129
|
symbolized_update(existing || (target[key] = {}), value)
|
124
130
|
else
|
125
131
|
target[key] = value
|
@@ -30,7 +30,7 @@ module WillPaginate
|
|
30
30
|
window_from = current_page - inner_window
|
31
31
|
window_to = current_page + inner_window
|
32
32
|
|
33
|
-
# adjust lower or upper limit if
|
33
|
+
# adjust lower or upper limit if either is out of bounds
|
34
34
|
if window_to > total_pages
|
35
35
|
window_from -= window_to - total_pages
|
36
36
|
window_to = total_pages
|
@@ -91,7 +91,9 @@ module WillPaginate
|
|
91
91
|
end
|
92
92
|
# render HTML for pagination
|
93
93
|
renderer.prepare collection, options, self
|
94
|
-
renderer.to_html
|
94
|
+
output = renderer.to_html
|
95
|
+
output = output.html_safe if output.respond_to?(:html_safe)
|
96
|
+
output
|
95
97
|
end
|
96
98
|
|
97
99
|
# Renders a message containing number of displayed vs. total entries.
|
data/lib/will_paginate.rb
CHANGED
@@ -8,18 +8,6 @@ elsif defined?(Rails::Initializer)
|
|
8
8
|
raise "will_paginate 3.0 is not compatible with Rails 2.3 or older"
|
9
9
|
end
|
10
10
|
|
11
|
-
if defined?(Merb::AbstractController)
|
12
|
-
require 'will_paginate/view_helpers/merb'
|
13
|
-
|
14
|
-
Merb::BootLoader.before_app_loads do
|
15
|
-
adapters = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }
|
16
|
-
# auto-load the right ORM adapter
|
17
|
-
if adapter = adapters[Merb.orm]
|
18
|
-
require "will_paginate/#{adapter}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
11
|
if defined?(Sinatra) and Sinatra.respond_to? :register
|
24
12
|
require 'will_paginate/view_helpers/sinatra'
|
25
13
|
end
|