pagy 4.2.0 → 4.6.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config/pagy.rb +30 -23
  3. data/lib/javascripts/pagy.js +104 -93
  4. data/lib/locales/bg.yml +2 -2
  5. data/lib/locales/bs.yml +2 -2
  6. data/lib/locales/ca.yml +2 -2
  7. data/lib/locales/cs.yml +2 -2
  8. data/lib/locales/da.yml +2 -2
  9. data/lib/locales/de.yml +2 -2
  10. data/lib/locales/en.yml +2 -2
  11. data/lib/locales/es.yml +2 -2
  12. data/lib/locales/fr.yml +2 -2
  13. data/lib/locales/hr.yml +2 -2
  14. data/lib/locales/id.yml +2 -2
  15. data/lib/locales/it.yml +2 -2
  16. data/lib/locales/ja.yml +2 -2
  17. data/lib/locales/km.yml +2 -2
  18. data/lib/locales/ko.yml +2 -2
  19. data/lib/locales/nb.yml +2 -2
  20. data/lib/locales/nl.yml +2 -2
  21. data/lib/locales/pl.yml +2 -2
  22. data/lib/locales/pt-BR.yml +2 -2
  23. data/lib/locales/pt.yml +2 -2
  24. data/lib/locales/ru.yml +2 -2
  25. data/lib/locales/sr.yml +2 -2
  26. data/lib/locales/sv-SE.yml +2 -2
  27. data/lib/locales/sv.yml +2 -2
  28. data/lib/locales/sw.yml +2 -2
  29. data/lib/locales/tr.yml +2 -2
  30. data/lib/locales/zh-CN.yml +2 -2
  31. data/lib/locales/zh-HK.yml +2 -2
  32. data/lib/locales/zh-TW.yml +3 -3
  33. data/lib/pagy.rb +27 -21
  34. data/lib/pagy/backend.rb +1 -0
  35. data/lib/pagy/console.rb +21 -0
  36. data/lib/pagy/deprecation.rb +27 -0
  37. data/lib/pagy/extras/arel.rb +1 -0
  38. data/lib/pagy/extras/array.rb +1 -0
  39. data/lib/pagy/extras/bootstrap.rb +16 -11
  40. data/lib/pagy/extras/bulma.rb +18 -13
  41. data/lib/pagy/extras/countless.rb +2 -1
  42. data/lib/pagy/extras/elasticsearch_rails.rb +1 -0
  43. data/lib/pagy/extras/foundation.rb +24 -17
  44. data/lib/pagy/extras/headers.rb +3 -3
  45. data/lib/pagy/extras/items.rb +18 -32
  46. data/lib/pagy/extras/materialize.rb +25 -19
  47. data/lib/pagy/extras/metadata.rb +3 -2
  48. data/lib/pagy/extras/navs.rb +18 -14
  49. data/lib/pagy/extras/overflow.rb +2 -2
  50. data/lib/pagy/extras/searchkick.rb +1 -0
  51. data/lib/pagy/extras/semantic.rb +24 -19
  52. data/lib/pagy/extras/shared.rb +4 -9
  53. data/lib/pagy/extras/standalone.rb +58 -0
  54. data/lib/pagy/extras/support.rb +12 -8
  55. data/lib/pagy/extras/trim.rb +8 -7
  56. data/lib/pagy/extras/uikit.rb +24 -19
  57. data/lib/pagy/frontend.rb +34 -25
  58. metadata +6 -5
  59. data/lib/locales/README.md +0 -35
  60. data/pagy.gemspec +0 -16
@@ -16,8 +16,8 @@ class Pagy
16
16
  # "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
17
17
  # "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
18
18
  # Notice: if :steps is false it will use the single {0 => @vars[:size]} size
19
- def sequels
20
- steps = @vars[:steps] || {0 => @vars[:size]}
19
+ def sequels(steps=nil)
20
+ steps ||= @vars[:steps] || {0 => @vars[:size]}
21
21
  raise VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}" \
22
22
  unless steps.key?(0)
23
23
  {}.tap do |sequels|
