pagy 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1893ce66c2ad5ccb5e1b55340873135bf1174f6876a7fe9987bf3d7b11c8b93d
4
- data.tar.gz: 15ec7c5615cc40f2fc854f18577632d99f0ec83134f432a2526ca51c1c579a2a
3
+ metadata.gz: 66ae2dcfec4f4aefaa0a2531b5abe5e0d18b92a835edf6549251c0073ce2f38f
4
+ data.tar.gz: 295ca05e50dc171da7c184d7d3e8dd9e3b7eaed1cf7387959471a3f758f6d169
5
5
  SHA512:
6
- metadata.gz: 3b0a30aa314e2abc44dbad8a89352cd640b3ff81979b31436b8911920df344eef2a43cd622ba2921e9ef088a3059611e7e3ccab05f1e07ab7e3bdaefd72ecd58
7
- data.tar.gz: 318953ee34f26d5f89f59417b2b02edda38608ada3946241633513167c1b5c5e209a8b474dfb8c1f028381283ba20cf367b5e2b7e9ad7ad95ca22af86d94730d
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.2.0)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '4.2.0';
5
+ Pagy.version = '4.3.0';
6
6
 
7
7
  Pagy.init = function(arg){
8
8
  var target = arg instanceof Event || arg === undefined ? document : arg,
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # main class
7
7
  class Pagy
8
- VERSION = '4.2.0'
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}" if @page > @last
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 >= 0 rescue false } # rubocop:disable Style/RescueModifier
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
- [ *0..size[0], # initial pages from 0
50
- *@page-size[1]..@page+size[2], # around current page
51
- *@last-size[3]+1..@last+1 # final pages till @last+1
52
- ].sort!.each_cons(2) do |left, right| # sort and loop by 2
53
- next if left.negative? || left == right # skip out of range and duplicates
54
- break if left > @last # break if out of @last boundary
55
- case right
56
- when left+1 then series.push(left) # no gap -> no additions
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.shift # shift the start boundary (0)
62
- series[series.index(@page)] = @page.to_s # convert the current page to String
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(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
59
+ pagy_json_tag pagy, :combo_nav, id, p_page, pagy_marked_link(link)
60
60
  })
61
61
  end
62
62
 
@@ -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('pagy.nav.gap')}</span></li>) # page gap
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('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>#{
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(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
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(pagy, link)}),
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(pagy, link)}</ul>) }
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('pagy.nav.prev')}</a>)
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>#{pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))})
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
@@ -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('pagy.nav.gap')}</a></li>) # page gap
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(pagy, link)}),
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('pagy.nav.gap')}</a></li>),
33
- 'after' => %(#{pagy_materialize_next_html(pagy, link)}</ul>) }
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(pagy, link, style)
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('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
50
+ pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
51
51
  }</div>#{
52
- pagy_materialize_next_html(pagy, link, style)
52
+ pagy_materialize_next_html pagy, link, style
53
53
  }</ul></div>#{
54
- pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
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
- +%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
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
 
@@ -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('pagy.nav.gap')}</span> ),
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(pagy, link)
30
+ pagy_nav_prev_html pagy, link
31
31
  }<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
32
- pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
32
+ pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
33
33
  }</span> #{
34
- pagy_nav_next_html(pagy, link)
34
+ pagy_nav_next_html pagy, link
35
35
  }</nav>#{
36
- pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
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('pagy.nav.prev')}</span> )
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('pagy.nav.next')}</span>)
54
+ %(<span class="page next disabled">#{pagy_t 'pagy.nav.next'}</span>)
55
55
  end
56
56
  end
57
57
 
@@ -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(vars.merge!(page: @last)) # re-run with the last page
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(Series) # special series for :empty_page
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
@@ -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(pagy, link)
47
+ pagy_semantic_prev_html pagy, link
48
48
  }<div class="pagy-combo-input item">#{
49
- pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
49
+ pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
50
50
  }</div> #{
51
- pagy_semantic_next_html(pagy, link)
51
+ pagy_semantic_next_html pagy, link
52
52
  }</div>#{
53
- pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
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
- %(<div class="item disabled"><i class="left small chevron icon"></i></div>)
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
- %(<div class="item disabled"><i class="right small chevron icon"></i></div>)
71
+ +%(<div class="item disabled"><i class="right small chevron icon"></i></div>)
72
72
  end
73
73
  end
74
74
 
@@ -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 << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
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 << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
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
@@ -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
- if num == 1
13
- link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
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
 
@@ -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(pagy, link)})
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('pagy.nav.gap')}</span></li>)
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('pagy.nav.prev')}</button>)
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('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
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(p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"')
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('pagy.nav.next')}</button>)
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(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
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('pagy.nav.prev')}</span>)
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('pagy.nav.next')}</span>)
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: 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(PAGE_PLACEHOLDER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
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
- "#{left}#{num}#{right}#{ case num
81
- when p_prev then ' rel="prev"'
82
- when p_next then ' rel="next"'
83
- else ''
84
- end } #{extra}>#{text}</a>"
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 initilized in order to avoid warning)
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.2.0
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-10 00:00:00.000000000 Z
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
@@ -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