pagy 0.8.2 → 0.8.3
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/pagy.rb +1 -4
- data/lib/pagy/extras/initializer_example.rb +4 -4
- data/lib/pagy/frontend.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d15c4b37bce77cfd5a60512d46d728a5ea33dcd8f9f32cf31de6307f9d5b5d8
|
4
|
+
data.tar.gz: 501a0e654d0874766cafaa5c12b79e3dc5b643cdb3150a99e6bd2d4cf45ce159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2aff48d06edc8e6aa08c118f55b01cc9e70beafc23fbb99a9af5bcb45bd63d0abc90a766d941abfeafa7ed0dbdd592f2471c383b8082bda02f328a679c3ad6
|
7
|
+
data.tar.gz: c48a529c198243dbcb66c20f7b5047dd12bdec53a22d72954b61967dbbb205bc5037ab6e84426f12be2ca3f5d43d4b61380d99a16f64ace8116a08c79ee8d489
|
data/lib/pagy.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
-
class Pagy ; VERSION = '0.8.
|
5
|
+
class Pagy ; VERSION = '0.8.3'
|
6
6
|
|
7
7
|
class OutOfRangeError < StandardError; end
|
8
8
|
|
@@ -12,9 +12,6 @@ class Pagy ; VERSION = '0.8.2'
|
|
12
12
|
# default core vars
|
13
13
|
VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params: {} }
|
14
14
|
|
15
|
-
# default I18n vars
|
16
|
-
zero_one = [:zero, :one] ; I18N = { file: Pagy.root.join('locales', 'pagy.yml').to_s, plurals: -> (c) {(zero_one[c] || :other).to_s.freeze} }
|
17
|
-
|
18
15
|
attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
|
19
16
|
|
20
17
|
# merge and validate the options, do some simple aritmetic and set the instance variables
|
@@ -46,10 +46,10 @@
|
|
46
46
|
# Pagy::VARS[:breakpoints] = { 0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3] } # example of width/size pairs
|
47
47
|
|
48
48
|
|
49
|
-
#
|
50
|
-
# See https://ddnexus.github.io/pagy/api/frontend#
|
51
|
-
# Pagy::I18N[:
|
52
|
-
# Pagy::I18N
|
49
|
+
# Pagy::Frontend::I18N Constant
|
50
|
+
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
51
|
+
# Pagy::Frontend::I18N[:plurals] = -> (c) {([:zero, :one][c] || :other).to_s # default
|
52
|
+
# Pagy::Frontend::I18N.load_file('path/to/dictionary.yml') # load a custom file
|
53
53
|
|
54
54
|
|
55
55
|
# Rails: extras assets path required by compact or responsive extras
|
data/lib/pagy/frontend.rb
CHANGED
@@ -57,14 +57,16 @@ class Pagy
|
|
57
57
|
end
|
58
58
|
|
59
59
|
|
60
|
-
#
|
61
|
-
|
60
|
+
# Pagy::Frontend::I18N constant
|
61
|
+
zero_one = [:zero, :one]; I18N = { plurals: -> (c) {(zero_one[c] || :other).to_s.freeze}, data: {}}
|
62
|
+
def I18N.load_file(file) I18N[:data].replace(YAML.load_file(file).first[1]) end
|
63
|
+
I18N[:data] = I18N.load_file(Pagy.root.join('locales', 'pagy.yml'))
|
62
64
|
|
63
65
|
# Similar to I18n.t for interpolation and pluralization but without translation
|
64
66
|
# Use only for single-language apps: it is specialized for pagy and 5x faster than I18n.t
|
65
67
|
# See also https://ddnexus.github.io/pagy/extras/i18n to use the standard I18n gem instead
|
66
68
|
def pagy_t(path, vars={})
|
67
|
-
value =
|
69
|
+
value = I18N[:data].dig(*path.to_s.split('.'.freeze)) or return %(translation missing: "#{path}")
|
68
70
|
if value.is_a?(Hash)
|
69
71
|
vars.key?(:count) or return value
|
70
72
|
plural = I18N[:plurals].call(vars[:count])
|