pagy 3.11.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +10 -4
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/bs.yml +24 -0
- data/lib/locales/hr.yml +24 -0
- data/lib/locales/sr.yml +23 -0
- data/lib/locales/utils/i18n.rb +3 -11
- data/lib/locales/utils/loader.rb +7 -10
- data/lib/locales/utils/p11n.rb +27 -20
- data/lib/pagy.rb +48 -26
- data/lib/pagy/backend.rb +4 -3
- data/lib/pagy/countless.rb +13 -10
- data/lib/pagy/exceptions.rb +8 -5
- data/lib/pagy/extras/arel.rb +3 -3
- data/lib/pagy/extras/array.rb +3 -3
- data/lib/pagy/extras/bootstrap.rb +54 -27
- data/lib/pagy/extras/bulma.rb +52 -34
- data/lib/pagy/extras/countless.rb +5 -7
- data/lib/pagy/extras/elasticsearch_rails.rb +27 -17
- data/lib/pagy/extras/foundation.rb +54 -29
- data/lib/pagy/extras/headers.rb +13 -9
- data/lib/pagy/extras/i18n.rb +8 -11
- data/lib/pagy/extras/items.rb +32 -29
- data/lib/pagy/extras/materialize.rb +50 -32
- data/lib/pagy/extras/metadata.rb +25 -20
- data/lib/pagy/extras/navs.rb +39 -18
- data/lib/pagy/extras/overflow.rb +50 -48
- data/lib/pagy/extras/searchkick.rb +26 -16
- data/lib/pagy/extras/semantic.rb +48 -27
- data/lib/pagy/extras/shared.rb +10 -6
- data/lib/pagy/extras/support.rb +10 -5
- data/lib/pagy/extras/trim.rb +11 -11
- data/lib/pagy/extras/uikit.rb +56 -31
- data/lib/pagy/frontend.rb +47 -29
- metadata +7 -7
- data/lib/locales/README.md +0 -35
- data/lib/pagy/extras/pagy_search.rb +0 -18
- data/pagy.gemspec +0 -16
data/lib/pagy/extras/headers.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/headers
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
5
|
# Add specialized backend methods to add pagination response headers
|
7
|
-
module Backend
|
6
|
+
module Backend
|
7
|
+
private
|
8
8
|
|
9
9
|
VARS[:headers] = { page: 'Current-Page', items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' }
|
10
10
|
|
@@ -15,17 +15,21 @@ class Pagy
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def pagy_headers(pagy)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
pagy_headers_hash(pagy).tap do |hash|
|
19
|
+
hash['Link'] = hash['Link'].map{|rel, link| %(<#{link}>; rel="#{rel}")}.join(', ')
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def pagy_headers_hash(pagy)
|
24
24
|
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
|
25
|
-
rels
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
|
26
|
+
rels['last'] = pagy.last unless countless
|
27
|
+
url_str = pagy_url_for(PAGE_PLACEHOLDER, pagy, :url)
|
28
|
+
hash = { 'Link' => rels.map do |rel, num|
|
29
|
+
next unless num
|
30
|
+
[ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
|
31
|
+
end.compact.to_h }
|
32
|
+
headers = pagy.vars[:headers]
|
29
33
|
hash[headers[:page]] = pagy.page.to_s if headers[:page]
|
30
34
|
hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
|
31
35
|
unless countless
|
data/lib/pagy/extras/i18n.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/i18n
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
@@ -8,18 +7,16 @@ class Pagy
|
|
8
7
|
|
9
8
|
::I18n.load_path += Dir[Pagy.root.join('locales', '*.yml')]
|
10
9
|
|
11
|
-
|
10
|
+
# unload the pagy default constant for efficiency
|
11
|
+
Pagy::I18n.clear.instance_eval do
|
12
|
+
undef :load
|
13
|
+
undef :t
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
def pagy_t_with_i18n(*args) ::I18n.t(*args) end
|
16
|
-
else
|
17
|
-
# keep 1.9 compatibility by hiding 2.0+ syntax in string
|
18
|
-
module_eval <<-RUBY
|
19
|
-
def pagy_t_with_i18n(key, **opts) ::I18n.t(key, **opts) end
|
20
|
-
RUBY
|
16
|
+
module UseI18nGem
|
17
|
+
def pagy_t(key, **opts) = ::I18n.t(key, **opts)
|
21
18
|
end
|
22
|
-
|
19
|
+
prepend UseI18nGem
|
23
20
|
|
24
21
|
end
|
25
22
|
end
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -12,40 +11,42 @@ class Pagy
|
|
12
11
|
|
13
12
|
ITEMS_PLACEHOLDER = '__pagy_items__'
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
module UseItemsExtra
|
15
|
+
private
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
%i[ pagy_get_vars
|
18
|
+
pagy_countless_get_vars
|
19
|
+
pagy_elasticsearch_rails_get_vars
|
20
|
+
pagy_searchkick_get_vars
|
21
|
+
].each do |meth|
|
22
|
+
next unless Backend.private_method_defined?(meth, true)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def pagy#{prefix}_get_vars_with_items(collection, vars)
|
30
|
-
pagy_with_items(vars)
|
31
|
-
pagy#{prefix}_get_vars_without_items(collection, vars)
|
32
|
-
end
|
33
|
-
alias_method :pagy#{prefix}_get_vars, :pagy#{prefix}_get_vars_with_items
|
34
|
-
#{if_end}
|
35
|
-
RUBY
|
24
|
+
define_method(meth) do |collection, vars|
|
25
|
+
vars[:items] ||= if (items = params[vars[:items_param] || VARS[:items_param]]) # :items from :items_param
|
26
|
+
[items.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items
|
27
|
+
end
|
28
|
+
super collection, vars
|
29
|
+
end
|
36
30
|
end
|
37
31
|
|
38
32
|
end
|
33
|
+
Backend.prepend UseItemsExtra
|
34
|
+
|
39
35
|
|
40
36
|
module Frontend
|
41
37
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
module UseItemsExtra
|
39
|
+
|
40
|
+
def pagy_url_for(page, pagy, url=nil)
|
41
|
+
p_vars = pagy.vars
|
42
|
+
params = request.GET.merge(p_vars[:params])
|
43
|
+
params[p_vars[:page_param].to_s] = page
|
44
|
+
params[p_vars[:items_param].to_s] = p_vars[:items]
|
45
|
+
"#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
46
|
+
end
|
47
|
+
|
47
48
|
end
|
48
|
-
|
49
|
+
prepend UseItemsExtra
|
49
50
|
|
50
51
|
# Return the items selector HTML. For example "Show [20] items per page"
|
51
52
|
def pagy_items_selector_js(pagy, id=pagy_id)
|
@@ -55,10 +56,12 @@ class Pagy
|
|
55
56
|
link = pagy_marked_link(pagy_link_proc(pagy))
|
56
57
|
p_vars[:items] = p_items # restore the items
|
57
58
|
|
58
|
-
html
|
59
|
+
html = %(<span id="#{id}">)
|
59
60
|
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
|
60
|
-
html <<
|
61
|
-
|
61
|
+
html << pagy_t('pagy.items_selector_js', item_name: pagy_t(p_vars[:i18n_key], count: p_items),
|
62
|
+
items_input: input,
|
63
|
+
count: p_items)
|
64
|
+
html << %(</span>#{pagy_json_tag(pagy, :items_selector, id, pagy.from, link)})
|
62
65
|
end
|
63
66
|
|
64
67
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -9,51 +8,70 @@ class Pagy
|
|
9
8
|
|
10
9
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
11
10
|
def pagy_materialize_nav(pagy)
|
12
|
-
link
|
13
|
-
|
14
|
-
|
11
|
+
link = pagy_link_proc(pagy)
|
12
|
+
|
13
|
+
html = +%(<div class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
|
+
html << pagy_materialize_prev_html(pagy, link)
|
15
15
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
|
-
html <<
|
17
|
-
|
18
|
-
|
16
|
+
html << case item
|
17
|
+
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
18
|
+
when String then %(<li class="active">#{link.call item}</li>) # active page
|
19
|
+
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
|
19
20
|
end
|
20
21
|
end
|
21
|
-
html << (
|
22
|
-
|
23
|
-
%(<div class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
|
22
|
+
html << pagy_materialize_next_html(pagy, link)
|
23
|
+
html << %(</ul></div>)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
27
|
def pagy_materialize_nav_js(pagy, id=pagy_id)
|
28
|
-
link
|
29
|
-
tags = { 'before' => (
|
30
|
-
+ (p_prev ? %(<li class="waves-effect prev">#{link.call(p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"')}</li>)
|
31
|
-
: %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>)) ),
|
28
|
+
link = pagy_link_proc(pagy)
|
29
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}),
|
32
30
|
'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
33
31
|
'active' => %(<li class="active">#{mark}</li>),
|
34
|
-
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t
|
35
|
-
'after' =>
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
33
|
+
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }
|
34
|
+
|
35
|
+
html = %(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
|
36
|
+
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
39
37
|
end
|
40
38
|
|
41
39
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
42
40
|
def pagy_materialize_combo_nav_js(pagy, id=pagy_id)
|
43
|
-
link
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
link = pagy_link_proc(pagy)
|
42
|
+
p_page = pagy.page
|
43
|
+
p_pages = pagy.pages
|
44
|
+
style = ' style="vertical-align: middle;"'
|
45
|
+
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
46
|
+
|
47
|
+
%(<div id="#{id}" class="pagy-materialize-combo-nav-js pagination" role="navigation" aria-label="pager"><div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;"><ul class="pagination" style="margin: 0px;">#{
|
48
|
+
pagy_materialize_prev_html pagy, link, style
|
49
|
+
}<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{
|
50
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
51
|
+
}</div>#{
|
52
|
+
pagy_materialize_next_html pagy, link, style
|
53
|
+
}</ul></div>#{
|
54
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
55
|
+
})
|
56
56
|
end
|
57
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def pagy_materialize_prev_html(pagy, link, style='')
|
61
|
+
if (p_prev = pagy.prev)
|
62
|
+
%(<li class="waves-effect prev"#{style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
63
|
+
else
|
64
|
+
%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def pagy_materialize_next_html(pagy, link, style='')
|
69
|
+
if (p_next = pagy.next)
|
70
|
+
%(<li class="waves-effect next"#{style}>#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
71
|
+
else
|
72
|
+
%(<li class="next disabled"#{style}><a href="#"><i class="material-icons">chevron_right</i></a></li>)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
58
76
|
end
|
59
77
|
end
|
data/lib/pagy/extras/metadata.rb
CHANGED
@@ -1,36 +1,41 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/metadata
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
5
|
# Add a specialized backend method for pagination metadata
|
7
|
-
module Backend
|
6
|
+
module Backend
|
7
|
+
private
|
8
8
|
|
9
|
-
METADATA = [
|
10
|
-
|
11
|
-
|
9
|
+
METADATA = %i[ scaffold_url first_url prev_url page_url next_url last_url
|
10
|
+
count page items vars pages last from to prev next series
|
11
|
+
].tap do |metadata|
|
12
|
+
metadata << :sequels if VARS.key?(:steps) # :steps gets defined along with the #sequels method
|
13
|
+
end.freeze
|
12
14
|
|
13
15
|
VARS[:metadata] = METADATA.dup
|
14
16
|
|
15
17
|
include Helpers
|
16
18
|
|
17
|
-
def pagy_metadata(pagy, url=
|
18
|
-
names
|
19
|
-
|
19
|
+
def pagy_metadata(pagy, url=nil)
|
20
|
+
names = pagy.vars[:metadata]
|
21
|
+
unknown = names - METADATA
|
22
|
+
raise VariableError.new(pagy), "unknown metadata #{unknown.inspect}" \
|
23
|
+
unless unknown.empty?
|
24
|
+
|
20
25
|
scaffold_url = pagy_url_for(PAGE_PLACEHOLDER, pagy, url)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
{}.tap do |metadata|
|
27
|
+
names.each do |key|
|
28
|
+
metadata[key] = case key
|
29
|
+
when :scaffold_url then scaffold_url
|
30
|
+
when :first_url then scaffold_url.sub(PAGE_PLACEHOLDER, 1.to_s)
|
31
|
+
when :prev_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.prev.to_s)
|
32
|
+
when :page_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.page.to_s)
|
33
|
+
when :next_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.next.to_s)
|
34
|
+
when :last_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.last.to_s)
|
35
|
+
else pagy.send(key)
|
36
|
+
end
|
37
|
+
end
|
32
38
|
end
|
33
|
-
metadata
|
34
39
|
end
|
35
40
|
|
36
41
|
end
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -9,30 +8,52 @@ class Pagy
|
|
9
8
|
|
10
9
|
# Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
11
10
|
def pagy_nav_js(pagy, id=pagy_id)
|
12
|
-
link
|
13
|
-
tags = { 'before' =>
|
14
|
-
: %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ),
|
11
|
+
link = pagy_link_proc(pagy)
|
12
|
+
tags = { 'before' => pagy_nav_prev_html(pagy, link),
|
15
13
|
'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
|
16
14
|
'active' => %(<span class="page active">#{pagy.page}</span> ),
|
17
|
-
'gap' => %(<span class="page gap">#{pagy_t
|
18
|
-
'after' =>
|
19
|
-
|
20
|
-
%(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav
|
15
|
+
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
|
16
|
+
'after' => pagy_nav_next_html(pagy, link) }
|
17
|
+
|
18
|
+
html = %(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>)
|
19
|
+
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
21
20
|
end
|
22
21
|
|
23
22
|
# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
24
23
|
def pagy_combo_nav_js(pagy, id=pagy_id)
|
25
|
-
link
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
link = pagy_link_proc(pagy)
|
25
|
+
p_page = pagy.page
|
26
|
+
p_pages = pagy.pages
|
27
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
28
|
+
|
29
|
+
%(<nav id="#{id}" class="pagy-combo-nav-js pagination" role="navigation" aria-label="pager">#{
|
30
|
+
pagy_nav_prev_html pagy, link
|
31
|
+
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
|
32
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
33
|
+
}</span> #{
|
34
|
+
pagy_nav_next_html pagy, link
|
35
|
+
}</nav>#{
|
36
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
37
|
+
})
|
35
38
|
end
|
36
39
|
|
40
|
+
private
|
41
|
+
|
42
|
+
def pagy_nav_prev_html(pagy, link)
|
43
|
+
if (p_prev = pagy.prev)
|
44
|
+
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
45
|
+
else
|
46
|
+
%(<span class="page prev disabled">#{pagy_t 'pagy.nav.prev'}</span> )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def pagy_nav_next_html(pagy, link)
|
51
|
+
if (p_next = pagy.next)
|
52
|
+
%(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
53
|
+
else
|
54
|
+
%(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
37
58
|
end
|
38
59
|
end
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -1,71 +1,73 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/overflow
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
5
|
|
7
|
-
|
6
|
+
module UseOverflowExtra
|
7
|
+
VARS[:overflow] = :empty_page
|
8
8
|
|
9
|
-
|
9
|
+
def overflow? = @overflow
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
raise VariableError.new(self), "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
11
|
+
def initialize(vars)
|
12
|
+
@overflow ||= false # don't override if :last_page re-run the method after an overflow
|
13
|
+
super
|
14
|
+
rescue OverflowError
|
15
|
+
@overflow = true # add the overflow flag
|
16
|
+
case @vars[:overflow]
|
17
|
+
when :exception
|
18
|
+
raise # same as without the extra
|
19
|
+
when :last_page
|
20
|
+
initial_page = @vars[:page] # save the very initial page (even after re-run)
|
21
|
+
initialize vars.merge!(page: @last) # re-run with the last page
|
22
|
+
@vars[:page] = initial_page # restore the inital page
|
23
|
+
when :empty_page
|
24
|
+
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
25
|
+
@prev = @last # prev relative to the actual page
|
26
|
+
extend Series # special series for :empty_page
|
27
|
+
else
|
28
|
+
raise VariableError.new(self), "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
29
|
+
end
|
32
30
|
end
|
33
|
-
end
|
34
|
-
alias_method :initialize, :initialize_with_overflow
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
module Series
|
33
|
+
def series(size=@vars[:size])
|
34
|
+
@page = @last # series for last page
|
35
|
+
super(size).tap do |s| # call original series
|
36
|
+
s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
|
37
|
+
@page = @vars[:page] # restore the actual page
|
38
|
+
end
|
42
39
|
end
|
43
40
|
end
|
41
|
+
|
44
42
|
end
|
43
|
+
prepend UseOverflowExtra
|
45
44
|
|
46
45
|
|
47
46
|
# support for Pagy::Countless
|
48
47
|
if defined?(Pagy::Countless)
|
49
48
|
class Countless
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
50
|
+
module UseOverflowExtra
|
51
|
+
|
52
|
+
def finalize(items)
|
53
|
+
@overflow = false
|
54
|
+
super
|
55
|
+
rescue OverflowError
|
56
|
+
@overflow = true # add the overflow flag
|
57
|
+
case @vars[:overflow]
|
58
|
+
when :exception
|
59
|
+
raise # same as without the extra
|
60
|
+
when :empty_page
|
61
|
+
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
62
|
+
@vars[:size] = [] # no page in the series
|
63
|
+
self
|
64
|
+
else
|
65
|
+
raise VariableError.new(self), "expected :overflow variable in [:empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
66
|
+
end
|
66
67
|
end
|
68
|
+
|
67
69
|
end
|
68
|
-
|
70
|
+
prepend UseOverflowExtra
|
69
71
|
|
70
72
|
end
|
71
73
|
end
|