pagy 4.2.0 → 4.6.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 +30 -23
- data/lib/javascripts/pagy.js +104 -93
- 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/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 +27 -21
- data/lib/pagy/backend.rb +1 -0
- data/lib/pagy/console.rb +21 -0
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/extras/arel.rb +1 -0
- data/lib/pagy/extras/array.rb +1 -0
- data/lib/pagy/extras/bootstrap.rb +16 -11
- data/lib/pagy/extras/bulma.rb +18 -13
- data/lib/pagy/extras/countless.rb +2 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +1 -0
- data/lib/pagy/extras/foundation.rb +24 -17
- data/lib/pagy/extras/headers.rb +3 -3
- data/lib/pagy/extras/items.rb +18 -32
- data/lib/pagy/extras/materialize.rb +25 -19
- data/lib/pagy/extras/metadata.rb +3 -2
- data/lib/pagy/extras/navs.rb +18 -14
- data/lib/pagy/extras/overflow.rb +2 -2
- data/lib/pagy/extras/searchkick.rb +1 -0
- data/lib/pagy/extras/semantic.rb +24 -19
- data/lib/pagy/extras/shared.rb +4 -9
- data/lib/pagy/extras/standalone.rb +58 -0
- data/lib/pagy/extras/support.rb +12 -8
- data/lib/pagy/extras/trim.rb +8 -7
- data/lib/pagy/extras/uikit.rb +24 -19
- data/lib/pagy/frontend.rb +34 -25
- metadata +6 -5
- data/lib/locales/README.md +0 -35
- data/pagy.gemspec +0 -16
@@ -16,7 +16,8 @@ class Pagy
|
|
16
16
|
|
17
17
|
# Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
|
18
18
|
def pagy_countless_get_vars(_collection, vars)
|
19
|
-
vars
|
19
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
20
|
+
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
20
21
|
vars
|
21
22
|
end
|
22
23
|
|
@@ -51,6 +51,7 @@ class Pagy
|
|
51
51
|
# Sub-method called only by #pagy_elasticsearch_rails: here for easy customization of variables by overriding
|
52
52
|
# the _collection argument is not available when the method is called
|
53
53
|
def pagy_elasticsearch_rails_get_vars(_collection, vars)
|
54
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
54
55
|
vars[:items] ||= VARS[:items]
|
55
56
|
vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
|
56
57
|
vars
|
@@ -7,10 +7,11 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for Foundation: it returns the html with the series of links to the pages
|
10
|
-
def pagy_foundation_nav(pagy)
|
11
|
-
|
10
|
+
def pagy_foundation_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)
|
12
13
|
|
13
|
-
html = +%(<nav class="pagy-foundation-nav"
|
14
|
+
html = +%(<nav#{p_id} class="pagy-foundation-nav" aria-label="Pagination"><ul class="pagination">)
|
14
15
|
html << pagy_foundation_prev_html(pagy, link)
|
15
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
17
|
html << case item
|
@@ -24,38 +25,44 @@ class Pagy
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
|
-
def pagy_foundation_nav_js(pagy,
|
28
|
-
|
29
|
-
|
28
|
+
def pagy_foundation_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: link_extra)
|
32
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
|
30
33
|
'link' => %(<li>#{link.call PAGE_PLACEHOLDER}</li>),
|
31
34
|
'active' => %(<li class="current">#{pagy.page}</li>),
|
32
35
|
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
|
33
|
-
'after' => %(#{pagy_foundation_next_html
|
36
|
+
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
|
34
37
|
|
35
|
-
html = %(<nav
|
36
|
-
html << pagy_json_tag(pagy, :nav,
|
38
|
+
html = %(<nav#{p_id} class="pagy-njs pagy-foundation-nav-js" aria-label="Pagination"></nav>)
|
39
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
37
40
|
end
|
38
41
|
|
39
42
|
# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
40
|
-
def pagy_foundation_combo_nav_js(pagy,
|
41
|
-
|
43
|
+
def pagy_foundation_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
44
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
45
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
46
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
42
47
|
p_page = pagy.page
|
43
48
|
p_pages = pagy.pages
|
44
49
|
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
50
|
|
46
|
-
%(<nav
|
51
|
+
%(<nav#{p_id} class="pagy-foundation-combo-nav-js" aria-label="Pagination"><div class="input-group">#{
|
47
52
|
if (p_prev = pagy.prev)
|
48
|
-
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom:
|
53
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0" aria-label="previous" class="prev button primary"'
|
49
54
|
else
|
50
|
-
%(<a style="margin-bottom:
|
55
|
+
%(<a style="margin-bottom: 0" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
|
51
56
|
end
|
52
57
|
}<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
|
53
58
|
if (p_next = pagy.next)
|
54
|
-
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom:
|
59
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0" aria-label="next" class="next button primary"'
|
55
60
|
else
|
56
|
-
%(<a style="margin-bottom:
|
61
|
+
%(<a style="margin-bottom: 0" class="next button primary disabled" href="#">#{pagy_t 'pagy.nav.next'}</a>)
|
57
62
|
end
|
58
|
-
}</div></nav>#{
|
63
|
+
}</div></nav>#{
|
64
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
65
|
+
})
|
59
66
|
end
|
60
67
|
|
61
68
|
private
|
data/lib/pagy/extras/headers.rb
CHANGED
@@ -24,11 +24,11 @@ class Pagy
|
|
24
24
|
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
|
25
25
|
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
|
26
26
|
rels['last'] = pagy.last unless countless
|
27
|
-
url_str = pagy_url_for(
|
28
|
-
hash = { 'Link' => rels.
|
27
|
+
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
|
28
|
+
hash = { 'Link' => rels.filter_map do |rel, num|
|
29
29
|
next unless num
|
30
30
|
[ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
|
31
|
-
end.
|
31
|
+
end.to_h }
|
32
32
|
headers = pagy.vars[:headers]
|
33
33
|
hash[headers[:page]] = pagy.page.to_s if headers[:page]
|
34
34
|
hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -9,57 +9,43 @@ class Pagy
|
|
9
9
|
VARS[:items_param] = :items
|
10
10
|
VARS[:max_items] = 100
|
11
11
|
|
12
|
+
VARS[:enable_items_extra] = true
|
13
|
+
|
12
14
|
ITEMS_PLACEHOLDER = '__pagy_items__'
|
13
15
|
|
14
|
-
module UseItemsExtra
|
15
|
-
private
|
16
|
+
module UseItemsExtra; end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
pagy_elasticsearch_rails_get_vars
|
20
|
-
pagy_searchkick_get_vars
|
21
|
-
].each do |meth|
|
22
|
-
next unless Backend.private_method_defined?(meth, true)
|
18
|
+
module Backend
|
19
|
+
private
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
def pagy_set_items_from_params(vars)
|
22
|
+
return if vars[:items]
|
23
|
+
return unless vars.key?(:enable_item_extra) ? vars[:enable_item_extra] : VARS[:enable_items_extra]
|
24
|
+
return unless (items = params[vars[:items_param] || VARS[:items_param]]) # :items from :items_param
|
25
|
+
vars[:items] = [items.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items
|
29
26
|
end
|
30
|
-
end
|
31
27
|
|
32
28
|
end
|
33
|
-
Backend.prepend UseItemsExtra
|
34
|
-
|
35
29
|
|
36
30
|
module Frontend
|
37
31
|
|
38
|
-
module UseItemsExtra
|
39
|
-
def pagy_url_for(page, pagy, url=nil)
|
40
|
-
p_vars = pagy.vars
|
41
|
-
params = request.GET.merge(p_vars[:params])
|
42
|
-
params[p_vars[:page_param].to_s] = page
|
43
|
-
params[p_vars[:items_param].to_s] = p_vars[:items]
|
44
|
-
"#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
prepend UseItemsExtra
|
48
|
-
|
49
32
|
# Return the items selector HTML. For example "Show [20] items per page"
|
50
|
-
def pagy_items_selector_js(pagy,
|
33
|
+
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil, link_extra: '')
|
34
|
+
return '' unless pagy.vars[:enable_items_extra]
|
35
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
36
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
51
37
|
p_vars = pagy.vars
|
52
38
|
p_items = p_vars[:items]
|
53
39
|
p_vars[:items] = ITEMS_PLACEHOLDER
|
54
|
-
link = pagy_marked_link(pagy_link_proc(pagy))
|
40
|
+
link = pagy_marked_link(pagy_link_proc(pagy, link_extra: link_extra))
|
55
41
|
p_vars[:items] = p_items # restore the items
|
56
42
|
|
57
|
-
html = %(<span
|
43
|
+
html = %(<span#{p_id} class="pagy-items-selector-js">)
|
58
44
|
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;">)
|
59
|
-
html << pagy_t('pagy.items_selector_js', item_name: pagy_t(p_vars[:i18n_key], count: p_items),
|
45
|
+
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
|
60
46
|
items_input: input,
|
61
47
|
count: p_items)
|
62
|
-
html << %(</span>#{pagy_json_tag
|
48
|
+
html << %(</span>#{pagy_json_tag pagy, :items_selector, pagy.from, link})
|
63
49
|
end
|
64
50
|
|
65
51
|
end
|
@@ -7,16 +7,17 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
10
|
-
def pagy_materialize_nav(pagy)
|
11
|
-
|
10
|
+
def pagy_materialize_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)
|
12
13
|
|
13
|
-
html = +%(<div class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
|
+
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
|
14
15
|
html << pagy_materialize_prev_html(pagy, link)
|
15
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
17
|
html << case item
|
17
18
|
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
18
19
|
when String then %(<li class="active">#{link.call item}</li>) # active page
|
19
|
-
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t
|
20
|
+
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
|
20
21
|
end
|
21
22
|
end
|
22
23
|
html << pagy_materialize_next_html(pagy, link)
|
@@ -24,34 +25,39 @@ class Pagy
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
|
-
def pagy_materialize_nav_js(pagy,
|
28
|
-
|
29
|
-
|
28
|
+
def pagy_materialize_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: link_extra)
|
32
|
+
|
33
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}),
|
30
34
|
'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
31
35
|
'active' => %(<li class="active">#{mark}</li>),
|
32
|
-
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t
|
33
|
-
'after' => %(#{pagy_materialize_next_html
|
36
|
+
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
37
|
+
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }
|
34
38
|
|
35
|
-
html = %(<div
|
36
|
-
html << pagy_json_tag(pagy, :nav,
|
39
|
+
html = %(<div#{p_id} class="pagy-njs pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
|
40
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
37
41
|
end
|
38
42
|
|
39
43
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
40
|
-
def pagy_materialize_combo_nav_js(pagy,
|
41
|
-
|
44
|
+
def pagy_materialize_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
45
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
46
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
47
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
42
48
|
p_page = pagy.page
|
43
49
|
p_pages = pagy.pages
|
44
50
|
style = ' style="vertical-align: middle;"'
|
45
51
|
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
52
|
|
47
|
-
%(<div
|
48
|
-
pagy_materialize_prev_html
|
53
|
+
%(<div#{p_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: 0">#{
|
54
|
+
pagy_materialize_prev_html pagy, link, style
|
49
55
|
}<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{
|
50
|
-
pagy_t
|
56
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
51
57
|
}</div>#{
|
52
|
-
pagy_materialize_next_html
|
58
|
+
pagy_materialize_next_html pagy, link, style
|
53
59
|
}</ul></div>#{
|
54
|
-
pagy_json_tag
|
60
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
55
61
|
})
|
56
62
|
end
|
57
63
|
|
@@ -61,7 +67,7 @@ class Pagy
|
|
61
67
|
if (p_prev = pagy.prev)
|
62
68
|
%(<li class="waves-effect prev"#{style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
63
69
|
else
|
64
|
-
|
70
|
+
%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
data/lib/pagy/extras/metadata.rb
CHANGED
@@ -16,13 +16,14 @@ class Pagy
|
|
16
16
|
|
17
17
|
include Helpers
|
18
18
|
|
19
|
-
def pagy_metadata(pagy,
|
19
|
+
def pagy_metadata(pagy, deprecated_url=nil, absolute: nil)
|
20
|
+
absolute = Pagy.deprecated_arg(:url, deprecated_url, :absolute, absolute) if deprecated_url
|
20
21
|
names = pagy.vars[:metadata]
|
21
22
|
unknown = names - METADATA
|
22
23
|
raise VariableError.new(pagy), "unknown metadata #{unknown.inspect}" \
|
23
24
|
unless unknown.empty?
|
24
25
|
|
25
|
-
scaffold_url = pagy_url_for(
|
26
|
+
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: absolute)
|
26
27
|
{}.tap do |metadata|
|
27
28
|
names.each do |key|
|
28
29
|
metadata[key] = case key
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -7,33 +7,37 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
10
|
-
def pagy_nav_js(pagy,
|
11
|
-
|
10
|
+
def pagy_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
11
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
12
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
13
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
12
14
|
tags = { 'before' => pagy_nav_prev_html(pagy, link),
|
13
15
|
'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
|
14
16
|
'active' => %(<span class="page active">#{pagy.page}</span> ),
|
15
|
-
'gap' => %(<span class="page gap">#{pagy_t
|
17
|
+
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
|
16
18
|
'after' => pagy_nav_next_html(pagy, link) }
|
17
19
|
|
18
|
-
html = %(<nav
|
19
|
-
html << pagy_json_tag(pagy, :nav,
|
20
|
+
html = %(<nav#{p_id} class="pagy-njs pagy-nav-js pagination" aria-label="pager"></nav>)
|
21
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
20
22
|
end
|
21
23
|
|
22
24
|
# Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
23
|
-
def pagy_combo_nav_js(pagy,
|
24
|
-
|
25
|
+
def pagy_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
26
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
27
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
28
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
25
29
|
p_page = pagy.page
|
26
30
|
p_pages = pagy.pages
|
27
31
|
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
32
|
|
29
|
-
%(<nav
|
30
|
-
pagy_nav_prev_html
|
33
|
+
%(<nav#{p_id} class="pagy-combo-nav-js pagination" aria-label="pager">#{
|
34
|
+
pagy_nav_prev_html pagy, link
|
31
35
|
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
|
32
|
-
pagy_t
|
36
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
33
37
|
}</span> #{
|
34
|
-
pagy_nav_next_html
|
38
|
+
pagy_nav_next_html pagy, link
|
35
39
|
}</nav>#{
|
36
|
-
pagy_json_tag
|
40
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
37
41
|
})
|
38
42
|
end
|
39
43
|
|
@@ -43,7 +47,7 @@ class Pagy
|
|
43
47
|
if (p_prev = pagy.prev)
|
44
48
|
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
45
49
|
else
|
46
|
-
%(<span class="page prev disabled">#{pagy_t
|
50
|
+
%(<span class="page prev disabled">#{pagy_t 'pagy.nav.prev'}</span> )
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
@@ -51,7 +55,7 @@ class Pagy
|
|
51
55
|
if (p_next = pagy.next)
|
52
56
|
%(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
53
57
|
else
|
54
|
-
%(<span class="page next disabled">#{pagy_t
|
58
|
+
%(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -18,12 +18,12 @@ class Pagy
|
|
18
18
|
raise # same as without the extra
|
19
19
|
when :last_page
|
20
20
|
initial_page = @vars[:page] # save the very initial page (even after re-run)
|
21
|
-
initialize
|
21
|
+
initialize vars.merge!(page: @last) # re-run with the last page
|
22
22
|
@vars[:page] = initial_page # restore the inital page
|
23
23
|
when :empty_page
|
24
24
|
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
25
25
|
@prev = @last # prev relative to the actual page
|
26
|
-
extend
|
26
|
+
extend Series # special series for :empty_page
|
27
27
|
else
|
28
28
|
raise VariableError.new(self), "expected :overflow variable in [:last_page, :empty_page, :exception]; got #{@vars[:overflow].inspect}"
|
29
29
|
end
|
@@ -49,6 +49,7 @@ class Pagy
|
|
49
49
|
# Sub-method called only by #pagy_searchkick: here for easy customization of variables by overriding
|
50
50
|
# the _collection argument is not available when the method is called
|
51
51
|
def pagy_searchkick_get_vars(_collection, vars)
|
52
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
52
53
|
vars[:items] ||= VARS[:items]
|
53
54
|
vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
|
54
55
|
vars
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -7,16 +7,17 @@ class Pagy
|
|
7
7
|
module Frontend
|
8
8
|
|
9
9
|
# Pagination for semantic: it returns the html with the series of links to the pages
|
10
|
-
def pagy_semantic_nav(pagy)
|
11
|
-
|
10
|
+
def pagy_semantic_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="item" #{link_extra}))
|
12
13
|
|
13
|
-
html = +%(<div class="pagy-semantic-nav ui pagination menu"
|
14
|
+
html = +%(<div#{p_id} class="pagy-semantic-nav ui pagination menu">)
|
14
15
|
html << pagy_semantic_prev_html(pagy, link)
|
15
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
17
|
html << case item
|
17
|
-
when Integer then link.call item
|
18
|
-
when String then %(<a class="item active">#{item}</a>)
|
19
|
-
when :gap then %(<div class="disabled item"
|
18
|
+
when Integer then link.call item # page link
|
19
|
+
when String then %(<a class="item active">#{item}</a>) # current page
|
20
|
+
when :gap then %(<div class="disabled item">#{pagy_t 'pagy.nav.gap'}</div>) # page gap
|
20
21
|
end
|
21
22
|
end
|
22
23
|
html << pagy_semantic_next_html(pagy, link)
|
@@ -24,33 +25,37 @@ class Pagy
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
|
-
def pagy_semantic_nav_js(pagy,
|
28
|
-
|
28
|
+
def pagy_semantic_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="item" #{link_extra}))
|
29
32
|
tags = { 'before' => pagy_semantic_prev_html(pagy, link),
|
30
33
|
'link' => link.call(PAGE_PLACEHOLDER),
|
31
34
|
'active' => %(<a class="item active">#{pagy.page}</a>),
|
32
35
|
'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
|
33
36
|
'after' => pagy_semantic_next_html(pagy, link) }
|
34
37
|
|
35
|
-
html = %(<div
|
36
|
-
html << pagy_json_tag(pagy, :nav,
|
38
|
+
html = %(<div#{p_id} class="pagy-njs pagy-semantic-nav-js ui pagination menu" role="navigation"></div>)
|
39
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
37
40
|
end
|
38
41
|
|
39
42
|
# Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
40
|
-
def pagy_semantic_combo_nav_js(pagy,
|
41
|
-
|
43
|
+
def pagy_semantic_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
44
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
45
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
46
|
+
link = pagy_link_proc(pagy, link_extra: %(class="item" #{link_extra}))
|
42
47
|
p_page = pagy.page
|
43
48
|
p_pages = pagy.pages
|
44
49
|
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; margin: 0 0.3rem">)
|
45
50
|
|
46
|
-
%(<div
|
47
|
-
pagy_semantic_prev_html
|
51
|
+
%(<div#{p_id} class="pagy-semantic-combo-nav-js ui compact menu" role="navigation">#{
|
52
|
+
pagy_semantic_prev_html pagy, link
|
48
53
|
}<div class="pagy-combo-input item">#{
|
49
|
-
pagy_t
|
54
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
50
55
|
}</div> #{
|
51
|
-
pagy_semantic_next_html
|
56
|
+
pagy_semantic_next_html pagy, link
|
52
57
|
}</div>#{
|
53
|
-
pagy_json_tag
|
58
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
54
59
|
})
|
55
60
|
end
|
56
61
|
|
@@ -60,7 +65,7 @@ class Pagy
|
|
60
65
|
if (p_prev = pagy.prev)
|
61
66
|
link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'
|
62
67
|
else
|
63
|
-
|
68
|
+
+%(<div class="item disabled"><i class="left small chevron icon"></i></div>)
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
@@ -68,7 +73,7 @@ class Pagy
|
|
68
73
|
if (p_next = pagy.next)
|
69
74
|
link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'
|
70
75
|
else
|
71
|
-
|
76
|
+
+%(<div class="item disabled"><i class="right small chevron icon"></i></div>)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|