pagy 3.7.3 → 3.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +1 -1
- data/lib/javascripts/pagy.js +2 -2
- data/lib/locales/README.md +9 -2
- data/lib/locales/da.yml +22 -0
- data/lib/locales/km.yml +19 -0
- data/lib/locales/{pt-br.yml → pt-BR.yml} +1 -1
- data/lib/locales/sv-SE.yml +23 -0
- data/lib/locales/{se.yml → sv.yml} +1 -1
- data/lib/locales/utils/i18n.rb +12 -5
- data/lib/locales/utils/loader.rb +5 -0
- data/lib/locales/utils/p11n.rb +10 -8
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/elasticsearch_rails.rb +2 -2
- data/lib/pagy/extras/i18n.rb +8 -1
- data/lib/pagy/extras/support.rb +1 -1
- data/lib/pagy/frontend.rb +2 -2
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb6594ae7a224e823f3796f39c8c3603b0dd1c37f7883b362a2654d2cd85e9c3
|
4
|
+
data.tar.gz: 9fda3ae984287802b2f8a91d52cea1b9c88a3b406f0d0982fb357680f49b0bee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2c47131206f194b5306d1c3f476405baf6e53265ee8e9fcf12bd86926605b767a9357ba699f2399aef597c89f362ed31b88571080b39453285ebeae6fd19d0a
|
7
|
+
data.tar.gz: c9a427a85448b69a1890d792e6f49192276c16c2c9b062d7a6c74c263d64fb3b39b39217598187b0dff38a69fe7f5dd3a16b4e3bfc7c613cc220222519134134
|
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.8.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
|
|
data/lib/javascripts/pagy.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
-
Pagy.version = '3.
|
5
|
+
Pagy.version = '3.8.2';
|
6
6
|
|
7
7
|
Pagy.init = function(arg){
|
8
8
|
var target = arg instanceof Event || arg === undefined ? document : arg,
|
@@ -101,6 +101,6 @@ Pagy.addInputEventListeners = function(input, handler){
|
|
101
101
|
};
|
102
102
|
|
103
103
|
Pagy.trim = function(html, param){
|
104
|
-
var re = new RegExp('[?&]' + param + '=1
|
104
|
+
var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&');
|
105
105
|
return html.replace(re, '');
|
106
106
|
};
|
data/lib/locales/README.md
CHANGED
@@ -11,13 +11,20 @@ You can create a Pull Request for your language, and get all the help you need t
|
|
11
11
|
### Check list for a new dictionary file:
|
12
12
|
|
13
13
|
- [ ] Find the pluralization rule for your language
|
14
|
-
|
14
|
+
|
15
|
+
- [ ] Find the locale file you need in the [list of pluralizations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/pluralization) and check the pluralization rule in it. For example it is `::RailsI18n::Pluralization::OneOther.with_locale(:en)` for `en.rb`. Note the rule part i.e. `OneOther`. In pagy that translates to the symbol `:one_other`.
|
16
|
+
|
17
|
+
- [ ] If the pluralization rule of your language is not the `:one_other` default, confirm that the [p11n.rb](https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) file already defines the pluralization rule of your dictionary file:
|
18
|
+
|
19
|
+
- [ ] If the rule is not defined, you can either: a) Add the rule as a new rule/lambda entry in the `p11n` variable hash and relative tests or b) Just create an issue requesting the addition to the rule/lambda entry and tests.
|
20
|
+
|
21
|
+
- [ ] Add your language to the `plurals` hash in the file.
|
15
22
|
|
16
23
|
- [ ] add/edit the first line comment in the language rule in your dictionary file (e.g. `# :one_other pluralization ...`
|
17
24
|
|
18
25
|
- [ ] The mandatory pluralized entry in the dictionary file is the `item_name`. Please, provide all the plurals needed by your language. E.g. if your language uses the `:east_slavic` you should provide the plurals for `one`, `few`, `many` and `other`, if it uses `:one_other`, you should provide `one` and `other` plurals. If it uses `:other` you should only provide a single value. Look into other dictionary files to get some example. Ask if in doubt.
|
19
26
|
|
20
|
-
- [ ] The other entries in the dictionary file don't need any plural variant in most languages since the pluralization of the `item_name` in the sentence is enough. However, in some language,
|
27
|
+
- [ ] The other entries in the dictionary file don't need any plural variant in most languages since the pluralization of the `item_name` in the sentence is enough. However, in some language, a whole sentence might need to be written in different ways for different counts. In that case you should add the different plurals for the sentence and the `count` will trigger the one that applies.
|
21
28
|
|
22
29
|
Feel free to ask for help in your Pull Request.
|
23
30
|
|
data/lib/locales/da.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
|
+
da:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "resultat"
|
8
|
+
other: "resultater"
|
9
|
+
|
10
|
+
nav:
|
11
|
+
prev: "‹ Forrige"
|
12
|
+
next: "Næste ›"
|
13
|
+
gap: "…"
|
14
|
+
|
15
|
+
info:
|
16
|
+
no_items: "Ingen %{item_name} fundet"
|
17
|
+
single_page: "Viser <b>%{count}</b> %{item_name}"
|
18
|
+
multiple_pages: "Viser %{item_name} <b>%{from}-%{to}</b> til <b>%{count}</b> totalt"
|
19
|
+
|
20
|
+
combo_nav_js: "Side %{page_input} of %{pages}"
|
21
|
+
|
22
|
+
items_selector_js: "Antal %{items_input} %{item_name} per side"
|
data/lib/locales/km.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
km:
|
4
|
+
pagy:
|
5
|
+
item_name: "ធាតុ"
|
6
|
+
|
7
|
+
nav:
|
8
|
+
prev: "‹ មុន"
|
9
|
+
next: "បន្ទាប់ ›"
|
10
|
+
gap: "…"
|
11
|
+
|
12
|
+
info:
|
13
|
+
no_items: "មិនមាន %{item_name} ទេ"
|
14
|
+
single_page: "បង្ហាញ <b>%{count}</b> %{item_name}"
|
15
|
+
multiple_pages: "បង្ហាញ %{item_name} <b>%{from}-%{to}</b> នៃ <b>%{count}</b> ជាចំនួនសរុប"
|
16
|
+
|
17
|
+
combo_nav_js: "ទំព័រ %{page_input} នៃ %{pages}"
|
18
|
+
|
19
|
+
items_selector_js: "បង្ហាញ %{items_input} %{item_name} ក្នុង ១ ទំព័រ"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# :one_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
|
2
|
+
|
3
|
+
sv-SE:
|
4
|
+
pagy:
|
5
|
+
|
6
|
+
item_name:
|
7
|
+
one: "resultat"
|
8
|
+
two: "resultat"
|
9
|
+
other: "resultat"
|
10
|
+
|
11
|
+
nav:
|
12
|
+
prev: "‹ Föregående"
|
13
|
+
next: "Nästa ›"
|
14
|
+
gap: "…"
|
15
|
+
|
16
|
+
info:
|
17
|
+
no_items: "Inga %{item_name} hittade"
|
18
|
+
single_page: "Visar <b>%{count}</b> %{item_name}"
|
19
|
+
multiple_pages: "Visar %{item_name} <b>%{from}-%{to}</b> av <b>%{count}</b> totalt"
|
20
|
+
|
21
|
+
combo_nav_js: "Sida %{page_input} av %{pages}"
|
22
|
+
|
23
|
+
items_selector_js: "Visa %{items_input} %{item_name} per sida"
|
data/lib/locales/utils/i18n.rb
CHANGED
@@ -4,15 +4,22 @@
|
|
4
4
|
|
5
5
|
# this file returns the I18n hash used as default alternative to the i18n gem
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Pagy::DEPRECATED_LOCALES = {'pt-br' =>'pt-BR', 'se' => 'sv-SE'}
|
8
|
+
|
9
|
+
Hash.new{|h,_| h.first[1]}.tap do |i18n_hash| # first loaded locale used as default
|
10
|
+
i18n_hash.define_singleton_method(:load) do |*load_args|
|
9
11
|
# eval: we don't need to keep the loader proc in memory
|
10
|
-
eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(
|
12
|
+
eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n_hash, *load_args) #rubocop:disable Security/Eval
|
11
13
|
end
|
12
|
-
|
14
|
+
i18n_hash.define_singleton_method(:t) do |locale, path, vars={}|
|
15
|
+
if Pagy::DEPRECATED_LOCALES.key?(locale)
|
16
|
+
new_locale = Pagy::DEPRECATED_LOCALES[locale]
|
17
|
+
$stderr.puts("WARNING: the Pagy locale '#{locale}' is deprecated; use '#{new_locale}' instead")
|
18
|
+
locale = new_locale
|
19
|
+
end
|
13
20
|
data, pluralize = self[locale]
|
14
21
|
translate = data[path] || vars[:count] && data[path+=".#{pluralize.call(vars[:count])}"] or return %([translation missing: "#{path}"])
|
15
22
|
translate.call(vars)
|
16
23
|
end
|
17
|
-
|
24
|
+
i18n_hash.load(locale: 'en')
|
18
25
|
end
|
data/lib/locales/utils/loader.rb
CHANGED
@@ -20,6 +20,11 @@ flatten = lambda do |hash, key=''|
|
|
20
20
|
lambda do |i18n, *args|
|
21
21
|
i18n.clear
|
22
22
|
args.each do |arg|
|
23
|
+
if Pagy::DEPRECATED_LOCALES.key?(arg[:locale])
|
24
|
+
new_locale = Pagy::DEPRECATED_LOCALES[arg[:locale]]
|
25
|
+
$stderr.puts("WARNING: the Pagy locale '#{arg[:locale]}' is deprecated; use '#{new_locale}' instead")
|
26
|
+
arg[:locale] = new_locale
|
27
|
+
end
|
23
28
|
arg[:filepath] ||= Pagy.root.join('locales', "#{arg[:locale]}.yml")
|
24
29
|
arg[:pluralize] ||= plurals[arg[:locale]]
|
25
30
|
hash = YAML.load(File.read(arg[:filepath], encoding: 'UTF-8')) #rubocop:disable Security/YAMLLoad
|
data/lib/locales/utils/p11n.rb
CHANGED
@@ -60,17 +60,19 @@ p11n = {
|
|
60
60
|
# The default pluralization for locales not explicitly listed here
|
61
61
|
# is the :one_other pluralization proc (used for English)
|
62
62
|
plurals = Hash.new(p11n[:one_other]).tap do |hash|
|
63
|
-
hash['id']
|
64
|
-
hash['fr']
|
65
|
-
hash['ja']
|
66
|
-
hash['ko']
|
67
|
-
hash['pl']
|
68
|
-
hash['ru']
|
69
|
-
hash['
|
70
|
-
hash['
|
63
|
+
hash['id'] = p11n[:other]
|
64
|
+
hash['fr'] = p11n[:one_upto_two_other]
|
65
|
+
hash['ja'] = p11n[:other]
|
66
|
+
hash['ko'] = p11n[:other]
|
67
|
+
hash['pl'] = p11n[:polish]
|
68
|
+
hash['ru'] = p11n[:east_slavic]
|
69
|
+
hash['sv'] = p11n[:one_two_other]
|
70
|
+
hash['sv-SE'] = p11n[:one_two_other]
|
71
|
+
hash['tr'] = p11n[:other]
|
71
72
|
hash['zh-CN'] = p11n[:other]
|
72
73
|
hash['zh-HK'] = p11n[:other]
|
73
74
|
hash['zh-TW'] = p11n[:other]
|
75
|
+
hash['km'] = p11n[:other]
|
74
76
|
end
|
75
77
|
|
76
78
|
[ plurals, p11n ]
|
data/lib/pagy.rb
CHANGED
@@ -13,7 +13,7 @@ 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
|
-
total = response.raw_response['hits']['total']
|
16
|
+
total = response.respond_to?(:raw_response) ? response.raw_response['hits']['total'] : response.response['hits']['total']
|
17
17
|
vars[:count] = total.is_a?(Hash) ? total['value'] : total
|
18
18
|
new(vars)
|
19
19
|
end
|
@@ -28,7 +28,7 @@ class Pagy
|
|
28
28
|
search_args[-1][:size] = vars[:items]
|
29
29
|
search_args[-1][:from] = vars[:items] * (vars[:page] - 1)
|
30
30
|
response = model.search(*search_args)
|
31
|
-
total = response.raw_response['hits']['total']
|
31
|
+
total = response.respond_to?(:raw_response) ? response.raw_response['hits']['total'] : response.response['hits']['total']
|
32
32
|
vars[:count] = total.is_a?(Hash) ? total['value'] : total
|
33
33
|
pagy = Pagy.new(vars)
|
34
34
|
# with :last_page overflow we need to re-run the method in order to get the hits
|
data/lib/pagy/extras/i18n.rb
CHANGED
@@ -11,7 +11,14 @@ class Pagy
|
|
11
11
|
Pagy::I18n.clear.instance_eval { undef :load; undef :t } # unload the pagy default constant for efficiency
|
12
12
|
|
13
13
|
alias_method :pagy_without_i18n, :pagy_t
|
14
|
-
|
14
|
+
if Gem::Version.new(::I18n::VERSION) < Gem::Version.new('1.6.0')
|
15
|
+
def pagy_t_with_i18n(*args) ::I18n.t(*args) end
|
16
|
+
else
|
17
|
+
# keep 1.9 compatibility by hiding 2.0+ syntax in string
|
18
|
+
module_eval <<-RUBY
|
19
|
+
def pagy_t_with_i18n(key, **opts) ::I18n.t(key, **opts) end
|
20
|
+
RUBY
|
21
|
+
end
|
15
22
|
alias_method :pagy_t, :pagy_t_with_i18n
|
16
23
|
|
17
24
|
end
|
data/lib/pagy/extras/support.rb
CHANGED
@@ -15,7 +15,7 @@ class Pagy
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
|
18
|
-
pagy.prev ? %(<span class="page prev"><a href="#{pagy_prev_url(pagy)}" rel="
|
18
|
+
pagy.prev ? %(<span class="page prev"><a href="#{pagy_prev_url(pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
|
19
19
|
: %(<span class="page prev disabled">#{text}</span>)
|
20
20
|
end
|
21
21
|
|
data/lib/pagy/frontend.rb
CHANGED
@@ -50,11 +50,11 @@ class Pagy
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# Return examples: "Displaying items 41-60 of 324 in total" of "Displaying Products 41-60 of 324 in total"
|
53
|
-
def pagy_info(pagy)
|
53
|
+
def pagy_info(pagy, item_name=nil)
|
54
54
|
path = if (count = pagy.count) == 0 ; 'pagy.info.no_items'
|
55
55
|
else pagy.pages == 1 ? 'pagy.info.single_page' : 'pagy.info.multiple_pages'
|
56
56
|
end
|
57
|
-
pagy_t(path, item_name: pagy_t(pagy.vars[:i18n_key], count: count), count: count, from: pagy.from, to: pagy.to)
|
57
|
+
pagy_t(path, item_name: item_name || pagy_t(pagy.vars[:i18n_key], count: count), count: count, from: pagy.from, to: pagy.to)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Returns a performance optimized proc to generate the HTML links
|
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.8.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: 2020-
|
11
|
+
date: 2020-06-12 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,
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/locales/README.md
|
26
26
|
- lib/locales/bg.yml
|
27
27
|
- lib/locales/ca.yml
|
28
|
+
- lib/locales/da.yml
|
28
29
|
- lib/locales/de.yml
|
29
30
|
- lib/locales/en.yml
|
30
31
|
- lib/locales/es.yml
|
@@ -32,13 +33,15 @@ files:
|
|
32
33
|
- lib/locales/id.yml
|
33
34
|
- lib/locales/it.yml
|
34
35
|
- lib/locales/ja.yml
|
36
|
+
- lib/locales/km.yml
|
35
37
|
- lib/locales/ko.yml
|
36
38
|
- lib/locales/nb.yml
|
37
39
|
- lib/locales/nl.yml
|
38
40
|
- lib/locales/pl.yml
|
39
|
-
- lib/locales/pt-
|
41
|
+
- lib/locales/pt-BR.yml
|
40
42
|
- lib/locales/ru.yml
|
41
|
-
- lib/locales/
|
43
|
+
- lib/locales/sv-SE.yml
|
44
|
+
- lib/locales/sv.yml
|
42
45
|
- lib/locales/tr.yml
|
43
46
|
- lib/locales/utils/i18n.rb
|
44
47
|
- lib/locales/utils/loader.rb
|
@@ -107,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
110
|
- !ruby/object:Gem::Version
|
108
111
|
version: '0'
|
109
112
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.1.2
|
111
114
|
signing_key:
|
112
115
|
specification_version: 4
|
113
116
|
summary: The Ultimate Pagination Ruby Gem
|