will_paginate 3.1.8 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/lib/will_paginate/active_record.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 +2 -0
- data/lib/will_paginate/page_number.rb +7 -11
- data/lib/will_paginate/railtie.rb +3 -4
- data/lib/will_paginate/version.rb +3 -3
- data/lib/will_paginate/view_helpers/action_view.rb +8 -4
- data/lib/will_paginate/view_helpers/hanami.rb +41 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +14 -8
- data/lib/will_paginate.rb +0 -12
- metadata +17 -48
- data/lib/will_paginate/data_mapper.rb +0 -100
- data/lib/will_paginate/view_helpers/merb.rb +0 -26
- data/spec/collection_spec.rb +0 -139
- data/spec/console +0 -12
- data/spec/console_fixtures.rb +0 -28
- data/spec/database.yml +0 -29
- data/spec/fake_rubygems.rb +0 -18
- data/spec/finders/active_record_spec.rb +0 -417
- data/spec/finders/activerecord_test_connector.rb +0 -140
- data/spec/finders/data_mapper_spec.rb +0 -114
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/mongoid_spec.rb +0 -145
- data/spec/finders/sequel_spec.rb +0 -65
- data/spec/finders/sequel_test_connector.rb +0 -15
- data/spec/fixtures/admin.rb +0 -3
- data/spec/fixtures/developer.rb +0 -9
- data/spec/fixtures/developers_projects.yml +0 -13
- data/spec/fixtures/project.rb +0 -13
- data/spec/fixtures/projects.yml +0 -6
- data/spec/fixtures/replies.yml +0 -29
- data/spec/fixtures/reply.rb +0 -8
- data/spec/fixtures/schema.rb +0 -38
- data/spec/fixtures/topic.rb +0 -8
- data/spec/fixtures/topics.yml +0 -30
- data/spec/fixtures/user.rb +0 -2
- data/spec/fixtures/users.yml +0 -35
- data/spec/matchers/deprecation_matcher.rb +0 -27
- data/spec/matchers/phrase_matcher.rb +0 -19
- data/spec/matchers/query_count_matcher.rb +0 -36
- data/spec/page_number_spec.rb +0 -83
- data/spec/per_page_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -46
- data/spec/view_helpers/action_view_spec.rb +0 -468
- data/spec/view_helpers/base_spec.rb +0 -143
- data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
- data/spec/view_helpers/view_example_group.rb +0 -146
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d6a838948c59686c5768a47e8e7e52b99c55868775645285022bc0d7c0e280
|
4
|
+
data.tar.gz: c92449392a8191a656e19d5e722314a2f2c1c50d646f5d98359b0d8193539dd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4511c22cbbf023ab6e32fc457c487ec393c2fdf6f8a3910ee0c0d8385061a98307b6a8a8f02a25af33f9f648f735c5d20d942412b3a7ff5a40d2d7ba67491917
|
7
|
+
data.tar.gz: a062b0bce8e25a24b818b926957b98f970e86b79f89fbb1e2cdfbce382a030d02b3f02800cce6dd1671d84d3251e33879095a1bbe669a7348df90a3664be95ec
|
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
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.1.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
|
|
@@ -105,9 +105,7 @@ module WillPaginate
|
|
105
105
|
# overloaded to be pagination-aware
|
106
106
|
def empty?
|
107
107
|
if !loaded? and offset_value
|
108
|
-
|
109
|
-
result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
|
110
|
-
result <= offset_value
|
108
|
+
total_entries <= offset_value
|
111
109
|
else
|
112
110
|
super
|
113
111
|
end
|
@@ -212,6 +210,8 @@ module WillPaginate
|
|
212
210
|
WHERE rownum <= #{pager.offset + pager.per_page}
|
213
211
|
) WHERE rnum >= #{pager.offset}
|
214
212
|
SQL
|
213
|
+
elsif (self.connection.adapter_name =~ /^sqlserver/i)
|
214
|
+
query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
|
215
215
|
else
|
216
216
|
query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
|
217
217
|
end
|
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:
|
@@ -8,6 +8,8 @@ module WillPaginate
|
|
8
8
|
extend CollectionMethods
|
9
9
|
@current_page = WillPaginate::PageNumber(options[:page] || @current_page || 1)
|
10
10
|
@page_multiplier = current_page - 1
|
11
|
+
@total_entries = options.delete(:total_entries)
|
12
|
+
|
11
13
|
pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i
|
12
14
|
limit(pp).skip(@page_multiplier * pp)
|
13
15
|
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 `Integer === 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'
|
@@ -39,7 +38,7 @@ module WillPaginate
|
|
39
38
|
end
|
40
39
|
def status_code_with_paginate(exception = @exception)
|
41
40
|
actual_exception = if exception.respond_to?(:cause)
|
42
|
-
exception.cause
|
41
|
+
exception.cause || exception
|
43
42
|
elsif exception.respond_to?(:original_exception)
|
44
43
|
exception.original_exception
|
45
44
|
else
|
@@ -60,11 +59,11 @@ module WillPaginate
|
|
60
59
|
end
|
61
60
|
|
62
61
|
module ControllerRescuePatch
|
63
|
-
def rescue_from(*args, &block)
|
62
|
+
def rescue_from(*args, **kwargs, &block)
|
64
63
|
if idx = args.index(WillPaginate::InvalidPage)
|
65
64
|
args[idx] = args[idx].name
|
66
65
|
end
|
67
|
-
super(*args, &block)
|
66
|
+
super(*args, **kwargs, &block)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -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
|
@@ -119,8 +119,12 @@ module WillPaginate
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def merge_get_params(url_params)
|
122
|
-
if @template.respond_to?
|
123
|
-
|
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
|
124
128
|
end
|
125
129
|
url_params
|
126
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
|
@@ -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)
|
47
|
+
aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" }
|
44
48
|
if page == current_page
|
45
|
-
tag(:em, page, :class => 'current')
|
49
|
+
tag(:em, page, :class => 'current', :"aria-label" => aria_label, :"aria-current" => 'page')
|
46
50
|
else
|
47
|
-
link(page, page, :rel => rel_value(page))
|
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
|
|
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
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mislav Marohnić
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: will_paginate provides a simple API for performing paginated queries
|
14
|
-
with Active Record
|
15
|
-
|
14
|
+
with Active Record and Sequel, and includes helpers for rendering pagination links
|
15
|
+
in Rails, Sinatra, and Hanami web apps.
|
16
16
|
email: mislav.marohnic@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
@@ -27,7 +27,6 @@ files:
|
|
27
27
|
- lib/will_paginate/array.rb
|
28
28
|
- lib/will_paginate/collection.rb
|
29
29
|
- lib/will_paginate/core_ext.rb
|
30
|
-
- lib/will_paginate/data_mapper.rb
|
31
30
|
- lib/will_paginate/deprecation.rb
|
32
31
|
- lib/will_paginate/i18n.rb
|
33
32
|
- lib/will_paginate/locale/en.yml
|
@@ -39,49 +38,20 @@ files:
|
|
39
38
|
- lib/will_paginate/version.rb
|
40
39
|
- lib/will_paginate/view_helpers.rb
|
41
40
|
- lib/will_paginate/view_helpers/action_view.rb
|
41
|
+
- lib/will_paginate/view_helpers/hanami.rb
|
42
42
|
- lib/will_paginate/view_helpers/link_renderer.rb
|
43
43
|
- lib/will_paginate/view_helpers/link_renderer_base.rb
|
44
|
-
- lib/will_paginate/view_helpers/merb.rb
|
45
44
|
- lib/will_paginate/view_helpers/sinatra.rb
|
46
|
-
|
47
|
-
- spec/console
|
48
|
-
- spec/console_fixtures.rb
|
49
|
-
- spec/database.yml
|
50
|
-
- spec/fake_rubygems.rb
|
51
|
-
- spec/finders/active_record_spec.rb
|
52
|
-
- spec/finders/activerecord_test_connector.rb
|
53
|
-
- spec/finders/data_mapper_spec.rb
|
54
|
-
- spec/finders/data_mapper_test_connector.rb
|
55
|
-
- spec/finders/mongoid_spec.rb
|
56
|
-
- spec/finders/sequel_spec.rb
|
57
|
-
- spec/finders/sequel_test_connector.rb
|
58
|
-
- spec/fixtures/admin.rb
|
59
|
-
- spec/fixtures/developer.rb
|
60
|
-
- spec/fixtures/developers_projects.yml
|
61
|
-
- spec/fixtures/project.rb
|
62
|
-
- spec/fixtures/projects.yml
|
63
|
-
- spec/fixtures/replies.yml
|
64
|
-
- spec/fixtures/reply.rb
|
65
|
-
- spec/fixtures/schema.rb
|
66
|
-
- spec/fixtures/topic.rb
|
67
|
-
- spec/fixtures/topics.yml
|
68
|
-
- spec/fixtures/user.rb
|
69
|
-
- spec/fixtures/users.yml
|
70
|
-
- spec/matchers/deprecation_matcher.rb
|
71
|
-
- spec/matchers/phrase_matcher.rb
|
72
|
-
- spec/matchers/query_count_matcher.rb
|
73
|
-
- spec/page_number_spec.rb
|
74
|
-
- spec/per_page_spec.rb
|
75
|
-
- spec/spec_helper.rb
|
76
|
-
- spec/view_helpers/action_view_spec.rb
|
77
|
-
- spec/view_helpers/base_spec.rb
|
78
|
-
- spec/view_helpers/link_renderer_base_spec.rb
|
79
|
-
- spec/view_helpers/view_example_group.rb
|
80
|
-
homepage: https://github.com/mislav/will_paginate/wiki
|
45
|
+
homepage: https://github.com/mislav/will_paginate
|
81
46
|
licenses:
|
82
47
|
- MIT
|
83
|
-
metadata:
|
84
|
-
|
48
|
+
metadata:
|
49
|
+
bug_tracker_uri: https://github.com/mislav/will_paginate/issues
|
50
|
+
changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v4.0.0
|
51
|
+
documentation_uri: https://www.rubydoc.info/gems/will_paginate/4.0.0
|
52
|
+
source_code_uri: https://github.com/mislav/will_paginate/tree/v4.0.0
|
53
|
+
wiki_uri: https://github.com/mislav/will_paginate/wiki
|
54
|
+
post_install_message:
|
85
55
|
rdoc_options:
|
86
56
|
- "--main"
|
87
57
|
- README.md
|
@@ -92,16 +62,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
62
|
requirements:
|
93
63
|
- - ">="
|
94
64
|
- !ruby/object:Gem::Version
|
95
|
-
version: '0'
|
65
|
+
version: '2.0'
|
96
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
67
|
requirements:
|
98
68
|
- - ">="
|
99
69
|
- !ruby/object:Gem::Version
|
100
70
|
version: '0'
|
101
71
|
requirements: []
|
102
|
-
|
103
|
-
|
104
|
-
signing_key:
|
72
|
+
rubygems_version: 3.4.6
|
73
|
+
signing_key:
|
105
74
|
specification_version: 4
|
106
75
|
summary: Pagination plugin for web frameworks and other apps
|
107
76
|
test_files: []
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'dm-core'
|
2
|
-
require 'dm-aggregates'
|
3
|
-
require 'will_paginate/per_page'
|
4
|
-
require 'will_paginate/page_number'
|
5
|
-
require 'will_paginate/collection'
|
6
|
-
|
7
|
-
module WillPaginate
|
8
|
-
module DataMapper
|
9
|
-
module Pagination
|
10
|
-
def page(num)
|
11
|
-
pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
|
12
|
-
per_page = query.limit || self.per_page
|
13
|
-
options = {:offset => pagenum.to_offset(per_page).to_i}
|
14
|
-
options[:limit] = per_page unless query.limit
|
15
|
-
col = new_collection(query.merge(options))
|
16
|
-
col.current_page = pagenum
|
17
|
-
col
|
18
|
-
end
|
19
|
-
|
20
|
-
def paginate(options)
|
21
|
-
options = options.dup
|
22
|
-
pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
|
23
|
-
per_page = options.delete(:per_page) || self.per_page
|
24
|
-
total = options.delete(:total_entries)
|
25
|
-
|
26
|
-
options.delete(:page)
|
27
|
-
options[:limit] = per_page.to_i
|
28
|
-
|
29
|
-
|
30
|
-
col = all(options).page(pagenum)
|
31
|
-
col.total_entries = total.to_i unless total.nil? || (total.kind_of?(String) && total.strip.empty?)
|
32
|
-
col
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module CollectionMethods
|
37
|
-
include WillPaginate::CollectionMethods
|
38
|
-
|
39
|
-
attr_accessor :current_page
|
40
|
-
attr_writer :total_entries
|
41
|
-
|
42
|
-
def paginated?
|
43
|
-
!current_page.nil?
|
44
|
-
end
|
45
|
-
|
46
|
-
def per_page
|
47
|
-
query.limit || model.per_page
|
48
|
-
end
|
49
|
-
|
50
|
-
def offset
|
51
|
-
query.offset
|
52
|
-
end
|
53
|
-
|
54
|
-
def total_entries
|
55
|
-
@total_entries ||= begin
|
56
|
-
if loaded? and @array.size < per_page and (current_page == 1 or @array.size > 0)
|
57
|
-
offset + @array.size
|
58
|
-
else
|
59
|
-
# :reload prevents Collection.filter from being run, which
|
60
|
-
# would cause a stack overflow
|
61
|
-
clean_query = query.merge(:reload => true)
|
62
|
-
# seems like the only way
|
63
|
-
clean_query.instance_variable_set('@limit', nil)
|
64
|
-
clean_query.instance_variable_set('@offset', 0)
|
65
|
-
new_collection(clean_query).count
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def to_a
|
71
|
-
if paginated?
|
72
|
-
::WillPaginate::Collection.create(current_page, per_page) do |col|
|
73
|
-
col.replace super
|
74
|
-
col.total_entries ||= total_entries
|
75
|
-
end
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
def new_collection(query, resources = nil)
|
84
|
-
col = super
|
85
|
-
col.current_page = self.current_page
|
86
|
-
col
|
87
|
-
end
|
88
|
-
|
89
|
-
def initialize_copy(original)
|
90
|
-
super
|
91
|
-
@total_entries = nil
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
::DataMapper::Model.append_extensions PerPage
|
96
|
-
::DataMapper::Model.append_extensions Pagination
|
97
|
-
::DataMapper::Collection.send(:include, Pagination)
|
98
|
-
::DataMapper::Collection.send(:include, CollectionMethods)
|
99
|
-
end
|
100
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'will_paginate/core_ext'
|
2
|
-
require 'will_paginate/view_helpers'
|
3
|
-
require 'will_paginate/view_helpers/link_renderer'
|
4
|
-
|
5
|
-
module WillPaginate
|
6
|
-
module Merb
|
7
|
-
include ViewHelpers
|
8
|
-
|
9
|
-
def will_paginate(collection, options = {}) #:nodoc:
|
10
|
-
options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
|
11
|
-
super(collection, options)
|
12
|
-
end
|
13
|
-
|
14
|
-
class LinkRenderer < ViewHelpers::LinkRenderer
|
15
|
-
protected
|
16
|
-
|
17
|
-
def url(page)
|
18
|
-
params = @template.request.params.except(:action, :controller).merge(param_name => page)
|
19
|
-
@template.url(:this, params)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
::Merb::AbstractController.send(:include, self)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|