pagy 3.5.0 → 3.7.2

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: a1cd0c46c7653c9ca234cdc26c4582ba9aed45de1e9041aad2fd5f7bf19c6b0f
4
- data.tar.gz: 4c8527dd62f9a5f6e32e660a78df65e92ab72a26c97e148149927eea0043b8fb
3
+ metadata.gz: 76652fd4a632f5c9214e1edd7ab0c1068a3d7d68cfab8ebf2bc32e72149fe90c
4
+ data.tar.gz: c644235b4a3157e17e60b26f41505bc84d2c6c952d01f4fbb922f20c3a8d63bc
5
5
  SHA512:
6
- metadata.gz: 450fb7112761bee9bcceb85dfcdd38c03e7914e29c8ea7f6816e8bebbbd7c742a39f77e9eec698b420bd481dbbaced929d023437e8991482fa087184c1664b9c
7
- data.tar.gz: f2d32c23c141e7d440715550856876152153c47d1fb98954ef4451e1ad483b6b81939c8cb9e1c559c14332ca42b4a014f751ab169f50d3ab3908bc299154c780
6
+ metadata.gz: 9dcf374789272f45d6b19c1179c02285de9ea3adfe9cd8fa3cc0449113060a91eb56e6609c71384756f49e078f3127e5e2b1f7bc964de54eecafe2308c470844
7
+ data.tar.gz: b5591387bfcc00721540e81f3cecd4f4e4e8a699f29329e29a3a8099d398d4439b8e8e6331dc6a4202d8734d1a7eb5dd74630413547cbd04b4d7faac4ea3068b
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Pagy initializer file (3.5.0)
4
+ # Pagy initializer file (3.7.2)
5
5
  # Customize only what you really need and notice that Pagy works also without any of the following lines.
6
6
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
7
7
 
@@ -89,7 +89,7 @@
89
89
  # require 'pagy/extras/overflow'
90
90
  # Pagy::VARS[:overflow] = :empty_page # default (other options: :last_page and :exception)
91
91
 
92
- # Metadata extra: Provides the pagination metadata to Javascrtipt frameworks like Vue.js, react.js, etc.
92
+ # Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
93
93
  # See https://ddnexus.github.io/pagy/extras/metadata
94
94
  # you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
95
95
  # require 'pagy/extras/shared'
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '3.5.0';
5
+ Pagy.version = '3.7.2';
6
6
 
