pagy 3.5.0 → 3.7.2
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.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +2 -2
- data/lib/javascripts/pagy.js +1 -1
- data/lib/locales/es.yml +1 -1
- data/lib/locales/fr.yml +2 -2
- data/lib/locales/it.yml +22 -0
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/arel.rb +31 -0
- data/lib/pagy/extras/bootstrap.rb +1 -1
- data/lib/pagy/extras/bulma.rb +2 -2
- data/lib/pagy/extras/elasticsearch_rails.rb +4 -2
- data/lib/pagy/extras/foundation.rb +1 -1
- data/lib/pagy/extras/headers.rb +6 -6
- data/lib/pagy/extras/items.rb +3 -1
- data/lib/pagy/extras/materialize.rb +1 -1
- data/lib/pagy/extras/metadata.rb +6 -6
- data/lib/pagy/extras/navs.rb +1 -1
- data/lib/pagy/extras/semantic.rb +1 -1
- data/lib/pagy/extras/shared.rb +1 -1
- data/lib/pagy/extras/uikit.rb +2 -2
- data/lib/pagy/frontend.rb +4 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76652fd4a632f5c9214e1edd7ab0c1068a3d7d68cfab8ebf2bc32e72149fe90c
|
4
|
+
data.tar.gz: c644235b4a3157e17e60b26f41505bc84d2c6c952d01f4fbb922f20c3a8d63bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dcf374789272f45d6b19c1179c02285de9ea3adfe9cd8fa3cc0449113060a91eb56e6609c71384756f49e078f3127e5e2b1f7bc964de54eecafe2308c470844
|
7
|
+
data.tar.gz: b5591387bfcc00721540e81f3cecd4f4e4e8a699f29329e29a3a8099d398d4439b8e8e6331dc6a4202d8734d1a7eb5dd74630413547cbd04b4d7faac4ea3068b
|
data/lib/config/pagy.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Pagy initializer file (3.
|
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
|
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'
|
data/lib/javascripts/pagy.js
CHANGED
data/lib/locales/es.yml
CHANGED
data/lib/locales/fr.yml
CHANGED
data/lib/locales/it.yml
ADDED
@@ -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"
|
data/lib/pagy.rb
CHANGED
@@ -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(
|
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>)
|
data/lib/pagy/extras/bulma.rb
CHANGED
@@ -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(
|
38
|
-
'active' => %(<li>#{link.call(
|
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
|
-
|
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
|
-
|
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(
|
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>)
|
data/lib/pagy/extras/headers.rb
CHANGED
@@ -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(
|
27
|
-
hash = { 'Link' => Hash[rels.map{|rel, n|[rel, url_str.sub(
|
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
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -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] =
|
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(
|
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>)
|
data/lib/pagy/extras/metadata.rb
CHANGED
@@ -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(
|
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(
|
26
|
-
when :prev_url ; scaffold_url.sub(
|
27
|
-
when :page_url ; scaffold_url.sub(
|
28
|
-
when :next_url ; scaffold_url.sub(
|
29
|
-
when :last_url ; scaffold_url.sub(
|
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
|
data/lib/pagy/extras/navs.rb
CHANGED
@@ -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(
|
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>)
|
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -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(
|
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"')})
|
data/lib/pagy/extras/shared.rb
CHANGED
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -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(
|
37
|
-
'active' => %(<li class="uk-active"><span>#{
|
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>) }
|
data/lib/pagy/frontend.rb
CHANGED
@@ -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 =
|
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(
|
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.
|
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:
|
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.
|
110
|
+
rubygems_version: 3.0.6
|
109
111
|
signing_key:
|
110
112
|
specification_version: 4
|
111
113
|
summary: The Ultimate Pagination Ruby Gem
|