pagy 4.3.0 → 4.4.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.
@@ -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,13 +3,14 @@
3
3
 
4
4
  class Pagy
5
5
 
6
- VARS[:trim] = true
6
+ VARS[:enable_trim_extra] = true
7
7
 
8
8
  module UseTrimExtra
9
9
 
10
- def pagy_link_proc(pagy, link_extra='')
11
- link_proc = super(pagy, link_extra)
12
- return link_proc unless pagy.vars[:trim]
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]
13
14
  lambda do |num, text=num, extra=''|
14
15
  link = link_proc.call(num, text, extra)
15
16
  return link unless num == 1
@@ -7,10 +7,11 @@ 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>)
@@ -23,26 +24,30 @@ 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
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
@@ -57,7 +62,7 @@ class Pagy
57
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
 
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" role="navigation" 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,28 +63,34 @@ 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, from: pagy.from, 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>)
69
79
  end
70
80
 
71
81
  # Returns a performance optimized proc to generate the HTML links
72
82
  # Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
73
- 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
74
85
  p_prev = pagy.prev
75
86
  p_next = pagy.next
76
- left, right = %(<a href="#{pagy_url_for PAGE_PLACEHOLDER, pagy}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
77
- lambda do |num, text=num, extra=''|
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=''|
78
89
  %(#{left}#{num}#{right}#{ case num
79
90
  when p_prev then ' rel="prev"'
80
91
  when p_next then ' rel="next"'
81
92
  else ''
82
- end } #{extra}>#{text}</a>)
93
+ end } #{extra_attrs}>#{text}</a>)
83
94
  end
84
95
  end
85
96
 
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.3.0
4
+ version: 4.4.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-20 00:00:00.000000000 Z
11
+ date: 2021-04-30 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,
@@ -57,6 +57,7 @@ files:
57
57
  - lib/pagy.rb
58
58
  - lib/pagy/backend.rb
59
59
  - lib/pagy/countless.rb
60
+ - lib/pagy/deprecation.rb
60
61
  - lib/pagy/exceptions.rb
61
62
  - lib/pagy/extras/arel.rb
62
63
  - lib/pagy/extras/array.rb
@@ -75,6 +76,7 @@ files:
75
76
  - lib/pagy/extras/searchkick.rb
76
77
  - lib/pagy/extras/semantic.rb
77
78
  - lib/pagy/extras/shared.rb
79
+ - lib/pagy/extras/standalone.rb
78
80
  - lib/pagy/extras/support.rb
79
81
  - lib/pagy/extras/trim.rb
80
82
  - lib/pagy/extras/uikit.rb
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  - !ruby/object:Gem::Version
114
116
  version: '0'
115
117
  requirements: []
116
- rubygems_version: 3.2.3
118
+ rubygems_version: 3.2.15
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: The Ultimate Pagination Ruby Gem