pagy 3.13.0 → 4.10.1
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/LICENSE.txt +1 -1
- data/lib/config/pagy.rb +36 -25
- data/lib/javascripts/pagy.js +104 -93
- data/lib/locales/ar.yml +26 -0
- data/lib/locales/bg.yml +2 -2
- data/lib/locales/bs.yml +2 -2
- data/lib/locales/ca.yml +2 -2
- data/lib/locales/cs.yml +2 -2
- data/lib/locales/da.yml +2 -2
- data/lib/locales/de.yml +2 -2
- data/lib/locales/en.yml +2 -2
- data/lib/locales/es.yml +2 -2
- data/lib/locales/fr.yml +2 -2
- data/lib/locales/hr.yml +2 -2
- data/lib/locales/id.yml +2 -2
- data/lib/locales/it.yml +2 -2
- data/lib/locales/ja.yml +2 -2
- data/lib/locales/km.yml +2 -2
- data/lib/locales/ko.yml +2 -2
- data/lib/locales/nb.yml +2 -2
- data/lib/locales/nl.yml +2 -2
- data/lib/locales/pl.yml +2 -2
- data/lib/locales/pt-BR.yml +2 -2
- data/lib/locales/pt.yml +2 -2
- data/lib/locales/ru.yml +2 -2
- data/lib/locales/sr.yml +2 -2
- data/lib/locales/sv-SE.yml +2 -2
- data/lib/locales/sv.yml +2 -2
- data/lib/locales/sw.yml +2 -2
- data/lib/locales/tr.yml +2 -2
- data/lib/locales/uk.yml +24 -0
- data/lib/locales/utils/i18n.rb +3 -11
- data/lib/locales/utils/loader.rb +7 -10
- data/lib/locales/utils/p11n.rb +44 -23
- data/lib/locales/zh-CN.yml +2 -2
- data/lib/locales/zh-HK.yml +2 -2
- data/lib/locales/zh-TW.yml +3 -3
- data/lib/pagy.rb +51 -40
- data/lib/pagy/backend.rb +5 -3
- data/lib/pagy/console.rb +21 -0
- data/lib/pagy/countless.rb +13 -10
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/exceptions.rb +6 -2
- data/lib/pagy/extras/arel.rb +4 -3
- data/lib/pagy/extras/array.rb +4 -3
- data/lib/pagy/extras/bootstrap.rb +61 -30
- data/lib/pagy/extras/bulma.rb +60 -38
- data/lib/pagy/extras/countless.rb +7 -8
- data/lib/pagy/extras/elasticsearch_rails.rb +28 -17
- data/lib/pagy/extras/foundation.rb +61 -32
- data/lib/pagy/extras/headers.rb +13 -9
- data/lib/pagy/extras/i18n.rb +10 -11
- data/lib/pagy/extras/items.rb +21 -34
- data/lib/pagy/extras/materialize.rb +58 -35
- data/lib/pagy/extras/meilisearch.rb +55 -0
- data/lib/pagy/extras/metadata.rb +27 -21
- data/lib/pagy/extras/navs.rb +44 -20
- data/lib/pagy/extras/overflow.rb +52 -48
- data/lib/pagy/extras/searchkick.rb +27 -16
- data/lib/pagy/extras/semantic.rb +55 -30
- data/lib/pagy/extras/shared.rb +14 -15
- data/lib/pagy/extras/standalone.rb +62 -0
- data/lib/pagy/extras/support.rb +20 -11
- data/lib/pagy/extras/trim.rb +12 -11
- data/lib/pagy/extras/uikit.rb +54 -35
- data/lib/pagy/frontend.rb +64 -33
- metadata +10 -8
- data/lib/pagy/extras/pagy_search.rb +0 -18
data/lib/pagy/backend.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See Pagy::Backend API documentation: https://ddnexus.github.io/pagy/api/backend
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
@@ -8,16 +7,19 @@ class Pagy
|
|
8
7
|
|
9
8
|
# See also the extras if you need specialized methods to paginate Arrays or other collections
|
10
9
|
|
11
|
-
|
10
|
+
|
11
|
+
module Backend
|
12
|
+
private # the whole module is private so no problem with including it in a controller
|
12
13
|
|
13
14
|
# Return Pagy object and items
|
14
15
|
def pagy(collection, vars={})
|
15
16
|
pagy = Pagy.new(pagy_get_vars(collection, vars))
|
16
|
-
|
17
|
+
[ pagy, pagy_get_items(collection, pagy) ]
|
17
18
|
end
|
18
19
|
|
19
20
|
# Sub-method called only by #pagy: here for easy customization of variables by overriding
|
20
21
|
def pagy_get_vars(collection, vars)
|
22
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
21
23
|
vars[:count] ||= (c = collection.count(:all)).is_a?(Hash) ? c.size : c
|
22
24
|
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
23
25
|
vars
|
data/lib/pagy/console.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pagy' # so you can require just the extra in the console
|
4
|
+
require 'pagy/extras/standalone'
|
5
|
+
|
6
|
+
class Pagy
|
7
|
+
# include Pagy::Console in irb/rails console for a ready to use pagy environment
|
8
|
+
module Console
|
9
|
+
def self.included(main)
|
10
|
+
main.include(Backend)
|
11
|
+
main.include(Frontend)
|
12
|
+
VARS[:url] = 'http://www.example.com/subdir'
|
13
|
+
end
|
14
|
+
|
15
|
+
def pagy_extras(*extras)
|
16
|
+
extras.each {|extra| require "pagy/extras/#{extra}"}
|
17
|
+
puts "Required extras: #{extras.map(&:inspect).join(', ')}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/pagy/countless.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'pagy'
|
@@ -7,25 +6,29 @@ class Pagy
|
|
7
6
|
|
8
7
|
class Countless < Pagy
|
9
8
|
|
9
|
+
INSTANCE_VARS_MIN = { items: 1, page: 1, outset: 0 }.freeze
|
10
|
+
|
10
11
|
# Merge and validate the options, do some simple arithmetic and set a few instance variables
|
11
|
-
def initialize(vars={})
|
12
|
+
def initialize(vars={}) # rubocop:disable Lint/MissingSuper
|
12
13
|
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden)
|
13
|
-
|
14
|
-
(
|
15
|
-
|
14
|
+
INSTANCE_VARS_MIN.each do |k,min| # validate instance variables
|
15
|
+
raise VariableError.new(self), "expected :#{k} >= #{min}; got #{@vars[k].inspect}" \
|
16
|
+
unless @vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min
|
16
17
|
end
|
17
18
|
@offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
|
18
19
|
end
|
19
20
|
|
20
21
|
# Finalize the instance variables based on the fetched items
|
21
22
|
def finalize(fetched)
|
22
|
-
|
23
|
+
raise OverflowError.new(self), "page #{@page} got no items" \
|
24
|
+
if fetched.zero? && @page > 1
|
25
|
+
|
23
26
|
@pages = @last = (fetched > @items ? @page + 1 : @page) # set the @pages and @last
|
24
|
-
@items = fetched if fetched < @items && fetched
|
25
|
-
@from = fetched
|
26
|
-
@to = fetched
|
27
|
+
@items = fetched if fetched < @items && fetched.positive? # adjust items for last non-empty page
|
28
|
+
@from = fetched.zero? ? 0 : @offset + 1 - @outset # page begins from item
|
29
|
+
@to = fetched.zero? ? 0 : @offset + @items - @outset # page ends to item
|
27
30
|
@prev = (@page-1 unless @page == 1) # nil if no prev page
|
28
|
-
@next = @page == @last ? (1 if @vars[:cycle]) : @page+1
|
31
|
+
@next = @page == @last ? (1 if @vars[:cycle]) : @page + 1 # nil if no next page, 1 if :cycle
|
29
32
|
self
|
30
33
|
end
|
31
34
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class Pagy
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# deprecated variables
|
6
|
+
def deprecated_var(var, val, new_var, new_val)
|
7
|
+
value = val || new_val
|
8
|
+
Warning.warn %([PAGY WARNING] deprecated use of '#{var}' var will not be supported in 5.0! Use '#{new_var}: #{value.inspect}' instead.)
|
9
|
+
value
|
10
|
+
end
|
11
|
+
|
12
|
+
# deprecated pagy_url_for argument order
|
13
|
+
def deprecated_order(pagy, page)
|
14
|
+
Warning.warn %([PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.)
|
15
|
+
[page, pagy]
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# deprecated posiitioal arguments
|
20
|
+
def deprecated_arg(arg, val, new_key, new_val)
|
21
|
+
value = val || new_val # we use the new_val if present
|
22
|
+
Warning.warn %([PAGY WARNING] deprecated use of positional '#{arg}' arg will not be supported in 5.0! Use only the keyword arg '#{new_key}: #{value.inspect}' instead.)
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/pagy/exceptions.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pagy
|
2
4
|
|
5
|
+
# generic variable error
|
3
6
|
class VariableError < ArgumentError
|
4
7
|
attr_reader :pagy
|
5
8
|
|
@@ -9,8 +12,8 @@ class Pagy
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def variable
|
12
|
-
message =~ /expected :(
|
13
|
-
|
15
|
+
message =~ /expected :(\w+)/
|
16
|
+
Regexp.last_match(1)&.to_sym
|
14
17
|
end
|
15
18
|
|
16
19
|
def value
|
@@ -18,6 +21,7 @@ class Pagy
|
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
24
|
+
# specific overflow error
|
21
25
|
class OverflowError < VariableError; end
|
22
26
|
|
23
27
|
end
|
data/lib/pagy/extras/arel.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/arel
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
|
-
module Backend
|
5
|
+
module Backend
|
6
|
+
private
|
7
7
|
|
8
8
|
def pagy_arel(collection, vars={})
|
9
9
|
pagy = Pagy.new(pagy_arel_get_vars(collection, vars))
|
10
|
-
|
10
|
+
[ pagy, pagy_get_items(collection, pagy) ]
|
11
11
|
end
|
12
12
|
|
13
13
|
def pagy_arel_get_vars(collection, vars)
|
14
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
14
15
|
vars[:count] ||= pagy_arel_count(collection)
|
15
16
|
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
16
17
|
vars
|
data/lib/pagy/extras/array.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/array
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
5
|
# Add specialized backend methods to paginate array collections
|
7
|
-
module Backend
|
6
|
+
module Backend
|
7
|
+
private
|
8
8
|
|
9
9
|
# Return Pagy object and items
|
10
10
|
def pagy_array(array, vars={})
|
11
11
|
pagy = Pagy.new(pagy_array_get_vars(array, vars))
|
12
|
-
|
12
|
+
[ pagy, array[pagy.offset, pagy.items] ]
|
13
13
|
end
|
14
14
|
|
15
15
|
# Sub-method called only by #pagy_array: here for easy customization of variables by overriding
|
16
16
|
def pagy_array_get_vars(array, vars)
|
17
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
17
18
|
vars[:count] ||= array.size
|
18
19
|
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
19
20
|
vars
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bootstrap
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -8,48 +7,80 @@ class Pagy
|
|
8
7
|
module Frontend
|
9
8
|
|
10
9
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
11
|
-
def pagy_bootstrap_nav(pagy)
|
12
|
-
|
10
|
+
def pagy_bootstrap_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
13
13
|
|
14
|
-
html =
|
15
|
-
|
14
|
+
html = +%(<nav#{p_id} class="pagy-bootstrap-nav" aria-label="pager"><ul class="pagination">)
|
15
|
+
html << pagy_bootstrap_prev_html(pagy, link)
|
16
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
-
html <<
|
18
|
-
|
19
|
-
|
17
|
+
html << case item
|
18
|
+
when Integer then %(<li class="page-item">#{link.call item}</li>)
|
19
|
+
when String then %(<li class="page-item active">#{link.call item}</li>)
|
20
|
+
when :gap then %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>)
|
20
21
|
end
|
21
22
|
end
|
22
|
-
html << (
|
23
|
-
|
24
|
-
%(<nav class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
|
23
|
+
html << pagy_bootstrap_next_html(pagy, link)
|
24
|
+
html << %(</ul></nav>)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
28
|
-
def pagy_bootstrap_nav_js(pagy,
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def pagy_bootstrap_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
29
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
30
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
31
|
+
link = pagy_link_proc(pagy, link_extra: %(class="page-link" #{link_extra}))
|
32
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
|
32
33
|
'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
33
34
|
'active' => %(<li class="page-item active">#{mark}</li>),
|
34
|
-
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t
|
35
|
-
'after' =>
|
36
|
-
|
37
|
-
%(<nav
|
35
|
+
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
36
|
+
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }
|
37
|
+
|
38
|
+
%(<nav#{p_id} class="pagy-njs pagy-bootstrap-nav-js" aria-label="pager" #{pagy_json_attr(pagy, :nav, tags, pagy.sequels(steps))}></nav>)
|
38
39
|
end
|
39
40
|
|
40
41
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
41
|
-
def pagy_bootstrap_combo_nav_js(pagy,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
input
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
def pagy_bootstrap_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
43
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
44
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
45
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
46
|
+
p_page = pagy.page
|
47
|
+
p_pages = pagy.pages
|
48
|
+
input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" class="text-primary" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
49
|
+
|
50
|
+
%(<nav#{p_id} class="pagy-bootstrap-combo-nav-js pagination" aria-label="pager"><div class="btn-group" role="group" #{
|
51
|
+
pagy_json_attr pagy, :combo_nav, p_page, pagy_marked_link(link)
|
52
|
+
}>#{
|
53
|
+
if (p_prev = pagy.prev)
|
54
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"'
|
55
|
+
else
|
56
|
+
%(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>)
|
57
|
+
end
|
58
|
+
}<div class="pagy-combo-input btn btn-primary disabled" style="white-space: nowrap;">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
|
59
|
+
if (p_next = pagy.next)
|
60
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"'
|
61
|
+
else
|
62
|
+
%(<a class="next btn btn-primary disabled" href="#">#{pagy_t 'pagy.nav.next' }</a>)
|
63
|
+
end
|
64
|
+
}</div></nav>)
|
52
65
|
end
|
53
66
|
|
67
|
+
private
|
68
|
+
|
69
|
+
def pagy_bootstrap_prev_html(pagy, link)
|
70
|
+
if (p_prev = pagy.prev)
|
71
|
+
%(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
72
|
+
else
|
73
|
+
%(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.prev'}</a></li>)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def pagy_bootstrap_next_html(pagy, link)
|
78
|
+
if (p_next = pagy.next)
|
79
|
+
%(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
80
|
+
else
|
81
|
+
%(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.next'}</a></li>)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
54
85
|
end
|
55
86
|
end
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/bulma
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -8,53 +7,76 @@ class Pagy
|
|
8
7
|
module Frontend
|
9
8
|
|
10
9
|
# Pagination for Bulma: it returns the html with the series of links to the pages
|
11
|
-
def pagy_bulma_nav(pagy)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
html << '<ul class="pagination-list">'
|
10
|
+
def pagy_bulma_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
13
|
+
|
14
|
+
html = +%(<nav#{p_id} class="pagy-bulma-nav pagination is-centered" aria-label="pagination">)
|
15
|
+
html << pagy_bulma_prev_next_html(pagy, link)
|
16
|
+
html << %(<ul class="pagination-list">)
|
19
17
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
20
|
-
html <<
|
21
|
-
|
22
|
-
|
18
|
+
html << case item
|
19
|
+
when Integer then %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}") }</li>) # page link
|
20
|
+
when String then %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>) # active page
|
21
|
+
when :gap then %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>) # page gap
|
23
22
|
end
|
24
23
|
end
|
25
|
-
html <<
|
26
|
-
%(<nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
|
24
|
+
html << %(</ul></nav>)
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
'link' => %(<li>#{link.call(PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}"))}</li>),
|
38
|
-
'active' => %(<li>#{link.call(PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}"))}</li>),
|
39
|
-
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>),
|
27
|
+
def pagy_bulma_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
28
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
29
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
30
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
31
|
+
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
|
32
|
+
'link' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}")}</li>),
|
33
|
+
'active' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}")}</li>),
|
34
|
+
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap' }</span></li>),
|
40
35
|
'after' => '</ul>' }
|
41
|
-
|
36
|
+
|
37
|
+
%(<nav#{p_id} class="pagy-njs pagy-bulma-nav-js pagination is-centered" aria-label="pagination" #{pagy_json_attr(pagy, :nav, tags, pagy.sequels(steps))}></nav>)
|
42
38
|
end
|
43
39
|
|
44
40
|
# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
45
|
-
def pagy_bulma_combo_nav_js(pagy,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
42
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
43
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
44
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
45
|
+
p_page = pagy.page
|
46
|
+
p_pages = pagy.pages
|
47
|
+
input = %(<input class="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; margin:0 0.3rem;">)
|
48
|
+
|
49
|
+
%(<nav#{p_id} class="pagy-bulma-combo-nav-js" aria-label="pagination"><div class="field is-grouped is-grouped-centered" role="group" #{
|
50
|
+
pagy_json_attr pagy, :combo_nav, p_page, pagy_marked_link(link)
|
51
|
+
}>#{
|
52
|
+
if (p_prev = pagy.prev)
|
53
|
+
%(<p class="control">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"'}</p>)
|
54
|
+
else
|
55
|
+
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.prev'}</a></p>)
|
56
|
+
end
|
57
|
+
}<div class="pagy-combo-input control level is-mobile">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</div>#{
|
58
|
+
if (p_next = pagy.next)
|
59
|
+
%(<p class="control">#{link.call p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"'}</p>)
|
60
|
+
else
|
61
|
+
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.next'}</a></p>)
|
62
|
+
end
|
63
|
+
}</div></nav>)
|
57
64
|
end
|
58
65
|
|
66
|
+
private
|
67
|
+
|
68
|
+
def pagy_bulma_prev_next_html(pagy, link)
|
69
|
+
html = +if (p_prev = pagy.prev)
|
70
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"'
|
71
|
+
else
|
72
|
+
%(<a class="pagination-previous" disabled>#{pagy_t 'pagy.nav.prev'}</a>)
|
73
|
+
end
|
74
|
+
html << if (p_next = pagy.next)
|
75
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"'
|
76
|
+
else
|
77
|
+
%(<a class="pagination-next" disabled>#{pagy_t 'pagy.nav.next' }</a>)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
59
81
|
end
|
60
82
|
end
|
@@ -1,25 +1,23 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/countless
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/countless'
|
6
5
|
|
7
6
|
class Pagy
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
module Backend ; private # the whole module is private so no problem with including it in a controller
|
8
|
+
module Backend
|
9
|
+
private # the whole module is private so no problem with including it in a controller
|
13
10
|
|
14
11
|
# Return Pagy object and items
|
15
12
|
def pagy_countless(collection, vars={})
|
16
13
|
pagy = Pagy::Countless.new(pagy_countless_get_vars(collection, vars))
|
17
|
-
|
14
|
+
[ pagy, pagy_countless_get_items(collection, pagy) ]
|
18
15
|
end
|
19
16
|
|
20
17
|
# Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
|
21
18
|
def pagy_countless_get_vars(_collection, vars)
|
22
|
-
vars
|
19
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
20
|
+
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
23
21
|
vars
|
24
22
|
end
|
25
23
|
|
@@ -29,7 +27,8 @@ class Pagy
|
|
29
27
|
items = collection.offset(pagy.offset).limit(pagy.items + 1).to_a
|
30
28
|
items_size = items.size
|
31
29
|
items.pop if items_size == pagy.items + 1
|
32
|
-
|
30
|
+
# finalize may adjust pagy.items, so must be used after checking the size
|
31
|
+
pagy.finalize(items_size)
|
33
32
|
items
|
34
33
|
end
|
35
34
|
|