pagy 4.2.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 +4 -2
- data/lib/javascripts/pagy.js +1 -1
- data/lib/pagy.rb +23 -19
- data/lib/pagy/extras/bootstrap.rb +1 -1
- data/lib/pagy/extras/bulma.rb +3 -3
- data/lib/pagy/extras/foundation.rb +6 -4
- data/lib/pagy/extras/items.rb +2 -0
- data/lib/pagy/extras/materialize.rb +9 -9
- data/lib/pagy/extras/navs.rb +7 -7
- data/lib/pagy/extras/overflow.rb +2 -2
- data/lib/pagy/extras/semantic.rb +6 -6
- data/lib/pagy/extras/shared.rb +2 -2
- data/lib/pagy/extras/trim.rb +5 -5
- data/lib/pagy/extras/uikit.rb +9 -9
- data/lib/pagy/frontend.rb +8 -10
- metadata +2 -4
- data/lib/locales/README.md +0 -35
- data/pagy.gemspec +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ae2dcfec4f4aefaa0a2531b5abe5e0d18b92a835edf6549251c0073ce2f38f
|
4
|
+
data.tar.gz: 295ca05e50dc171da7c184d7d3e8dd9e3b7eaed1cf7387959471a3f758f6d169
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96430c17d8936a27942e3da7c0fbcff4d80372afd1f99b7a0c12b4ed5eb694aa1921404d31b77889078dc0fc59b4bbc5bfb0e4a6c418f3ae50837436bc17262
|
7
|
+
data.tar.gz: d7349c4e47d8b33cdadea01168d8a122ef36c6283164cf895dbcf197aca0f07c44437abce7e7d72b29d358f4d95b80586157d5bd5eeb4515e32b7001031329b8
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (4.
|
3
|
+
# Pagy initializer file (4.3.0)
|
4
4
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
5
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
6
|
|
@@ -104,7 +104,9 @@
|
|
104
104
|
# Trim extra: Remove the page=1 param from links
|
105
105
|
# See https://ddnexus.github.io/pagy/extras/trim
|
106
106
|
# require 'pagy/extras/trim'
|
107
|
-
|
107
|
+
# after requiring it will trim by default
|
108
|
+
# set to false if you want to make :trim an opt-in variable
|
109
|
+
# Pagy::VARS[:trim] = true # default
|
108
110
|
|
109
111
|
|
110
112
|
# Pagy Variables
|
data/lib/javascripts/pagy.js
CHANGED
data/lib/pagy.rb
CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# main class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '4.
|
8
|
+
VERSION = '4.3.0'
|
9
9
|
|
10
10
|
# Root pathname to get the path of Pagy files like templates or dictionaries
|
11
11
|
def self.root
|
@@ -29,13 +29,14 @@ class Pagy
|
|
29
29
|
unless @vars[name] && instance_variable_set(:"@#{name}", @vars[name].to_i) >= min
|
30
30
|
end
|
31
31
|
@pages = @last = [(@count.to_f / @items).ceil, 1].max
|
32
|
-
raise OverflowError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}"
|
32
|
+
raise OverflowError.new(self), "expected :page in 1..#{@last}; got #{@page.inspect}" \
|
33
|
+
if @page > @last
|
33
34
|
|
34
35
|
@offset = @items * (@page - 1) + @outset
|
35
|
-
@items = @count - ((@pages-1) * @items) if @page == @last && @count.positive?
|
36
|
+
@items = @count - ((@pages - 1) * @items) if @page == @last && @count.positive?
|
36
37
|
@from = @count.zero? ? 0 : @offset + 1 - @outset
|
37
38
|
@to = @count.zero? ? 0 : @offset + @items - @outset
|
38
|
-
@prev = (@page-1 unless @page == 1)
|
39
|
+
@prev = (@page - 1 unless @page == 1)
|
39
40
|
@next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
|
40
41
|
end
|
41
42
|
|
@@ -43,23 +44,26 @@ class Pagy
|
|
43
44
|
def series(size=@vars[:size])
|
44
45
|
return [] if size.empty?
|
45
46
|
raise VariableError.new(self), "expected 4 items >= 0 in :size; got #{size.inspect}" \
|
46
|
-
unless size.size == 4 && size.all?{ |num| num
|
47
|
-
|
47
|
+
unless size.size == 4 && size.all?{ |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
|
48
|
+
# This algorithm is up to ~5x faster and ~2.3x lighter than the previous one (pagy < 4.3)
|
49
|
+
left_gap_start = 1 + size[0]
|
50
|
+
left_gap_end = @page - size[1] - 1
|
51
|
+
right_gap_start = @page + size[2] + 1
|
52
|
+
right_gap_end = @last - size[3]
|
53
|
+
left_gap_end = right_gap_end if left_gap_end > right_gap_end
|
54
|
+
right_gap_start = left_gap_start if left_gap_start > right_gap_start
|
48
55
|
series = []
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
when left+2 then series.push(left, left+1) # 1 page gap -> fill with missing page
|
58
|
-
else series.push(left, :gap) # n page gap -> add gap
|
59
|
-
end
|
56
|
+
start = 1
|
57
|
+
if (left_gap_end - left_gap_start).positive?
|
58
|
+
series.push(*start..(left_gap_start - 1), :gap)
|
59
|
+
start = left_gap_end + 1
|
60
|
+
end
|
61
|
+
if (right_gap_end - right_gap_start).positive?
|
62
|
+
series.push(*start..(right_gap_start - 1), :gap)
|
63
|
+
start = right_gap_end + 1
|
60
64
|
end
|
61
|
-
series.
|
62
|
-
series[series.index(@page)] = @page.to_s
|
65
|
+
series.push(*start..@last)
|
66
|
+
series[series.index(@page)] = @page.to_s
|
63
67
|
series
|
64
68
|
end
|
65
69
|
|
@@ -56,7 +56,7 @@ class Pagy
|
|
56
56
|
%(<a class="next btn btn-primary disabled" href="#">#{pagy_t 'pagy.nav.next' }</a>)
|
57
57
|
end
|
58
58
|
}</div></nav>#{
|
59
|
-
pagy_json_tag
|
59
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
60
60
|
})
|
61
61
|
end
|
62
62
|
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -17,7 +17,7 @@ class Pagy
|
|
17
17
|
html << case item
|
18
18
|
when Integer then %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}") }</li>) # page link
|
19
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
|
20
|
+
when :gap then %(<li><span class="pagination-ellipsis">#{pagy_t 'pagy.nav.gap'}</span></li>) # page gap
|
21
21
|
end
|
22
22
|
end
|
23
23
|
html << %(</ul></nav>)
|
@@ -48,14 +48,14 @@ class Pagy
|
|
48
48
|
else
|
49
49
|
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.prev'}</a></p>)
|
50
50
|
end
|
51
|
-
}<div class="pagy-combo-input control level is-mobile">#{pagy_t
|
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
52
|
if (p_next = pagy.next)
|
53
53
|
%(<p class="control">#{link.call p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"'}</p>)
|
54
54
|
else
|
55
55
|
%(<p class="control"><a class="button" disabled>#{pagy_t 'pagy.nav.next'}</a></p>)
|
56
56
|
end
|
57
57
|
}</div></nav>#{
|
58
|
-
pagy_json_tag
|
58
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
59
59
|
})
|
60
60
|
end
|
61
61
|
|
@@ -26,11 +26,11 @@ class Pagy
|
|
26
26
|
# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
27
|
def pagy_foundation_nav_js(pagy, id=pagy_id)
|
28
28
|
link = pagy_link_proc(pagy)
|
29
|
-
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html
|
29
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
|
30
30
|
'link' => %(<li>#{link.call PAGE_PLACEHOLDER}</li>),
|
31
31
|
'active' => %(<li class="current">#{pagy.page}</li>),
|
32
32
|
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
|
33
|
-
'after' => %(#{pagy_foundation_next_html
|
33
|
+
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
|
34
34
|
|
35
35
|
html = %(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>)
|
36
36
|
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
@@ -47,7 +47,7 @@ class Pagy
|
|
47
47
|
if (p_prev = pagy.prev)
|
48
48
|
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"'
|
49
49
|
else
|
50
|
-
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t
|
50
|
+
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
|
51
51
|
end
|
52
52
|
}<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
|
53
53
|
if (p_next = pagy.next)
|
@@ -55,7 +55,9 @@ class Pagy
|
|
55
55
|
else
|
56
56
|
%(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t 'pagy.nav.next'}</a>)
|
57
57
|
end
|
58
|
-
}</div></nav>#{
|
58
|
+
}</div></nav>#{
|
59
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
60
|
+
})
|
59
61
|
end
|
60
62
|
|
61
63
|
private
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -36,6 +36,7 @@ class Pagy
|
|
36
36
|
module Frontend
|
37
37
|
|
38
38
|
module UseItemsExtra
|
39
|
+
|
39
40
|
def pagy_url_for(page, pagy, url=nil)
|
40
41
|
p_vars = pagy.vars
|
41
42
|
params = request.GET.merge(p_vars[:params])
|
@@ -43,6 +44,7 @@ class Pagy
|
|
43
44
|
params[p_vars[:items_param].to_s] = p_vars[:items]
|
44
45
|
"#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
45
46
|
end
|
47
|
+
|
46
48
|
end
|
47
49
|
prepend UseItemsExtra
|
48
50
|
|
@@ -16,7 +16,7 @@ class Pagy
|
|
16
16
|
html << case item
|
17
17
|
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
18
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
|
19
|
+
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
|
20
20
|
end
|
21
21
|
end
|
22
22
|
html << pagy_materialize_next_html(pagy, link)
|
@@ -26,11 +26,11 @@ class Pagy
|
|
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
28
|
link = pagy_link_proc(pagy)
|
29
|
-
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html
|
29
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}),
|
30
30
|
'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
31
31
|
'active' => %(<li class="active">#{mark}</li>),
|
32
|
-
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t
|
33
|
-
'after' => %(#{pagy_materialize_next_html
|
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
34
|
|
35
35
|
html = %(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
|
36
36
|
html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
|
@@ -45,13 +45,13 @@ class Pagy
|
|
45
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
46
|
|
47
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
|
48
|
+
pagy_materialize_prev_html pagy, link, style
|
49
49
|
}<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{
|
50
|
-
pagy_t
|
50
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
51
51
|
}</div>#{
|
52
|
-
pagy_materialize_next_html
|
52
|
+
pagy_materialize_next_html pagy, link, style
|
53
53
|
}</ul></div>#{
|
54
|
-
pagy_json_tag
|
54
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
55
55
|
})
|
56
56
|
end
|
57
57
|
|
@@ -61,7 +61,7 @@ class Pagy
|
|
61
61
|
if (p_prev = pagy.prev)
|
62
62
|
%(<li class="waves-effect prev"#{style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
63
63
|
else
|
64
|
-
|
64
|
+
%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -12,7 +12,7 @@ class Pagy
|
|
12
12
|
tags = { 'before' => pagy_nav_prev_html(pagy, link),
|
13
13
|
'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
|
14
14
|
'active' => %(<span class="page active">#{pagy.page}</span> ),
|
15
|
-
'gap' => %(<span class="page gap">#{pagy_t
|
15
|
+
'gap' => %(<span class="page gap">#{pagy_t 'pagy.nav.gap'}</span> ),
|
16
16
|
'after' => pagy_nav_next_html(pagy, link) }
|
17
17
|
|
18
18
|
html = %(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>)
|
@@ -27,13 +27,13 @@ class Pagy
|
|
27
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
28
|
|
29
29
|
%(<nav id="#{id}" class="pagy-combo-nav-js pagination" role="navigation" aria-label="pager">#{
|
30
|
-
pagy_nav_prev_html
|
30
|
+
pagy_nav_prev_html pagy, link
|
31
31
|
}<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
|
32
|
-
pagy_t
|
32
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
33
33
|
}</span> #{
|
34
|
-
pagy_nav_next_html
|
34
|
+
pagy_nav_next_html pagy, link
|
35
35
|
}</nav>#{
|
36
|
-
pagy_json_tag
|
36
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
37
37
|
})
|
38
38
|
end
|
39
39
|
|
@@ -43,7 +43,7 @@ class Pagy
|
|
43
43
|
if (p_prev = pagy.prev)
|
44
44
|
%(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
|
45
45
|
else
|
46
|
-
%(<span class="page prev disabled">#{pagy_t
|
46
|
+
%(<span class="page prev disabled">#{pagy_t 'pagy.nav.prev'}</span> )
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ class Pagy
|
|
51
51
|
if (p_next = pagy.next)
|
52
52
|
%(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
|
53
53
|
else
|
54
|
-
%(<span class="page next disabled">#{pagy_t
|
54
|
+
%(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
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
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -44,13 +44,13 @@ class Pagy
|
|
44
44
|
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
45
|
|
46
46
|
%(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">#{
|
47
|
-
pagy_semantic_prev_html
|
47
|
+
pagy_semantic_prev_html pagy, link
|
48
48
|
}<div class="pagy-combo-input item">#{
|
49
|
-
pagy_t
|
49
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
50
50
|
}</div> #{
|
51
|
-
pagy_semantic_next_html
|
51
|
+
pagy_semantic_next_html pagy, link
|
52
52
|
}</div>#{
|
53
|
-
pagy_json_tag
|
53
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
54
54
|
})
|
55
55
|
end
|
56
56
|
|
@@ -60,7 +60,7 @@ class Pagy
|
|
60
60
|
if (p_prev = pagy.prev)
|
61
61
|
link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'
|
62
62
|
else
|
63
|
-
|
63
|
+
+%(<div class="item disabled"><i class="left small chevron icon"></i></div>)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,7 +68,7 @@ class Pagy
|
|
68
68
|
if (p_next = pagy.next)
|
69
69
|
link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'
|
70
70
|
else
|
71
|
-
|
71
|
+
+%(<div class="item disabled"><i class="right small chevron icon"></i></div>)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
data/lib/pagy/extras/shared.rb
CHANGED
@@ -30,14 +30,14 @@ class Pagy
|
|
30
30
|
if defined?(Oj)
|
31
31
|
# it returns a script tag with the JSON-serialized args generated with the faster oj gem
|
32
32
|
def pagy_json_tag(pagy, *args)
|
33
|
-
args <<
|
33
|
+
args << pagy.vars[:page_param] if pagy.vars[:trim]
|
34
34
|
%(<script type="application/json" class="pagy-json">#{Oj.dump(args, mode: :strict)}</script>)
|
35
35
|
end
|
36
36
|
else
|
37
37
|
require 'json'
|
38
38
|
# it returns a script tag with the JSON-serialized args generated with the slower to_json
|
39
39
|
def pagy_json_tag(pagy, *args)
|
40
|
-
args <<
|
40
|
+
args << pagy.vars[:page_param] if pagy.vars[:trim]
|
41
41
|
%(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
|
42
42
|
end
|
43
43
|
end
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -3,17 +3,17 @@
|
|
3
3
|
|
4
4
|
class Pagy
|
5
5
|
|
6
|
+
VARS[:trim] = true
|
7
|
+
|
6
8
|
module UseTrimExtra
|
7
9
|
|
8
10
|
def pagy_link_proc(pagy, link_extra='')
|
9
11
|
link_proc = super(pagy, link_extra)
|
12
|
+
return link_proc unless pagy.vars[:trim]
|
10
13
|
lambda do |num, text=num, extra=''|
|
11
14
|
link = link_proc.call(num, text, extra)
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
link
|
16
|
-
end
|
15
|
+
return link unless num == 1
|
16
|
+
link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -10,12 +10,12 @@ class Pagy
|
|
10
10
|
def pagy_uikit_nav(pagy)
|
11
11
|
link = pagy_link_proc(pagy)
|
12
12
|
|
13
|
-
html = %(<ul class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html
|
13
|
+
html = %(<ul class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
|
14
14
|
pagy.series.each do |item|
|
15
15
|
html << case item
|
16
16
|
when Integer then %(<li>#{link.call item}</li>)
|
17
17
|
when String then %(<li class="uk-active"><span>#{item}</span></li>)
|
18
|
-
when :gap then %(<li class="uk-disabled"><span>#{pagy_t
|
18
|
+
when :gap then %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
html << pagy_uikit_next_html(pagy, link)
|
@@ -46,18 +46,18 @@ class Pagy
|
|
46
46
|
if (p_prev = pagy.prev)
|
47
47
|
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="uk-button uk-button-default"'
|
48
48
|
else
|
49
|
-
%(<button class="uk-button uk-button-default" disabled>#{pagy_t
|
49
|
+
%(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.prev'}</button>)
|
50
50
|
end
|
51
51
|
}<div class="uk-text-middle uk-margin-left uk-margin-right">#{
|
52
|
-
pagy_t
|
52
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
53
53
|
}</div>#{
|
54
54
|
if (p_next = pagy.next)
|
55
|
-
link.call
|
55
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"'
|
56
56
|
else
|
57
|
-
%(<button class="uk-button uk-button-default" disabled>#{pagy_t
|
57
|
+
%(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.next'}</button>)
|
58
58
|
end
|
59
59
|
}</div>#{
|
60
|
-
pagy_json_tag
|
60
|
+
pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
|
61
61
|
})
|
62
62
|
end
|
63
63
|
|
@@ -66,7 +66,7 @@ class Pagy
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def pagy_uikit_prev_html(pagy, link)
|
69
|
-
previous_span = %(<span uk-pagination-previous>#{pagy_t
|
69
|
+
previous_span = %(<span uk-pagination-previous>#{pagy_t 'pagy.nav.prev'}</span>)
|
70
70
|
if (p_prev = pagy.prev)
|
71
71
|
%(<li>#{link.call p_prev, previous_span}</li>)
|
72
72
|
else
|
@@ -75,7 +75,7 @@ class Pagy
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def pagy_uikit_next_html(pagy, link)
|
78
|
-
next_span = %(<span uk-pagination-next>#{pagy_t
|
78
|
+
next_span = %(<span uk-pagination-next>#{pagy_t 'pagy.nav.next'}</span>)
|
79
79
|
if (p_next = pagy.next)
|
80
80
|
%(<li>#{link.call p_next, next_span}</li>)
|
81
81
|
else
|
data/lib/pagy/frontend.rb
CHANGED
@@ -65,9 +65,7 @@ class Pagy
|
|
65
65
|
else 'pagy.info.multiple_pages'
|
66
66
|
end
|
67
67
|
pagy_t key, item_name: item_name || pagy_t(pagy.vars[:i18n_key], count: count),
|
68
|
-
count:
|
69
|
-
from: pagy.from,
|
70
|
-
to: pagy.to
|
68
|
+
count: count, from: pagy.from, to: pagy.to
|
71
69
|
end
|
72
70
|
|
73
71
|
# Returns a performance optimized proc to generate the HTML links
|
@@ -75,18 +73,18 @@ class Pagy
|
|
75
73
|
def pagy_link_proc(pagy, link_extra='')
|
76
74
|
p_prev = pagy.prev
|
77
75
|
p_next = pagy.next
|
78
|
-
left, right = %(<a href="#{pagy_url_for
|
76
|
+
left, right = %(<a href="#{pagy_url_for PAGE_PLACEHOLDER, pagy}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
|
79
77
|
lambda do |num, text=num, extra=''|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
%(#{left}#{num}#{right}#{ case num
|
79
|
+
when p_prev then ' rel="prev"'
|
80
|
+
when p_next then ' rel="next"'
|
81
|
+
else ''
|
82
|
+
end } #{extra}>#{text}</a>)
|
85
83
|
end
|
86
84
|
end
|
87
85
|
|
88
86
|
# Similar to I18n.t: just ~18x faster using ~10x less memory
|
89
|
-
# (@pagy_locale explicitly
|
87
|
+
# (@pagy_locale explicitly initialized in order to avoid warning)
|
90
88
|
def pagy_t(key, **opts)
|
91
89
|
Pagy::I18n.t @pagy_locale||=nil, key, **opts
|
92
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
|
14
14
|
and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
|
@@ -22,7 +22,6 @@ files:
|
|
22
22
|
- LICENSE.txt
|
23
23
|
- lib/config/pagy.rb
|
24
24
|
- lib/javascripts/pagy.js
|
25
|
-
- lib/locales/README.md
|
26
25
|
- lib/locales/bg.yml
|
27
26
|
- lib/locales/bs.yml
|
28
27
|
- lib/locales/ca.yml
|
@@ -95,7 +94,6 @@ files:
|
|
95
94
|
- lib/templates/uikit_nav.html.erb
|
96
95
|
- lib/templates/uikit_nav.html.haml
|
97
96
|
- lib/templates/uikit_nav.html.slim
|
98
|
-
- pagy.gemspec
|
99
97
|
homepage: https://github.com/ddnexus/pagy
|
100
98
|
licenses:
|
101
99
|
- MIT
|
data/lib/locales/README.md
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# Pagy locales
|
2
|
-
|
3
|
-
### Please, submit your translation!
|
4
|
-
|
5
|
-
If you find that some translation could be improved, please, create an issue.
|
6
|
-
|
7
|
-
If you are using pagy with some language missing from the dictionary files, please, submit your translation!
|
8
|
-
|
9
|
-
You can create a Pull Request for your language, and get all the help you need to correctly complete it. Here is a check list.
|
10
|
-
|
11
|
-
### Check list for a new dictionary file:
|
12
|
-
|
13
|
-
- [ ] Find the pluralization rule for your language
|
14
|
-
|
15
|
-
- [ ] Find the locale file you need in the [list of pluralizations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/pluralization) and check the pluralization rule in it. For example it is `::RailsI18n::Pluralization::OneOther.with_locale(:en)` for `en.rb`. Note the rule part i.e. `OneOther`. In pagy that translates to the symbol `:one_other`.
|
16
|
-
|
17
|
-
- [ ] If the pluralization rule of your language is not the `:one_other` default, confirm that the [p11n.rb](https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) file already defines the pluralization rule of your dictionary file:
|
18
|
-
|
19
|
-
- [ ] If the rule is not defined, you can either: a) Add the rule as a new rule/lambda entry in the `p11n` variable hash and relative tests or b) Just create an issue requesting the addition to the rule/lambda entry and tests.
|
20
|
-
|
21
|
-
- [ ] Add your language to the `plurals` hash in the file.
|
22
|
-
|
23
|
-
- [ ] add/edit the first line comment in the language rule in your dictionary file (e.g. `# :one_other pluralization ...`
|
24
|
-
|
25
|
-
- [ ] The mandatory pluralized entry in the dictionary file is the `item_name`. Please, provide all the plurals needed by your language. E.g. if your language uses the `:east_slavic` you should provide the plurals for `one`, `few`, `many` and `other`, if it uses `:one_other`, you should provide `one` and `other` plurals. If it uses `:other` you should only provide a single value. Look into other dictionary files to get some example. Ask if in doubt.
|
26
|
-
|
27
|
-
- [ ] The other entries in the dictionary file don't need any plural variant in most languages since the pluralization of the `item_name` in the sentence is enough. However, in some language, a whole sentence might need to be written in different ways for different counts. In that case you should add the different plurals for the sentence and the `count` will trigger the one that applies.
|
28
|
-
|
29
|
-
Feel free to ask for help in your Pull Request.
|
30
|
-
|
31
|
-
### Useful Links
|
32
|
-
|
33
|
-
* [Pagy I18n Documentation](https://ddnexus.github.io/pagy/api/frontend#i18n)
|
34
|
-
* [I18n Extra](https://ddnexus.github.io/pagy/extras/i18n)
|
35
|
-
|
data/pagy.gemspec
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'pagy'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = 'pagy'
|
7
|
-
s.version = Pagy::VERSION
|
8
|
-
s.authors = ['Domizio Demichelis']
|
9
|
-
s.email = ['dd.nexus@gmail.com']
|
10
|
-
s.summary = 'The Ultimate Pagination Ruby Gem'
|
11
|
-
s.description = 'Agnostic pagination in plain ruby: it works with any framework, ORM and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays, JSON data... Easy, powerful, fast and light.'
|
12
|
-
s.homepage = 'https://github.com/ddnexus/pagy'
|
13
|
-
s.license = 'MIT'
|
14
|
-
s.files = `git ls-files -z`.split("\x0").select{|f| f.start_with?('lib', 'pagy.gemspec', 'LICENSE') }
|
15
|
-
s.required_ruby_version = '>= 3.0'
|
16
|
-
end
|