pagy 3.5.1 → 3.7.3

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: 5d5bc9d035a9a4d9f5f807a6e95cdad150a705ab17df7fc964ea3103614a7a7d
4
- data.tar.gz: 6cee7bf4ccb841d55b1d38619f4cac613f765f8040fbe2162e2cf1ec99e84655
3
+ metadata.gz: 94c03adb9b45ec8718cf2541a03bf7d24eeb4a50bd8ea904397f4414cf888a05
4
+ data.tar.gz: 23502a3be34f3251ffde3a6ad0e4fb3bf896ed87c9945fee5c19d52ee95b1c01
5
5
  SHA512:
6
- metadata.gz: 883c2262141419d5f1e1270ef6a443bfce351c54fa1a893a477dc8dfd00ab0af1b75c7f8670e26a1a73a406723006a1ac23667a2ba9b652390eab5b46e5964d9
7
- data.tar.gz: cdb1bd1461caf095f22407eab5de315d306dbdfb1f2cc2a733f811c92f5fdef475f1995264317e32ec8d775a019e46757b801426b8f4f7c160ff4eb9bbad799e
6
+ metadata.gz: e61129fb99a6eb80dad7e229b6e160d88b5ff44e64dca48b03e7419672df191f602fbd64a03ad600c05a282ce8b9fbced6a56526b092cf44e240e7b6fe5d1465
7
+ data.tar.gz: 451e59f3750d2eca6f704b0643f2c5afe84a56af504fee65e214d897ed5c81e0f38e04206086eb26acdab6db76d9f4c639698687c596508c67ce68f18e210477
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Pagy initializer file (3.5.1)
4
+ # Pagy initializer file (3.7.3)
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '3.5.1';
5
+ Pagy.version = '3.7.3';
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.1'
7
+ class Pagy ; VERSION = '3.7.3'
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
@@ -21,7 +21,7 @@ class Pagy
21
21
  end
22
22
  html << (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
23
23
  : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
24
- %(<nav class="pagy-bootstrap-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
24
+ %(<nav class="pagy-bootstrap-nav" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
25
25
  end
26
26
 
27
27
  # Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
@@ -29,12 +29,12 @@ 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>)
36
36
  : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li></ul>) }
37
- %(<nav id="#{id}" class="pagy-bootstrap-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels, defined?(TRIM) && pagy.vars[:page_param])})
37
+ %(<nav id="#{id}" class="pagy-bootstrap-nav-js" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, tags, pagy.sequels, defined?(TRIM) && pagy.vars[:page_param])})
38
38
  end
39
39
 
40
40
  # Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
@@ -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])})
@@ -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>"}
@@ -6,7 +6,7 @@
6
6
  Usage: link.call( page_number [, text [, extra_attributes_string ]])
7
7
  -%>
8
8
  <% link = pagy_link_proc(pagy, 'class="page-link"') -%>
9
- <%# -%><nav aria-label="pager" class="pagy-bootstrap-nav pagination" role="navigation">
9
+ <%# -%><nav aria-label="pager" class="pagy-bootstrap-nav" role="navigation">
10
10
  <%# -%> <ul class="pagination">
11
11
  <% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
12
12
  <% else -%> <li class="page-item prev disabled"><a href="#" class="page-link"><%== pagy_t('pagy.nav.prev') %></a></li>
@@ -6,7 +6,7 @@
6
6
 
7
7
  - link = pagy_link_proc(pagy, 'class="page-link"')
8
8
 
9
- %nav.pagy-bootstrap-nav.pagination{"aria-label" => "pager", :role => "navigation"}
9
+ %nav.pagy-bootstrap-nav{"aria-label" => "pager", :role => "navigation"}
10
10
 
11
11
  %ul.pagination
12
12
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  - link = pagy_link_proc(pagy, 'class="page-link"')
8
8
 
9
- nav.pagy-bootstrap-nav.pagination role="navigation" aria-label="pager"
9
+ nav.pagy-bootstrap-nav role="navigation" aria-label="pager"
10
10
 
11
11
  ul.pagination
12
12
 
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.1
4
+ version: 3.7.3
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-31 00:00:00.000000000 Z
11
+ date: 2020-02-11 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