7
7
  Pagy.init = function(arg){
8
8
  var target = arg instanceof Event || arg === undefined ? document : arg,
@@ -8,7 +8,7 @@ es:
8
8
  other: "ítems"
9
9
 
10
10
  nav:
11
- prev: "‹ Prev"
11
+ prev: "‹ Anterior"
12
12
  next: "Siguiente ›"
13
13
  gap: "…"
14
14
 
@@ -4,8 +4,8 @@ fr:
4
4
  pagy:
5
5
 
6
6
  item_name:
7
- one: "élement"
8
- other: "élements"
7
+ one: "élément"
8
+ other: "éléments"
9
9
 
10
10
  nav:
11
11
  prev: "‹ Précédent"
@@ -0,0 +1,22 @@
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
3
+ it:
4
+ pagy:
5
+
6
+ item_name:
7
+ one: "elemento"
8
+ other: "elementi"
9
+
10
+ nav:
11
+ prev: "‹ Precedente"
12
+ next: "Seguente ›"
13
+ gap: "…"
14
+
15
+ info:
16
+ no_items: "Nessun %{item_name} trovato"
17
+ single_page: "Visualizzazione di <b>%{count}</b> %{item_name}"
18
+ multiple_pages: "Visualizzazione %{item_name} <b>%{from}-%{to}</b> di <b>%{count}</b> in totale"
19
+
20
+ combo_nav_js: "Pagina %{page_input} di %{pages}"
21
+
22
+ items_selector_js: "Mostra %{items_input} %{item_name} per pagina"
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'pathname'
6
6
 
7
- class Pagy ; VERSION = '3.5.0'
7
+ class Pagy ; VERSION = '3.7.2'
8
8
 
9
9
  # Root pathname to get the path of Pagy files like templates or dictionaries
10
10
  def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end
@@ -0,0 +1,31 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/arel
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
4
+
5
+ class Pagy
6
+ module Backend ; private
7
+
8
+ def pagy_arel(collection, vars={})
9
+ pagy = Pagy.new(pagy_arel_get_vars(collection, vars))
10
+ return pagy, pagy_get_items(collection, pagy)
11
+ end
12
+
13
+ def pagy_arel_get_vars(collection, vars)
14
+ vars[:count] ||= pagy_arel_count(collection)
15
+ vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
16
+ vars
17
+ end
18
+
19
+ def pagy_arel_count(collection)
20
+ if collection.group_values.empty?
21
+ # COUNT(*)
22
+ collection.count(:all)
23
+ else
24
+ # COUNT(*) OVER ()
25
+ sql = Arel.star.count.over(Arel::Nodes::Grouping.new([]))
26
+ collection.unscope(:order).limit(1).pluck(sql).first.to_i
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -29,7 +29,7 @@ class Pagy
29
29
  link, p_prev, p_next = pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
30
30
  tags = { 'before' => p_prev ? %(<ul class="pagination"><li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
31
31
  : %(<ul class="pagination"><li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>),
32
- 'link' => %(<li class="page-item">#{mark = link.call(MARK)}</li>),
32
+ 'link' => %(<li class="page-item">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
33
33
  'active' => %(<li class="page-item active">#{mark}</li>),
34
34
  'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>),
35
35
  'after' => p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li></ul>)
@@ -34,8 +34,8 @@ class Pagy
34
34
  + (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
35
35
  : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>)) \
36
36
  + '<ul class="pagination-list">' ),
37
- 'link' => %(<li>#{link.call(MARK, MARK, %(class="pagination-link" aria-label="goto page #{MARK}"))}</li>),
38
- 'active' => %(<li>#{link.call(MARK, MARK, %(class="pagination-link is-current" aria-current="page" aria-label="page #{MARK}"))}</li>),
37
+ 'link' => %(<li>#{link.call(PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link" aria-label="goto page #{PAGE_PLACEHOLDER}"))}</li>),
38
+ 'active' => %(<li>#{link.call(PAGE_PLACEHOLDER, PAGE_PLACEHOLDER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{PAGE_PLACEHOLDER}"))}</li>),
39
39
  'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>),
40
40
  'after' => '</ul>' }
41
41
  %(<nav id="#{id}" class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels, defined?(TRIM) && pagy.vars[:page_param])})
@@ -13,7 +13,8 @@ class Pagy
13
13
  def self.new_from_elasticsearch_rails(response, vars={})
14
14
  vars[:items] = response.search.options[:size] || 10
15
15
  vars[:page] = (response.search.options[:from] || 0) / vars[:items] + 1
16
- vars[:count] = response.raw_response['hits']['total']
16
+ total = response.raw_response['hits']['total']
17
+ vars[:count] = total.is_a?(Hash) ? total['value'] : total
17
18
  new(vars)
18
19
  end
19
20
 
@@ -27,7 +28,8 @@ class Pagy
27
28
  search_args[-1][:size] = vars[:items]
28
29
  search_args[-1][:from] = vars[:items] * (vars[:page] - 1)
29
30
  response = model.search(*search_args)
30
- vars[:count] = response.raw_response['hits']['total']
31
+ total = response.raw_response['hits']['total']
32
+ vars[:count] = total.is_a?(Hash) ? total['value'] : total
31
33
  pagy = Pagy.new(vars)
32
34
  # with :last_page overflow we need to re-run the method in order to get the hits
33
35
  if defined?(OVERFLOW) && pagy.overflow? && pagy.vars[:overflow] == :last_page
@@ -30,7 +30,7 @@ class Pagy
30
30
  tags = { 'before' => ( '<ul class="pagination">' \
31
31
  + (p_prev ? %(<li class="prev">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"')}</li>)
32
32
  : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>)) ),
33
- 'link' => %(<li>#{link.call(MARK)}</li>),
33
+ 'link' => %(<li>#{link.call(PAGE_PLACEHOLDER)}</li>),
34
34
  'active' => %(<li class="current">#{pagy.page}</li>),
35
35
  'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
36
36
  'after' => ( (p_next ? %(<li class="next">#{link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next"')}</li>)
@@ -23,14 +23,14 @@ class Pagy
23
23
  def pagy_headers_hash(pagy)
24
24
  countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
25
25
  rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }; rels['last'] = pagy.last unless countless
26
- url_str = pagy_url_for(Frontend::MARK, pagy, :url)
27
- hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(Frontend::MARK, n.to_s)] if n}.compact] }
26
+ url_str = pagy_url_for(PAGE_PLACEHOLDER, pagy, :url)
27
+ hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(PAGE_PLACEHOLDER, n.to_s)] if n}.compact] }
28
28
  headers = pagy.vars[:headers]
29
- hash[headers[:page]] = pagy.page if headers[:page]
30
- hash[headers[:items]] = pagy.vars[:items] if headers[:items]
29
+ hash[headers[:page]] = pagy.page.to_s if headers[:page]
30
+ hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
31
31
  unless countless
32
- hash[headers[:pages]] = pagy.pages if headers[:pages]
33
- hash[headers[:count]] = pagy.count if headers[:count]
32
+ hash[headers[:pages]] = pagy.pages.to_s if headers[:pages]
33
+ hash[headers[:count]] = pagy.count.to_s if headers[:count]
34
34
  end
35
35
  hash
36
36
  end
@@ -10,6 +10,8 @@ class Pagy
10
10
  VARS[:items_param] = :items
11
11
  VARS[:max_items] = 100
12
12
 
13
+ ITEMS_PLACEHOLDER = '__pagy_items__'
14
+
13
15
  # Handle a custom number of :items from params
14
16
  module Backend ; private
15
17
 
@@ -49,7 +51,7 @@ class Pagy
49
51
  def pagy_items_selector_js(pagy, id=pagy_id)
50
52
  p_vars = pagy.vars
51
53
  p_items = p_vars[:items]
52
- p_vars[:items] = '__pagy_items__'
54
+ p_vars[:items] = ITEMS_PLACEHOLDER
53
55
  link = pagy_marked_link(pagy_link_proc(pagy))
54
56
  p_vars[:items] = p_items # restore the items
55
57
 
@@ -29,7 +29,7 @@ class Pagy
29
29
  tags = { 'before' => ( '<ul class="pagination">' \
30
30
  + (p_prev ? %(<li class="waves-effect prev">#{link.call(p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"')}</li>)
31
31
  : %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>)) ),
32
- 'link' => %(<li class="waves-effect">#{mark = link.call(MARK)}</li>),
32
+ 'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
33
33
  'active' => %(<li class="active">#{mark}</li>),
34
34
  'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>),
35
35
  'after' => ( (p_next ? %(<li class="waves-effect next">#{link.call(p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"')}</li>)
@@ -17,16 +17,16 @@ class Pagy
17
17
  def pagy_metadata(pagy, url=false)
18
18
  names = pagy.vars[:metadata]
19
19
  (unknown = names - METADATA).empty? or raise(VariableError.new(pagy), "unknown metadata #{unknown.inspect}")
20
- scaffold_url = pagy_url_for(Frontend::MARK, pagy, url)
20
+ scaffold_url = pagy_url_for(PAGE_PLACEHOLDER, pagy, url)
21
21
  metadata = {}
22
22
  names.each do |key|
23
23
  metadata[key] = case key
24
24
  when :scaffold_url ; scaffold_url
25
- when :first_url ; scaffold_url.sub(Frontend::MARK, 1.to_s)
26
- when :prev_url ; scaffold_url.sub(Frontend::MARK, pagy.prev.to_s)
27
- when :page_url ; scaffold_url.sub(Frontend::MARK, pagy.page.to_s)
28
- when :next_url ; scaffold_url.sub(Frontend::MARK, pagy.next.to_s)
29
- when :last_url ; scaffold_url.sub(Frontend::MARK, pagy.last.to_s)
25
+ when :first_url ; scaffold_url.sub(PAGE_PLACEHOLDER, 1.to_s)
26
+ when :prev_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.prev.to_s)
27
+ when :page_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.page.to_s)
28
+ when :next_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.next.to_s)
29
+ when :last_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.last.to_s)
30
30
  else pagy.send(key)
31
31
  end
32
32
  end
@@ -12,7 +12,7 @@ class Pagy
12
12
  link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
13
13
  tags = { 'before' => p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
14
14
  : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ),
15
- 'link' => %(<span class="page">#{link.call(MARK)}</span> ),
15
+ 'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
16
16
  'active' => %(<span class="page active">#{pagy.page}</span> ),
17
17
  'gap' => %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ),
18
18
  'after' => p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
@@ -29,7 +29,7 @@ class Pagy
29
29
  link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
30
30
  tags = { 'before' => (p_prev ? %(#{link.call(p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"')})
31
31
  : %(<div class="item disabled"><i class="left small chevron icon"></i></div>)),
32
- 'link' => %(#{link.call(MARK)}),
32
+ 'link' => %(#{link.call(PAGE_PLACEHOLDER)}),
33
33
  'active' => %(<a class="item active">#{pagy.page}</a>),
34
34
  'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
35
35
  'after' => (p_next ? %(#{link.call(p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"')})
@@ -45,7 +45,7 @@ class Pagy
45
45
 
46
46
  # it returns the marked link to used by pagy.js
47
47
  def pagy_marked_link(link)
48
- link.call(MARK, '', 'style="display: none;"')
48
+ link.call(PAGE_PLACEHOLDER, '', 'style="display: none;"')
49
49
  end
50
50
 
51
51
  end
@@ -33,8 +33,8 @@ class Pagy
33
33
  next_span = "<span uk-pagination-next>#{pagy_t('pagy.nav.next')}</span>"
34
34
  tags = { 'before' => p_prev ? %(<li>#{link.call p_prev, previous_span}</li>)
35
35
  : %(<li class="uk-disabled"><a href="#">#{previous_span}</a></li>),
36
- 'link' => %(<li>#{link.call(MARK)}</li>),
37
- 'active' => %(<li class="uk-active"><span>#{MARK}</span></li>),
36
+ 'link' => %(<li>#{link.call(PAGE_PLACEHOLDER)}</li>),
37
+ 'active' => %(<li class="uk-active"><span>#{PAGE_PLACEHOLDER}</span></li>),
38
38
  'gap' => %(<li class="uk-disabled"><span>#{pagy_t('pagy.nav.gap')}</span></li>),
39
39
  'after' => p_next ? %(<li>#{link.call p_next, next_span}</li>)
40
40
  : %(<li class="uk-disabled"><a href="#">#{next_span}</a></li>) }
@@ -6,6 +6,8 @@ require 'yaml'
6
6
 
7
7
  class Pagy
8
8
 
9
+ PAGE_PLACEHOLDER = '__pagy_page__' # string used for search and replace, hardcoded also in the pagy.js file
10
+
9
11
  # I18n static hash loaded at startup, used as default alternative to the i18n gem.
10
12
  # see https://ddnexus.github.io/pagy/api/frontend#i18n
11
13
  I18n = eval(Pagy.root.join('locales', 'utils', 'i18n.rb').read) #rubocop:disable Security/Eval
@@ -28,7 +30,7 @@ class Pagy
28
30
  include Helpers
29
31
 
30
32
  EMPTY = '' # EMPTY + 'string' is almost as fast as +'string' but is also 1.9 compatible
31
- MARK = '__pagy_page__' # string used for search and replace, hardcoded also in the pagy.js file
33
+ MARK = PAGE_PLACEHOLDER # backward compatibility in case of helper-overriding in legacy apps
32
34
 
33
35
  # Generic pagination: it returns the html with the series of links to the pages
34
36
  def pagy_nav(pagy)
@@ -59,7 +61,7 @@ class Pagy
59
61
  # Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
60
62
  def pagy_link_proc(pagy, link_extra='')
61
63
  p_prev, p_next = pagy.prev, pagy.next
62
- a, b = %(<a href="#{pagy_url_for(MARK, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(MARK, 2)
64
+ a, b = %(<a href="#{pagy_url_for(PAGE_PLACEHOLDER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(PAGE_PLACEHOLDER, 2)
63
65
  lambda {|n, text=n, extra=''| "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'
64
66
  elsif n == p_next ; ' rel="next"'
65
67
  else '' end } #{extra}>#{text}</a>"}
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: 3.5.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-20 00:00:00.000000000 Z
11
+ date: 2020-01-14 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,
@@ -30,6 +30,7 @@ files:
30
30
  - lib/locales/es.yml
31
31
  - lib/locales/fr.yml
32
32
  - lib/locales/id.yml
33
+ - lib/locales/it.yml
33
34
  - lib/locales/ja.yml
34
35
  - lib/locales/ko.yml
35
36
  - lib/locales/nb.yml
@@ -49,6 +50,7 @@ files:
49
50
  - lib/pagy/backend.rb
50
51
  - lib/pagy/countless.rb
51
52
  - lib/pagy/exceptions.rb
53
+ - lib/pagy/extras/arel.rb
52
54
  - lib/pagy/extras/array.rb
53
55
  - lib/pagy/extras/bootstrap.rb
54
56
  - lib/pagy/extras/bulma.rb
@@ -105,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubygems_version: 3.0.3
110
+ rubygems_version: 3.0.6
109
111
  signing_key:
110
112
  specification_version: 4
111
113
  summary: The Ultimate Pagination Ruby Gem