pagy 5.6.1 → 5.6.2

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: a5d3090b61a9b11c0763a7c2d103ee36f4a36f0618e7e99b32357bab408a29bc
4
- data.tar.gz: d5c3c376deda1c84558bbcff43809c9235cb2fc9ced7492ecdfe8df6397c873e
3
+ metadata.gz: 0a24ac286e97d1aacd7603d7ada3791006120004bf56c027320c4184b9488fc7
4
+ data.tar.gz: 63a018d758c2ffff334de22fc8fdd433cdffe74030ba46ca5c3cf5dc8a563a9c
5
5
  SHA512:
6
- metadata.gz: 6591de1571e9b6bdf1a26668cf730dcbba4c83ef9f2d3727b3a1bec5f98c49a69ae2d55aab363444d85a3310e3de65fe119fb3606ca63cfdf56202c14c591568
7
- data.tar.gz: 02fea4991aab7911107460e58e73a66f507f9fff990261f1536fddf016b9523003165ed0dfd024013282ef43fec221cb7fcfa27b7f6b23c60a742f175adc0eae
6
+ metadata.gz: f5fd0f9dd9c8c8a151ea026e7e749ba6446fec53baf4bd9af276f8059f062d50d54b0d500e46762f5f4df8a3f89af475f4b07c7d8633f8194ee3da5d33d2b104
7
+ data.tar.gz: cd09f6222ce1d6db7c92984c9382d080d386ea862f66b3b7104721ea6cc6fc5e788714ce2aa623517c6ad9f17c6c95fd52fdcbcf2ba9a017c1485b262ce86405
data/lib/config/pagy.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.6.1)
4
- # Customize only what you really need and notice that Pagy works also without any of the following lines.
3
+ # Pagy initializer file (5.6.2)
4
+ # Customize only what you really need and notice that the core 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
 
7
7
 
8
8
  # Pagy DEFAULT Variables
9
9
  # See https://ddnexus.github.io/pagy/api/pagy#variables
10
- # All the Pagy::DEFAULT are set for all the Pagy instances but can be overridden per instance
11
- # by just passing them to Pagy.new|Pagy::Countless.new|Pagy::Calendar.new or the #pagy controller method
10
+ # All the Pagy::DEFAULT are set for all the Pagy instances but can be overridden per instance by just passing them to
11
+ # Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
12
12
 
13
13
 
14
14
  # Instance variables
@@ -40,7 +40,7 @@
40
40
  # See https://ddnexus.github.io/pagy/extras/array
41
41
  # require 'pagy/extras/array'
42
42
 
43
- # Calendar extra: Add pagination filtering by calendar time unit (year, quartr, month, week, day)
43
+ # Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
44
44
  # See https://ddnexus.github.io/pagy/extras/calendar
45
45
  # require 'pagy/extras/calendar'
46
46
  # Default for each unit
@@ -60,7 +60,7 @@
60
60
  # Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
61
61
  # Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
62
62
  #
63
- # Uncomment the following block, if you need calendar localization without using the I18n extra
63
+ # Uncomment the following lines, if you need calendar localization without using the I18n extra
64
64
  # module LocalizePagyCalendar
65
65
  # def localize(time, opts)
66
66
  # ::I18n.l(time, **opts)
@@ -100,8 +100,8 @@
100
100
  # you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
101
101
  # require 'pagy/extras/shared'
102
102
  # require 'pagy/extras/metadata'
103
- # For performance reason, you should explicitly set ONLY the metadata you use in the frontend
104
- # Pagy::DEFAULT[:metadata] = %i[scaffold_url count page prev next last] # example
103
+ # For performance reasons, you should explicitly set ONLY the metadata you use in the frontend
104
+ # Pagy::DEFAULT[:metadata] = %i[scaffold_url page prev next last] # example
105
105
 
106
106
  # Searchkick extra: Paginate `Searchkick::Results` objects
107
107
  # See https://ddnexus.github.io/pagy/extras/searchkick
@@ -212,18 +212,18 @@
212
212
  #
213
213
  # load the "de", "en" and "es" built-in locales:
214
214
  # (the first passed :locale will be used also as the default_locale)
215
- # Pagy::I18n.load({locale: 'de'},
216
- # {locale: 'en'},
217
- # {locale: 'es'})
215
+ # Pagy::I18n.load({ locale: 'de' },
216
+ # { locale: 'en' },
217
+ # { locale: 'es' })
218
218
  #
219
219
  # load the "en" built-in locale, a custom "es" locale,
220
220
  # and a totally custom locale complete with a custom :pluralize proc:
221
221
  # (the first passed :locale will be used also as the default_locale)
222
- # Pagy::I18n.load({locale: 'en'},
223
- # {locale: 'es', filepath: 'path/to/pagy-es.yml'},
224
- # {locale: 'xyz', # not built-in
225
- # filepath: 'path/to/pagy-xyz.yml',
226
- # pluralize: lambda{ |count| ... } )
222
+ # Pagy::I18n.load({ locale: 'en' },
223
+ # { locale: 'es', filepath: 'path/to/pagy-es.yml' },
224
+ # { locale: 'xyz', # not built-in
225
+ # filepath: 'path/to/pagy-xyz.yml',
226
+ # pluralize: lambda{ |count| ... } )
227
227
 
228
228
 
229
229
  # I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
@@ -5,7 +5,7 @@
5
5
  // Container of the whole pagy stuff
6
6
  function Pagy(){}
7
7
 
8
- Pagy.version = '5.6.1'
8
+ Pagy.version = '5.6.2'
9
9
 
10
10
  // Used by the waitForMe function
11
11
  Pagy.delay = 100
@@ -0,0 +1,22 @@
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
3
+ ta:
4
+ pagy:
5
+
6
+ item_name:
7
+ one: "பதிவு"
8
+ other: "பதிவுகள்"
9
+
10
+ nav:
11
+ prev: "‹ முந்தையது"
12
+ next: "அடுத்தது ›"
13
+ gap: "…"
14
+
15
+ info:
16
+ no_items: "%{item_name} கிடைக்கவில்லை"
17
+ single_page: "<b>%{count}</b> %{item_name} காட்டப்படுகின்றது"
18
+ multiple_pages: "மொத்தம் <b>%{count}</b> %{item_name}, காட்டப்படுபவை <b>%{from}-%{to}</b>"
19
+
20
+ combo_nav_js: "<label>%{pages}-இல் %{page_input}-வது பக்கம்</label>"
21
+
22
+ items_selector_js: "<label>ஒரு பக்கத்திற்கு %{items_input} %{item_name} காட்டு</label>"
@@ -16,12 +16,12 @@ class Pagy # :nodoc:
16
16
  @initial = new_time(@starting.year, @starting.month, @starting.day)
17
17
  @final = new_time(@ending.year, @ending.month, @ending.day) + DAY
18
18
  @pages = @last = (@final - @initial).to_i / DAY
19
- @from = start_for(@page)
19
+ @from = starting_time_for(@page)
20
20
  @to = @from + DAY
21
21
  end
22
22
 
23
- # Time for the page
24
- def start_for(page)
23
+ # Starting time for the page
24
+ def starting_time_for(page)
25
25
  @initial + (snap(page) * DAY)
26
26
  end
27
27
  end
@@ -5,7 +5,7 @@ class Pagy
5
5
  # Mixin for month based unit periods
6
6
  # It is used for month and quarter, but you could use it to implement less common unit of 6, 4, 2 months
7
7
  # (see the https://ddnexus.github.io/pagy/api/calendar#custom-units sections for details).
8
- # The class that includes it needs to set the MONTH duration for the unit and the usual DEFAULT.
8
+ # The including class must set the MONTHS duration for the unit and the usual DEFAULT.
9
9
  module MonthMixin
10
10
  protected
11
11
 
@@ -13,36 +13,34 @@ class Pagy
13
13
  def setup_unit_vars
14
14
  super
15
15
  @months = self.class::MONTHS # number of months in the unit