@@ -30,23 +30,18 @@ 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[:enable_trim_extra]
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[:enable_trim_extra]
41
41
  %(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
42
42
  end
43
43
  end
44
44
 
45
- # it returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags
46
- def pagy_id
47
- "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
48
- end
49
-
50
45
  # it returns the marked link to used by pagy.js
51
46
  def pagy_marked_link(link)
52
47
  link.call PAGE_PLACEHOLDER, '', 'style="display: none;"'
@@ -0,0 +1,58 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/standalone
2
+ # frozen_string_literal: true
3
+
4
+ require 'uri'
5
+ class Pagy
6
+
7
+ # extracted from Rack::Utils and reformatted for rubocop
8
+ module QueryUtils
9
+ module_function
10
+ def escape(str)
11
+ URI.encode_www_form_component(str)
12
+ end
13
+ def build_nested_query(value, prefix = nil)
14
+ case value
15
+ when Array
16
+ value.map { |v| build_nested_query(v, "#{prefix}[]") }.join('&')
17
+ when Hash
18
+ value.map { |k, v| build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k)) }.delete_if(&:empty?).join('&')
19
+ when nil
20
+ prefix
21
+ else
22
+ raise ArgumentError, 'value must be a Hash' if prefix.nil?
23
+ "#{prefix}=#{escape(value)}"
24
+ end
25
+ end
26
+ end
27
+
28
+ module UseStandaloneExtra
29
+ # without any :url var it works exactly as the regular #pagy_url_for;
30
+ # with a defined :url variable it does not use rack/request
31
+ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
32
+ absolute = Pagy.deprecated_arg(:url, deprecated_url, :absolute, absolute) if deprecated_url
33
+ pagy, page = Pagy.deprecated_order(pagy, page) if page.is_a?(Pagy)
34
+ p_vars = pagy.vars
35
+ if p_vars[:url]
36
+ url_string = p_vars[:url]
37
+ params = {}
38
+ else
39
+ url_string = "#{request.base_url if absolute}#{request.path}"
40
+ params = request.GET
41
+ end
42
+ params = params.merge(p_vars[:params])
43
+ params[p_vars[:page_param].to_s] = page
44
+ params[p_vars[:items_param].to_s] = p_vars[:items] if defined?(UseItemsExtra)
45
+ query_string = "?#{QueryUtils.build_nested_query(pagy_get_params(params))}" unless params.empty?
46
+ "#{url_string}#{query_string}#{p_vars[:fragment]}"
47
+ end
48
+ end
49
+ Helpers.prepend UseStandaloneExtra
50
+
51
+ # defines a dummy #params method if not already defined in the including module
52
+ module Backend
53
+ def self.included(controller)
54
+ controller.define_method(:params){{}} unless controller.method_defined?(:params)
55
+ end
56
+ end
57
+
58
+ end
@@ -6,35 +6,39 @@ class Pagy
6
6
  module Frontend
7
7
 
8
8
  def pagy_prev_url(pagy)
9
- pagy_url_for(pagy.prev, pagy) if pagy.prev
9
+ pagy_url_for(pagy, pagy.prev) if pagy.prev
10
10
  end
11
11
 
12
12
  def pagy_next_url(pagy)
13
- pagy_url_for(pagy.next, pagy) if pagy.next
13
+ pagy_url_for(pagy, pagy.next) if pagy.next
14
14
  end
15
15
 
16
- def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
16
+ def pagy_prev_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.prev'), link_extra: '')
17
+ text = Pagy.deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
18
+ link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
17
19
  if pagy.prev
