pagy 4.9.0 → 4.11.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.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +5 -1
- data/lib/javascripts/pagy.js +6 -2
- data/lib/locales/ar.yml +26 -0
- data/lib/locales/utils/p11n.rb +24 -8
- data/lib/pagy.rb +1 -1
- data/lib/pagy/countless.rb +2 -0
- data/lib/pagy/extras/countless.rb +5 -1
- data/lib/pagy/extras/meilisearch.rb +4 -4
- data/lib/pagy/extras/trim.rb +5 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed7987ef93f9d2d45f8b37c7d8c62546bb08b658699d4fdacf7e06b2e5abdefe
|
4
|
+
data.tar.gz: d2330d05cbf068d938425ed64ec3a0b0a16cf86d36cd2a2b2d8fc2568942a2d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c938d41fae6e33cfd0d569655b134f2d239fe44f6fc5cdcfc76234e20d5c6a9e2650e6bd6f3230044783353ba65dde5afb24867af8df4c59189eee67dda25fea
|
7
|
+
data.tar.gz: 585446ab8b45078fcb666dc9a406516eeac7f715cca90118d5927f5d89acf0cc51056aa75aebed9885c3e5b25f61f9e4baad75869f2d244ab01a359919493b98
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (4.
|
3
|
+
# Pagy initializer file (4.11.0)
|
4
4
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
5
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
6
|
|
@@ -42,6 +42,7 @@
|
|
42
42
|
# Countless extra: Paginate without any count, saving one query per rendering
|
43
43
|
# See https://ddnexus.github.io/pagy/extras/countless
|
44
44
|
# require 'pagy/extras/countless'
|
45
|
+
# Pagy::VARS[:countless_minimal] = false # default (eager loading)
|
45
46
|
|
46
47
|
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
47
48
|
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
@@ -56,6 +57,9 @@
|
|
56
57
|
# also the elasticsearch_rails extra that defines the same
|
57
58
|
# VARS[:searchkick_search_method] = :pagy_search
|
58
59
|
# require 'pagy/extras/searchkick'
|
60
|
+
# uncomment if you are going to use Searchkick.pagy_search
|
61
|
+
# Searchkick.extend Pagy::Searchkick
|
62
|
+
|
59
63
|
|
60
64
|
# Frontend Extras
|
61
65
|
|
data/lib/javascripts/pagy.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
-
Pagy.version = '4.
|
5
|
+
Pagy.version = '4.11.0'
|
6
6
|
|
7
7
|
Pagy.delay = 100
|
8
8
|
|
@@ -114,4 +114,8 @@ Pagy.waitForMe =
|
|
114
114
|
Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay)
|
115
115
|
}
|
116
116
|
|
117
|
-
|
117
|
+
|
118
|
+
if (typeof window !== "undefined") {
|
119
|
+
window.addEventListener('resize', Pagy.waitForMe, true)
|
120
|
+
}
|
121
|
+
|
data/lib/locales/ar.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
ar:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
zero: "صفر"
|
8
|
+
one: "عنصر"
|
9
|
+
two: "عنصرين"
|
10
|
+
few: "قليل"
|
11
|
+
many: "كثير"
|
12
|
+
other: "عناصر"
|
13
|
+
|
14
|
+
nav:
|
15
|
+
prev: "‹ السابق"
|
16
|
+
next: "التالي ›"
|
17
|
+
gap: "…"
|
18
|
+
|
19
|
+
info:
|
20
|
+
no_items: "لا يوجد %{item_name}"
|
21
|
+
single_page: "عرض <b>%{count}</b> %{item_name}"
|
22
|
+
multiple_pages: "عرض %{item_name} <b>%{from}-%{to}</b> من اجمالي <b>%{count}</b>"
|
23
|
+
|
24
|
+
combo_nav_js: "الصفحة %{page_input} من %{pages}"
|
25
|
+
|
26
|
+
items_selector_js: "عرض %{items_input} %{item_name} لكل صفحة"
|
data/lib/locales/utils/p11n.rb
CHANGED
@@ -19,6 +19,20 @@ from12to14 = [12,13,14].freeze
|
|
19
19
|
p11n = {
|
20
20
|
one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
|
21
21
|
|
22
|
+
arabic: lambda do |n|
|
23
|
+
n ||= 0
|
24
|
+
mod100 = n % 100
|
25
|
+
|
26
|
+
case
|
27
|
+
when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
|
28
|
+
when n == 1 then 'one'
|
29
|
+
when n == 2 then 'two'
|
30
|
+
when (3..10).to_a.include?(mod100) then 'few'
|
31
|
+
when (11..99).to_a.include?(mod100) then 'many'
|
32
|
+
else 'other'
|
33
|
+
end
|
34
|
+
end,
|
35
|
+
|
22
36
|
east_slavic: lambda do |n|
|
23
37
|
n ||= 0
|
24
38
|
mod10 = n % 10
|
@@ -32,14 +46,6 @@ p11n = {
|
|
32
46
|
end
|
33
47
|
end,
|
34
48
|
|
35
|
-
west_slavic: lambda do |n|
|
36
|
-
case n
|
37
|
-
when 1 then 'one'
|
38
|
-
when 2, 3, 4 then 'few'
|
39
|
-
else 'other'
|
40
|
-
end
|
41
|
-
end,
|
42
|
-
|
43
49
|
one_two_other: lambda do |n|
|
44
50
|
case n
|
45
51
|
when 1 then 'one'
|
@@ -63,7 +69,16 @@ p11n = {
|
|
63
69
|
when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
|
64
70
|
else 'other'
|
65
71
|
end
|
72
|
+
end,
|
73
|
+
|
74
|
+
west_slavic: lambda do |n|
|
75
|
+
case n
|
76
|
+
when 1 then 'one'
|
77
|
+
when 2, 3, 4 then 'few'
|
78
|
+
else 'other'
|
79
|
+
end
|
66
80
|
end
|
81
|
+
|
67
82
|
}
|
68
83
|
|
69
84
|
# Hash of locale/pluralization pairs
|
@@ -71,6 +86,7 @@ p11n = {
|
|
71
86
|
# The default pluralization for locales not explicitly listed here
|
72
87
|
# is the :one_other pluralization proc (used for English)
|
73
88
|
plurals = Hash.new(p11n[:one_other]).tap do |hash|
|
89
|
+
hash['ar'] = p11n[:arabic]
|
74
90
|
hash['bs'] = p11n[:east_slavic]
|
75
91
|
hash['cs'] = p11n[:west_slavic]
|
76
92
|
hash['id'] = p11n[:other]
|
data/lib/pagy.rb
CHANGED
data/lib/pagy/countless.rb
CHANGED
@@ -11,6 +11,8 @@ class Pagy
|
|
11
11
|
# Merge and validate the options, do some simple arithmetic and set a few instance variables
|
12
12
|
def initialize(vars={}) # rubocop:disable Lint/MissingSuper
|
13
13
|
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden)
|
14
|
+
@vars[:fragment] = Pagy.deprecated_var(:anchor, @vars[:anchor], :fragment, @vars[:fragment]) if @vars[:anchor]
|
15
|
+
|
14
16
|
INSTANCE_VARS_MIN.each do |k,min| # validate instance variables
|
15
17
|
raise VariableError.new(self), "expected :#{k} >= #{min}; got #{@vars[k].inspect}" \
|
16
18
|
unless @vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min
|
@@ -5,6 +5,8 @@ require 'pagy/countless'
|
|
5
5
|
|
6
6
|
class Pagy
|
7
7
|
|
8
|
+
VARS[:countless_minimal] = false
|
9
|
+
|
8
10
|
module Backend
|
9
11
|
private # the whole module is private so no problem with including it in a controller
|
10
12
|
|
@@ -17,13 +19,15 @@ class Pagy
|
|
17
19
|
# Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
|
18
20
|
def pagy_countless_get_vars(_collection, vars)
|
19
21
|
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
20
|
-
vars[:page]
|
22
|
+
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
21
23
|
vars
|
22
24
|
end
|
23
25
|
|
24
26
|
# Sub-method called only by #pagy_countless: here for easy customization of record-extraction by overriding
|
25
27
|
def pagy_countless_get_items(collection, pagy)
|
26
28
|
# This should work with ActiveRecord, Sequel, Mongoid...
|
29
|
+
return collection.offset(pagy.offset).limit(pagy.items) if pagy.vars[:countless_minimal]
|
30
|
+
|
27
31
|
items = collection.offset(pagy.offset).limit(pagy.items + 1).to_a
|
28
32
|
items_size = items.size
|
29
33
|
items.pop if items_size == pagy.items + 1
|
@@ -15,9 +15,9 @@ class Pagy
|
|
15
15
|
|
16
16
|
# create a Pagy object from a Meilisearch results
|
17
17
|
def self.new_from_meilisearch(results, vars={})
|
18
|
-
vars[:items] = results.raw_answer[
|
19
|
-
vars[:page] = [results.raw_answer[
|
20
|
-
vars[:count] = results.raw_answer[
|
18
|
+
vars[:items] = results.raw_answer['limit']
|
19
|
+
vars[:page] = [results.raw_answer['offset'] / vars[:items], 1].max
|
20
|
+
vars[:count] = results.raw_answer['nbHits']
|
21
21
|
new(vars)
|
22
22
|
end
|
23
23
|
|
@@ -32,7 +32,7 @@ class Pagy
|
|
32
32
|
options[:limit] = vars[:items]
|
33
33
|
options[:offset] = (vars[:page] - 1) * vars[:items]
|
34
34
|
results = model.search(term, **options)
|
35
|
-
vars[:count] = results.raw_answer[
|
35
|
+
vars[:count] = results.raw_answer['nbHits']
|
36
36
|
|
37
37
|
pagy = Pagy.new(vars)
|
38
38
|
# with :last_page overflow we need to re-run the method in order to get the hits
|
data/lib/pagy/extras/trim.rb
CHANGED
@@ -14,10 +14,14 @@ class Pagy
|
|
14
14
|
lambda do |num, text=num, extra=''|
|
15
15
|
link = +link_proc.call(num, text, extra)
|
16
16
|
return link unless num == 1
|
17
|
-
|
17
|
+
pagy_trim(pagy, link)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def pagy_trim(pagy, link)
|
22
|
+
link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
|
23
|
+
end
|
24
|
+
|
21
25
|
end
|
22
26
|
Frontend.prepend UseTrimExtra
|
23
27
|
|
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.
|
4
|
+
version: 4.11.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-
|
11
|
+
date: 2021-08-20 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,6 +22,7 @@ files:
|
|
22
22
|
- LICENSE.txt
|
23
23
|
- lib/config/pagy.rb
|
24
24
|
- lib/javascripts/pagy.js
|
25
|
+
- lib/locales/ar.yml
|
25
26
|
- lib/locales/bg.yml
|
26
27
|
- lib/locales/bs.yml
|
27
28
|
- lib/locales/ca.yml
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
- !ruby/object:Gem::Version
|
119
120
|
version: '0'
|
120
121
|
requirements: []
|
121
|
-
rubygems_version: 3.2.
|
122
|
+
rubygems_version: 3.2.3
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: The Ultimate Pagination Ruby Gem
|