16
- @initial = new_time(@starting.year, beginning_month(@starting.month))
17
- @final = add_to(new_time(@ending.year, beginning_month(@ending.month)), @months)
16
+ @initial = new_time(@starting.year, starting_month_including(@starting.month))
17
+ @final = add_months_to(new_time(@ending.year, starting_month_including(@ending.month)), @months)
18
18
  @pages = @last = (months_in(@final) - months_in(@initial)) / @months
19
- @from = start_for(@page)
20
- @to = add_to(@from, @months)
19
+ @from = starting_time_for(@page)
20
+ @to = add_months_to(@from, @months)
21
21
  end
22
22
 
23
- # Time for the page
24
- def start_for(page)
25
- add_to(@initial, snap(page) * @months)
23
+ # Starting time for the page
24
+ def starting_time_for(page)
25
+ add_months_to(@initial, snap(page) * @months)
26
26
  end
27
27
 
28
- # Return the beginning month for the unit (e.g. quarter) that includes the month argument
29
- def beginning_month(month)
30
- (@months * ((month - 1) / @months)) + 1
28
+ # Starting month of the unit including the passed month
29
+ def starting_month_including(month)
30
+ (@months * ((month - 1) / @months)) + 1 # remove 1 month for 0-11 calculations and add it back for 1-12 conversion
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- # Months in time
35
+ # Number of months in time
36
36
  def months_in(time)
37
37
  (time.year * 12) + time.month
38
38
  end
39
39
 
40
40
  # Add months to time
41
- def add_to(time, months)
42
- months += months_in(time)
43
- year = months / 12
44
- month = months % 12
45
- month.zero? ? new_time(year - 1, 12) : new_time(year, month)
41
+ def add_months_to(time, months)
42
+ months += months_in(time) - 1 # remove 1 month for 0-11 calculations
43
+ new_time(months / 12, (months % 12) + 1) # add 1 month back for 1-12 conversion
46
44
  end
47
45
  end
48
46
  end
@@ -14,9 +14,9 @@ class Pagy # :nodoc:
14
14
 
15
15
  # The label for any page, with the substitution of the '%q' token
16
16
  def label_for(page, opts = {})
17
- start_time = start_for(page.to_i)
18
- opts[:format] = (opts[:format] || @vars[:format]).gsub('%q') { (start_time.month / 4) + 1 }
19
- localize(start_time, opts)
17
+ starting_time = starting_time_for(page.to_i) # page could be a string
18
+ opts[:format] = (opts[:format] || @vars[:format]).gsub('%q') { (starting_time.month / 4) + 1 }
19
+ localize(starting_time, opts)
20
20
  end
21
21
  end
22
22
  end
@@ -18,12 +18,12 @@ class Pagy # :nodoc:
18
18
  @initial = week_start(@starting)
19
19
  @final = week_start(@ending) + WEEK
20
20
  @pages = @last = (@final - @initial).to_i / WEEK
21
- @from = start_for(@page)
21
+ @from = starting_time_for(@page)
22
22
  @to = @from + WEEK
23
23
  end
24
24
 
25
- # Time for the page
26
- def start_for(page)
25
+ # Starting time for the page
26
+ def starting_time_for(page)
27
27
  @initial + (snap(page) * WEEK)
28
28
  end
29
29
 
@@ -16,12 +16,12 @@ class Pagy # :nodoc:
16
16
  @initial = new_time(@starting.year)
17
17
  @final = new_time(@ending.year + 1)
18
18
  @pages = @last = @final.year - @initial.year
19
- @from = start_for(@page)
19
+ @from = starting_time_for(@page)
20
20
  @to = new_time(@from.year + 1)
21
21
  end
22
22
 
23
- # Time for the page
24
- def start_for(page)
23
+ # Starting time for the page
24
+ def starting_time_for(page)
25
25
  new_time(@initial.year + snap(page))
26
26
  end
27
27
  end
data/lib/pagy/calendar.rb CHANGED
@@ -36,7 +36,7 @@ class Pagy # :nodoc:
36
36
  # The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
37
37
  def label_for(page, opts = {})
