pagy 3.11.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/exceptions.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
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
|
|
6
9
|
def initialize(pagy)
|
10
|
+
super
|
7
11
|
@pagy = pagy
|
8
12
|
end
|
9
13
|
|
10
14
|
def variable
|
11
|
-
message =~ /expected :(
|
12
|
-
|
15
|
+
message =~ /expected :(\w+)/
|
16
|
+
Regexp.last_match(1)&.to_sym
|
13
17
|
end
|
14
18
|
|
15
|
-
def value
|
16
|
-
pagy.vars[variable]
|
17
|
-
end
|
19
|
+
def value = pagy.vars[variable]
|
18
20
|
end
|
19
21
|
|
22
|
+
# specific overflow error
|
20
23
|
class OverflowError < VariableError; end
|
21
24
|
|
22
25
|
end
|
data/lib/pagy/extras/arel.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
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)
|
data/lib/pagy/extras/array.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
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
|
@@ -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'
|
@@ -9,47 +8,75 @@ class Pagy
|
|
9
8
|
|
10
9
|
# Pagination for bootstrap: it returns the html with the series of links to the pages
|
11
10
|
def pagy_bootstrap_nav(pagy)
|
12
|
-
link
|
11
|
+
link = pagy_link_proc(pagy, 'class="page-link"')
|
13
12
|
|
14
|
-
html =
|
15
|
-
|
13
|
+
html = +%(<nav class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
|
+
html << pagy_bootstrap_prev_html(pagy, link)
|
16
15
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
-
html <<
|
18
|
-
|
19
|
-
|
16
|
+
html << case item
|
17
|
+
when Integer then %(<li class="page-item">#{link.call item}</li>)
|
18
|
+
when String then %(<li class="page-item active">#{link.call item}</li>)
|
19
|
+
when :gap then %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
html << (
|
23
|
-
|
24
|
-
%(<nav class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
|
22
|
+
html << pagy_bootstrap_next_html(pagy, link)
|
23
|
+
html << %(</ul></nav>)
|
25
24
|
end
|
26
25
|
|
27
26
|
# Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
28
27
|
def pagy_bootstrap_nav_js(pagy, id=pagy_id)
|
29
|
-
link
|
30
|
-
tags = { 'before' =>
|
31
|
-
: %(<ul class="pagination"><li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>),
|
28
|
+
link = pagy_link_proc(pagy, 'class="page-link"')
|
29
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_bootstrap_prev_html pagy, link}),
|
32
30
|
'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
33
31
|
'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 id="#{id}" class="pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav
|
32
|
+
'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
33
|
+
'after' => %(#{pagy_bootstrap_next_html pagy, link}</ul>) }
|
34
|
+
|
35
|
+
html = %(<nav id="#{id}" class="pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav>)
|
36
|
+
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
38
37
|
end
|
39
38
|
|
40
39
|
# Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
41
40
|
def pagy_bootstrap_combo_nav_js(pagy, id=pagy_id)
|
42
|
-
link
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
link = pagy_link_proc(pagy)
|
42
|
+
p_page = pagy.page
|
43
|
+
p_pages = pagy.pages
|
44
|
+
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;">)
|
45
|
+
|
46
|
+
%(<nav id="#{id}" class="pagy-bootstrap-combo-nav-js pagination" role="navigation" aria-label="pager"><div class="btn-group" role="group">#{
|
47
|
+
if (p_prev = pagy.prev)
|
48
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"'
|
49
|
+
else
|
50
|
+
%(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>)
|
51
|
+
end
|
52
|
+
}<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>#{
|
53
|
+
if (p_next = pagy.next)
|
54
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"'
|
55
|
+
else
|
56
|
+
%(<a class="next btn btn-primary disabled" href="#">#{pagy_t 'pagy.nav.next' }</a>)
|
57
|
+
end
|
58
|
+
}</div></nav>#{
|
59
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
60
|
+
})
|
52
61
|
end
|
53
62
|
|
63
|
+
private
|
64
|
+
|
65
|
+
def pagy_bootstrap_prev_html(pagy, link)
|
66
|
+
if (p_prev = pagy.prev)
|
67
|
+
%(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
68
|
+
else
|
69
|
+
%(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.prev'}</a></li>)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def pagy_bootstrap_next_html(pagy, link)
|
74
|
+
if (p_next = pagy.next)
|
75
|
+
%(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
76
|
+
else
|
77
|
+
%(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t 'pagy.nav.next'}</a></li>)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
54
81
|
end
|
55
82
|
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'
|
@@ -9,52 +8,71 @@ class Pagy
|
|
9
8
|
|
10
9
|
# Pagination for Bulma: it returns the html with the series of links to the pages
|
11
10
|
def pagy_bulma_nav(pagy)
|
12
|
-
link
|
11
|
+
link = pagy_link_proc(pagy)
|
13
12
|
|
14
|
-
html = (
|
15
|
-
|
16
|
-
|
17
|
-
: %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
|
18
|
-
html << '<ul class="pagination-list">'
|
13
|
+
html = +%(<nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">)
|
14
|
+
html << pagy_bulma_prev_next_html(pagy, link)
|
15
|
+
html << %(<ul class="pagination-list">)
|
19
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
20
|
-
html <<
|
21
|
-
|
22
|
-
|
17
|
+
html << case item
|
18
|
+
when Integer then %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}") }</li>) # page link
|
19
|
+
when String then %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-label="page #{item}" aria-current="page")}</li>) # active page
|
20
|
+
when :gap then %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>) # page gap
|
23
21
|
end
|
24
22
|
end
|
25
|
-
html <<
|
26
|
-
%(<nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
|
23
|
+
html << %(</ul></nav>)
|
27
24
|
end
|
28
25
|
|
29
|
-
# Javascript pagination for bulma: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
30
26
|
def pagy_bulma_nav_js(pagy, id=pagy_id)
|
31
|
-
link
|
32
|
-
tags = { 'before' => (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
+ '<ul class="pagination-list">' ),
|
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
|
+
link = pagy_link_proc(pagy)
|
28
|
+
tags = { 'before' => %(#{pagy_bulma_prev_next_html(pagy, link)}<ul class="pagination-list">),
|
29
|
+
'link' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}")}</li>),
|
30
|
+
'active' => %(<li>#{link.call PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}")}</li>),
|
31
|
+
'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap' }</span></li>),
|
40
32
|
'after' => '</ul>' }
|
41
|
-
|
33
|
+
|
34
|
+
html = %(<nav id="#{id}" class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>)
|
35
|
+
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
42
36
|
end
|
43
37
|
|
44
38
|
# Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
45
39
|
def pagy_bulma_combo_nav_js(pagy, id=pagy_id)
|
46
|
-
link
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
40
|
+
link = pagy_link_proc(pagy)
|
41
|
+
p_page = pagy.page
|
42
|
+
p_pages = pagy.pages
|
43
|
+
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;">)
|
44
|
+
|
45
|
+
%(<nav id="#{id}" class="pagy-bulma-combo-nav-js" role="navigation" aria-label="pagination"><div class="field is-grouped is-grouped-centered" role="group">#{
|
46
|
+
if (p_prev = pagy.prev)
|
47
|
+
%(<p class="control">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"'}</p>)
|
48
|
+
else
|
49
|
+
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.prev'}</a></p>)
|
50
|
+
end
|
51
|
+
}<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>#{
|
52
|
+
if (p_next = pagy.next)
|
53
|
+
%(<p class="control">#{link.call p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"'}</p>)
|
54
|
+
else
|
55
|
+
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.next'}</a></p>)
|
56
|
+
end
|
57
|
+
}</div></nav>#{
|
58
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
59
|
+
})
|
57
60
|
end
|
58
61
|
|
62
|
+
private
|
63
|
+
|
64
|
+
def pagy_bulma_prev_next_html(pagy, link)
|
65
|
+
html = if (p_prev = pagy.prev)
|
66
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"'
|
67
|
+
else
|
68
|
+
%(<a class="pagination-previous" disabled>#{pagy_t 'pagy.nav.prev'}</a>)
|
69
|
+
end
|
70
|
+
html << if (p_next = pagy.next)
|
71
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"'
|
72
|
+
else
|
73
|
+
%(<a class="pagination-next" disabled>#{pagy_t 'pagy.nav.next' }</a>)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
59
77
|
end
|
60
78
|
end
|
@@ -1,20 +1,17 @@
|
|
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
|
@@ -29,7 +26,8 @@ class Pagy
|
|
29
26
|
items = collection.offset(pagy.offset).limit(pagy.items + 1).to_a
|
30
27
|
items_size = items.size
|
31
28
|
items.pop if items_size == pagy.items + 1
|
32
|
-
|
29
|
+
# finalize may adjust pagy.items, so must be used after checking the size
|
30
|
+
pagy.finalize(items_size)
|
33
31
|
items
|
34
32
|
end
|
35
33
|
|
@@ -1,13 +1,21 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
|
-
require 'pagy/extras/pagy_search'
|
6
|
-
|
7
4
|
class Pagy
|
8
5
|
|
9
|
-
|
10
|
-
|
6
|
+
VARS[:elasticsearch_rails_search_method] ||= :pagy_search
|
7
|
+
|
8
|
+
module ElasticsearchRails
|
9
|
+
# returns an array used to delay the call of #search
|
10
|
+
# after the pagination variables are merged to the options
|
11
|
+
# it also pushes to the same array an eventually called method
|
12
|
+
def pagy_elasticsearch_rails(query_or_payload, **options)
|
13
|
+
[self, query_or_payload, options].tap do |args|
|
14
|
+
args.define_singleton_method(:method_missing){|*a| args += a}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
alias_method VARS[:elasticsearch_rails_search_method], :pagy_elasticsearch_rails
|
18
|
+
end
|
11
19
|
|
12
20
|
# create a Pagy object from an Elasticsearch::Model::Response::Response object
|
13
21
|
def self.new_from_elasticsearch_rails(response, vars={})
|
@@ -19,23 +27,25 @@ class Pagy
|
|
19
27
|
end
|
20
28
|
|
21
29
|
# Add specialized backend methods to paginate ElasticsearchRails searches
|
22
|
-
module Backend
|
30
|
+
module Backend
|
31
|
+
private
|
23
32
|
|
24
33
|
# Return Pagy object and items
|
25
34
|
def pagy_elasticsearch_rails(pagy_search_args, vars={})
|
26
|
-
model,
|
27
|
-
vars
|
28
|
-
|
29
|
-
|
30
|
-
response
|
31
|
-
total
|
32
|
-
vars[:count]
|
35
|
+
model, query_or_payload, options, *called = pagy_search_args
|
36
|
+
vars = pagy_elasticsearch_rails_get_vars(nil, vars)
|
37
|
+
options[:size] = vars[:items]
|
38
|
+
options[:from] = vars[:items] * (vars[:page] - 1)
|
39
|
+
response = model.search(query_or_payload, **options)
|
40
|
+
total = response.respond_to?(:raw_response) ? response.raw_response['hits']['total'] : response.response['hits']['total']
|
41
|
+
vars[:count] = total.is_a?(Hash) ? total['value'] : total
|
42
|
+
|
33
43
|
pagy = Pagy.new(vars)
|
34
44
|
# with :last_page overflow we need to re-run the method in order to get the hits
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
45
|
+
return pagy_elasticsearch_rails(pagy_search_args, vars.merge(page: pagy.page)) \
|
46
|
+
if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
|
47
|
+
|
48
|
+
[ pagy, called.empty? ? response : response.send(*called) ]
|
39
49
|
end
|
40
50
|
|
41
51
|
# Sub-method called only by #pagy_elasticsearch_rails: here for easy customization of variables by overriding
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -9,49 +8,75 @@ class Pagy
|
|
9
8
|
|
10
9
|
# Pagination for Foundation: it returns the html with the series of links to the pages
|
11
10
|
def pagy_foundation_nav(pagy)
|
12
|
-
link
|
11
|
+
link = pagy_link_proc(pagy)
|
13
12
|
|
14
|
-
html =
|
15
|
-
|
13
|
+
html = +%(<nav class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">)
|
14
|
+
html << pagy_foundation_prev_html(pagy, link)
|
16
15
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
-
html <<
|
18
|
-
|
19
|
-
|
16
|
+
html << case item
|
17
|
+
when Integer then %(<li>#{link.call item}</li>) # page link
|
18
|
+
when String then %(<li class="current">#{item}</li>) # active page
|
19
|
+
when :gap then %(<li class="ellipsis gap" aria-hidden="true"></li>) # page gap
|
20
20
|
end
|
21
21
|
end
|
22
|
-
html << (
|
23
|
-
|
24
|
-
%(<nav class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
|
22
|
+
html << pagy_foundation_next_html(pagy, link)
|
23
|
+
html << %(</ul></nav>)
|
25
24
|
end
|
26
25
|
|
27
26
|
# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
28
27
|
def pagy_foundation_nav_js(pagy, id=pagy_id)
|
29
|
-
link
|
30
|
-
tags = { 'before' => (
|
31
|
-
|
32
|
-
: %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>)) ),
|
33
|
-
'link' => %(<li>#{link.call(PAGE_PLACEHOLDER)}</li>),
|
28
|
+
link = pagy_link_proc(pagy)
|
29
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
|
30
|
+
'link' => %(<li>#{link.call PAGE_PLACEHOLDER}</li>),
|
34
31
|
'active' => %(<li class="current">#{pagy.page}</li>),
|
35
32
|
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
|
36
|
-
'after' =>
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
|
34
|
+
|
35
|
+
html = %(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>)
|
36
|
+
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
40
37
|
end
|
41
38
|
|
42
39
|
# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
43
40
|
def pagy_foundation_combo_nav_js(pagy, id=pagy_id)
|
44
|
-
link
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
link = pagy_link_proc(pagy)
|
42
|
+
p_page = pagy.page
|
43
|
+
p_pages = pagy.pages
|
44
|
+
input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1}rem; padding: 0 0.3rem; margin: 0 0.3rem;">)
|
45
|
+
|
46
|
+
%(<nav id="#{id}" class="pagy-foundation-combo-nav-js" role="navigation" aria-label="Pagination"><div class="input-group">#{
|
47
|
+
if (p_prev = pagy.prev)
|
48
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"'
|
49
|
+
else
|
50
|
+
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
|
51
|
+
end
|
52
|
+
}<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
|
53
|
+
if (p_next = pagy.next)
|
54
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"'
|
55
|
+
else
|
56
|
+
%(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t 'pagy.nav.next'}</a>)
|
57
|
+
end
|
58
|
+
}</div></nav>#{
|
59
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
60
|
+
})
|
54
61
|
end
|
55
62
|
|
63
|
+
private
|
64
|
+
|
65
|
+
def pagy_foundation_prev_html(pagy, link)
|
66
|
+
if (p_prev = pagy.prev)
|
67
|
+
%(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
68
|
+
else
|
69
|
+
%(<li class="prev disabled">#{pagy_t 'pagy.nav.prev' }</li>)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def pagy_foundation_next_html(pagy, link)
|
74
|
+
if (p_next = pagy.next)
|
75
|
+
%(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
76
|
+
else
|
77
|
+
%(<li class="next disabled">#{pagy_t 'pagy.nav.next'}</li>)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
56
81
|
end
|
57
82
|
end
|