18
- %(<span class="page prev"><a href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
20
+ %(<span class="page prev"><a href="#{pagy_url_for(pagy, pagy.prev)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
19
21
  else
20
22
  %(<span class="page prev disabled">#{text}</span>)
21
23
  end
22
24
  end
23
25
 
24
- def pagy_next_link(pagy, text = pagy_t('pagy.nav.next'), link_extra = '')
26
+ def pagy_next_link(pagy, deprecated_text=nil, deprecated_link_extra=nil, text: pagy_t('pagy.nav.next'), link_extra: '')
27
+ text = Pagy.deprecated_arg(:text, deprecated_text, :text, text) if deprecated_text
28
+ link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
25
29
  if pagy.next
26
- %(<span class="page next"><a href="#{pagy_url_for(pagy.next, pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
30
+ %(<span class="page next"><a href="#{pagy_url_for(pagy, pagy.next)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
27
31
  else
28
32
  %(<span class="page next disabled">#{text}</span>)
29
33
  end
30
34
  end
31
35
 
32
36
  def pagy_prev_link_tag(pagy)
33
- %(<link href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev"/>) if pagy.prev
37
+ %(<link href="#{pagy_url_for(pagy, pagy.prev)}" rel="prev"/>) if pagy.prev
34
38
  end
35
39
 
36
40
  def pagy_next_link_tag(pagy)
37
- %(<link href="#{pagy_url_for(pagy.next, pagy)}" rel="next"/>) if pagy.next
41
+ %(<link href="#{pagy_url_for(pagy, pagy.next)}" rel="next"/>) if pagy.next
38
42
  end
39
43
 
40
44
  end
@@ -3,17 +3,18 @@
3
3
 
4
4
  class Pagy
5
5
 
6
+ VARS[:enable_trim_extra] = true
7
+
6
8
  module UseTrimExtra
7
9
 
8
- def pagy_link_proc(pagy, link_extra='')
9
- link_proc = super(pagy, link_extra)
10
+ def pagy_link_proc(pagy, deprecated_link_extra=nil, link_extra: '')
11
+ link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
12
+ link_proc = super(pagy, link_extra: link_extra)
13
+ return link_proc unless pagy.vars[:enable_trim_extra]
10
14
  lambda do |num, text=num, extra=''|
11
15
  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
16
+ return link unless num == 1
17
+ link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
17
18
  end
18
19
  end
19
20
 
@@ -7,15 +7,16 @@ class Pagy
7
7
  module Frontend
8
8
 
9
9
  # Pagination for uikit: it returns the html with the series of links to the pages
10
- def pagy_uikit_nav(pagy)
11
- link = pagy_link_proc(pagy)
10
+ def pagy_uikit_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 = %(<ul class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html(pagy, link)})
14
+ html = %(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
14
15
  pagy.series.each do |item|
15
16
  html << case item
16
17
  when Integer then %(<li>#{link.call item}</li>)
17
18
  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>)
19
+ when :gap then %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>)
19
20
  end
20
21
  end
21
22
  html << pagy_uikit_next_html(pagy, link)
@@ -23,41 +24,45 @@ class Pagy
23
24
  end
24
25
 
25
26
  # Javascript pagination for uikit: it returns a nav and a JSON tag used by the Pagy.nav javascript
26
- def pagy_uikit_nav_js(pagy, id=pagy_id)
27
- link = pagy_link_proc(pagy)
27
+ def pagy_uikit_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
28
+ pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
29
+ p_id = %( id="#{pagy_id}") if pagy_id
30
+ link = pagy_link_proc(pagy, link_extra: link_extra)
28
31
  tags = { 'before' => pagy_uikit_prev_html(pagy, link),
29
32
  'link' => %(<li>#{link.call(PAGE_PLACEHOLDER)}</li>),
30
33
  'active' => %(<li class="uk-active"><span>#{PAGE_PLACEHOLDER}</span></li>),
31
- 'gap' => %(<li class="uk-disabled"><span>#{pagy_t('pagy.nav.gap')}</span></li>),
34
+ 'gap' => %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>),
32
35
  'after' => pagy_uikit_next_html(pagy, link) }
33
36
 
34
- html = %(<ul id="#{id}" class="pagy-uikit-nav-js uk-pagination uk-flex-center"></ul>)
35
- html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
37
+ html = %(<ul#{p_id} class="pagy-njs pagy-uikit-nav-js uk-pagination uk-flex-center"></ul>)
38
+ html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
36
39
  end
37
40
 
38
41
  # Javascript combo pagination for uikit: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
39
- def pagy_uikit_combo_nav_js(pagy, id=pagy_id)
40
- link = pagy_link_proc(pagy)
42
+ def pagy_uikit_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
43
+ pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
44
+ p_id = %( id="#{pagy_id}") if pagy_id
45
+ link = pagy_link_proc(pagy, link_extra: link_extra)
41
46
  p_page = pagy.page
42
47
  p_pages = pagy.pages
43
48
  input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" class="uk-input" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
44
49
 
45
- %(<div id="#{id}" class="pagy-uikit-combo-nav-js uk-button-group">#{
50
+ %(<div#{p_id} class="pagy-uikit-combo-nav-js uk-button-group">#{
46
51
  if (p_prev = pagy.prev)
47
52
  link.call p_prev, pagy_t('pagy.nav.prev'), 'class="uk-button uk-button-default"'
48
53
  else
49
- %(<button class="uk-button uk-button-default" disabled>#{pagy_t('pagy.nav.prev')}</button>)
54
+ %(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.prev'}</button>)
50
55
  end
51
56
  }<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)
57
+ pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
53
58
  }</div>#{
54
59
  if (p_next = pagy.next)
55
- link.call(p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"')
60
+ link.call p_next, pagy_t('pagy.nav.next'), 'class="uk-button uk-button-default"'
56
61
  else
57
- %(<button class="uk-button uk-button-default" disabled>#{pagy_t('pagy.nav.next')}</button>)
62
+ %(<button class="uk-button uk-button-default" disabled>#{pagy_t 'pagy.nav.next'}</button>)
58
63
  end
59
64
  }</div>#{
60
- pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
65
+ pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
61
66
  })
62
67
  end
63
68
 
@@ -66,7 +71,7 @@ class Pagy
66
71
  private
67
72
 
68
73
  def pagy_uikit_prev_html(pagy, link)
69
- previous_span = %(<span uk-pagination-previous>#{pagy_t('pagy.nav.prev')}</span>)
74
+ previous_span = %(<span uk-pagination-previous>#{pagy_t 'pagy.nav.prev'}</span>)
70
75
  if (p_prev = pagy.prev)
71
76
  %(<li>#{link.call p_prev, previous_span}</li>)
72
77
  else
@@ -75,7 +80,7 @@ class Pagy
75
80
  end
76
81
 
77
82
  def pagy_uikit_next_html(pagy, link)
78
- next_span = %(<span uk-pagination-next>#{pagy_t('pagy.nav.next')}</span>)
83
+ next_span = %(<span uk-pagination-next>#{pagy_t 'pagy.nav.next'}</span>)
79
84
  if (p_next = pagy.next)
80
85
  %(<li>#{link.call p_next, next_span}</li>)
81
86
  else
data/lib/pagy/frontend.rb CHANGED
@@ -13,11 +13,15 @@ class Pagy
13
13
 
14
14
  module Helpers
15
15
  # This works with all Rack-based frameworks (Sinatra, Padrino, Rails, ...)
16
- def pagy_url_for(page, pagy, url=nil)
16
+ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
17
+ absolute = Pagy.deprecated_arg(:url, deprecated_url, :absolute, absolute) if deprecated_url
18
+ pagy, page = Pagy.deprecated_order(pagy, page) if page.is_a?(Pagy)
17
19
  p_vars = pagy.vars
18
20
  params = request.GET.merge(p_vars[:params])
19
- params[p_vars[:page_param].to_s] = page
20
- "#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
21
+ params[p_vars[:page_param].to_s] = page
22
+ params[p_vars[:items_param].to_s] = p_vars[:items] if defined?(UseItemsExtra)
23
+ query_string = "?#{Rack::Utils.build_nested_query(pagy_get_params(params))}" unless params.empty?
24
+ "#{request.base_url if absolute}#{request.path}#{query_string}#{p_vars[:fragment]}"
21
25
  end
22
26
 
23
27
  # Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
@@ -31,12 +35,13 @@ class Pagy
31
35
  include Helpers
32
36
 
33
37
  # Generic pagination: it returns the html with the series of links to the pages
34
- def pagy_nav(pagy)
35
- link = pagy_link_proc(pagy)
38
+ def pagy_nav(pagy, pagy_id: nil, link_extra: '')
39
+ p_id = %( id="#{pagy_id}") if pagy_id
40
+ link = pagy_link_proc(pagy, link_extra: link_extra)
36
41
  p_prev = pagy.prev
37
42
  p_next = pagy.next
38
43
 
39
- html = +%(<nav class="pagy-nav pagination" role="navigation" aria-label="pager">)
44
+ html = +%(<nav#{p_id} class="pagy-nav pagination" aria-label="pager">)
40
45
  html << if p_prev
41
46
  %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
42
47
  else
@@ -58,35 +63,39 @@ class Pagy
58
63
  end
59
64
 
60
65
  # Return examples: "Displaying items 41-60 of 324 in total" of "Displaying Products 41-60 of 324 in total"
61
- def pagy_info(pagy, item_name=nil)
62
- count = pagy.count
63
- key = if count.zero? then 'pagy.info.no_items'
64
- elsif pagy.pages == 1 then 'pagy.info.single_page'
65
- else 'pagy.info.multiple_pages'
66
- end
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
66
+ def pagy_info(pagy, deprecated_item_name=nil, pagy_id: nil, item_name: nil, i18n_key: nil)
67
+ p_id = %( id="#{pagy_id}") if pagy_id
68
+ item_name = Pagy.deprecated_arg(:item_name, deprecated_item_name, :item_name, item_name) if deprecated_item_name
69
+ p_count = pagy.count
70
+ key = if p_count.zero? then 'pagy.info.no_items'
71
+ elsif pagy.pages == 1 then 'pagy.info.single_page'
72
+ else 'pagy.info.multiple_pages'
73
+ end
74
+
75
+ %(<span#{p_id} class="pagy-info">#{
76
+ pagy_t key, item_name: item_name || pagy_t(i18n_key || pagy.vars[:i18n_key], count: p_count),
77
+ count: p_count, from: pagy.from, to: pagy.to
78
+ }</span>)
71
79
  end
72
80
 
73
81
  # Returns a performance optimized proc to generate the HTML links
74
82
  # Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
75
- def pagy_link_proc(pagy, link_extra='')
83
+ def pagy_link_proc(pagy, deprecated_link_extra=nil, link_extra: '')
84
+ link_extra = Pagy.deprecated_arg(:link_extra, deprecated_link_extra, :link_extra, link_extra) if deprecated_link_extra
76
85
  p_prev = pagy.prev
77
86
  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)
79
- 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>"
87
+ left, right = %(<a href="#{pagy_url_for pagy, PAGE_PLACEHOLDER}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
88
+ lambda do |num, text=num, extra_attrs=''|
89
+ %(#{left}#{num}#{right}#{ case num
90
+ when p_prev then ' rel="prev"'
91
+ when p_next then ' rel="next"'
92
+ else ''
93
+ end } #{extra_attrs}>#{text}</a>)
85
94
  end
86
95
  end
87
96
 
88
97
  # Similar to I18n.t: just ~18x faster using ~10x less memory
89
- # (@pagy_locale explicitly initilized in order to avoid warning)
98
+ # (@pagy_locale explicitly initialized in order to avoid warning)
90
99
  def pagy_t(key, **opts)
91
100
  Pagy::I18n.t @pagy_locale||=nil, key, **opts
92
101
  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.6.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-05-09 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
@@ -57,7 +56,9 @@ files:
57
56
  - lib/locales/zh-TW.yml
58
57
  - lib/pagy.rb
59
58
  - lib/pagy/backend.rb
59
+ - lib/pagy/console.rb
60
60
  - lib/pagy/countless.rb
61
+ - lib/pagy/deprecation.rb
61
62
  - lib/pagy/exceptions.rb
62
63
  - lib/pagy/extras/arel.rb
63
64
  - lib/pagy/extras/array.rb
@@ -76,6 +77,7 @@ files:
76
77
  - lib/pagy/extras/searchkick.rb
77
78
  - lib/pagy/extras/semantic.rb
78
79
  - lib/pagy/extras/shared.rb
80
+ - lib/pagy/extras/standalone.rb
79
81
  - lib/pagy/extras/support.rb
80
82
  - lib/pagy/extras/trim.rb
81
83
  - lib/pagy/extras/uikit.rb
@@ -95,7 +97,6 @@ files:
95
97
  - lib/templates/uikit_nav.html.erb
96
98
  - lib/templates/uikit_nav.html.haml
97
99
  - lib/templates/uikit_nav.html.slim
98
- - pagy.gemspec
99
100
  homepage: https://github.com/ddnexus/pagy
100
101
  licenses:
101
102
  - MIT
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
118
  requirements: []
118
- rubygems_version: 3.2.3
119
+ rubygems_version: 3.2.15
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: The Ultimate Pagination Ruby Gem
@@ -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
-