38
38
  opts[:format] ||= @vars[:format]
39
- localize(start_for(page.to_i), opts)
39
+ localize(starting_time_for(page.to_i), opts) # page could be a string
40
40
  end
41
41
 
42
42
  # Period of the active page (used for nested units)
data/lib/pagy/frontend.rb CHANGED
@@ -76,8 +76,8 @@ class Pagy
76
76
 
77
77
  # Similar to I18n.t: just ~18x faster using ~10x less memory
78
78
  # (@pagy_locale explicitly initialized in order to avoid warning)
79
- def pagy_t(key, **opts)
80
- Pagy::I18n.t(@pagy_locale ||= nil, key, **opts)
79
+ def pagy_t(key, opts = {})
80
+ Pagy::I18n.t(@pagy_locale ||= nil, key, opts)
81
81
  end
82
82
  end
83
83
  end
data/lib/pagy/i18n.rb CHANGED
@@ -10,12 +10,16 @@ class Pagy
10
10
 
11
11
  # Pluralization rules
12
12
  module P11n
13
- # Utility variables
14
- from0to1 = [0, 1].freeze
15
- from2to4 = [2, 3, 4].freeze
16
- from5to9 = [5, 6, 7, 8, 9].freeze
17
- from11to14 = [11, 12, 13, 14].freeze
18
- from12to14 = [12, 13, 14].freeze
13
+ # Pluralization variables
14
+ from0to1 = (0..1).to_a.freeze
15
+ from2to4 = (2..4).to_a.freeze
16
+ from3to10 = (3..10).to_a.freeze
17
+ from5to9 = (5..9).to_a.freeze
18
+ from11to14 = (11..14).to_a.freeze
19
+ from11to99 = (11..99).to_a.freeze
20
+ from12to14 = (12..14).to_a.freeze
21
+
22
+ from0to1_from5to9 = from0to1 + from5to9
19
23
 
20
24
  # Store the proc defining each pluralization RULE
21
25
  # Logic adapted from https://github.com/svenfuchs/rails-i18n
@@ -24,12 +28,12 @@ class Pagy
24
28
  lambda do |n = 0|
25
29
  mod100 = n % 100
26
30
  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'
31
+ when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
32
+ when n == 1 then 'one'
33
+ when n == 2 then 'two'
34
+ when from3to10.include?(mod100) then 'few'
35
+ when from11to99.include?(mod100) then 'many'
36
+ else 'other'
33
37
  end
34
38
  end,
35
39
 
@@ -68,10 +72,10 @@ class Pagy
68
72
  mod10 = n % 10
69
73
  mod100 = n % 100
70
74
  case
71
- when n == 1 then 'one'
72
- when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
73
- when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
74
- else 'other'
75
+ when n == 1 then 'one'
76
+ when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
77
+ when from0to1_from5to9.include?(mod10) || from12to14.include?(mod100) then 'many'
78
+ else 'other'
75
79
  end
76
80
  end,
77
81
 
@@ -149,7 +153,7 @@ class Pagy
149
153
  end
150
154
 
151
155
  # Translate and pluralize the key with the locale DATA
152
- def t(locale, key, **opts)
156
+ def t(locale, key, opts = {})
153
157
  data, pluralize = DATA[locale]
154
158
  translation = data[key] || (opts[:count] && data[key += ".#{pluralize.call(opts[:count])}"]) \
155
159
  or return %([translation missing: "#{key}"])
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # Core class
7
7
  class Pagy
8
- VERSION = '5.6.1'
8
+ VERSION = '5.6.2'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
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: 5.6.1
4
+ version: 5.6.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: 2021-11-28 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Agnostic pagination in plain ruby. It does it all. Better.
14
14
  email:
@@ -46,6 +46,7 @@ files:
46
46
  - lib/locales/sv-SE.yml
47
47
  - lib/locales/sv.yml
48
48
  - lib/locales/sw.yml
49
+ - lib/locales/ta.yml
49
50
  - lib/locales/tr.yml
50
51
  - lib/locales/uk.yml
51
52
  - lib/locales/zh-CN.yml