pagy 5.5.0 → 5.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c55595ac8caaa34c73688103333dc62e9ebb395696725e7c305e5ace3d7f42
4
- data.tar.gz: 3e259f8f72025fc7955fb6107920be08025539d5178e5c4c714173d26aa05da1
3
+ metadata.gz: 0a24ac286e97d1aacd7603d7ada3791006120004bf56c027320c4184b9488fc7
4
+ data.tar.gz: 63a018d758c2ffff334de22fc8fdd433cdffe74030ba46ca5c3cf5dc8a563a9c
5
5
  SHA512:
6
- metadata.gz: fede5003b2a686ee972d7dd93a80b5221704518212adb8faa7b133c309b2ece0094f3fbe72575fb4e29b706a819f5dc447fc6f3a89b4c3fe202e23542dfee310
7
- data.tar.gz: 15840445b0afa7e343c9f0f4ad196b847cb564d8d2a5da56b94a9a59ac348731fc6bb104c282343f77654a0d07090dd501957e751c843c88de208779581dbbae
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.5.0)
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,24 +40,27 @@
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, 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
47
- # Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination
48
- # Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format
47
+ # Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination
48
+ # Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format
49
49
  #
50
- # Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
51
- # Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
50
+ # Pagy::Calendar::Quarter::DEFAULT[:order] = :asc # Time direction of pagination
51
+ # Pagy::Calendar::Quarter::DEFAULT[:format] = '%Y-Q%q' # strftime format
52
52
  #
53
- # Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination
54
- # Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format
55
- # Pagy::Calendar::Week::DEFAULT[:offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
53
+ # Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
54
+ # Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
56
55
  #
57
- # Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
58
- # Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
56
+ # Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination
57
+ # Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format
58
+ # Pagy::Calendar::Week::DEFAULT[:offset] = 0 # Day offset from Sunday (0: Sunday; 1: Monday;... 6: Saturday)
59
59
  #
60
- # Uncomment the following block, if you need calendar localization without using the I18n extra
60
+ # Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
61
+ # Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
62
+ #
63
+ # Uncomment the following lines, if you need calendar localization without using the I18n extra
61
64
  # module LocalizePagyCalendar
62
65
  # def localize(time, opts)
63
66
  # ::I18n.l(time, **opts)
@@ -97,8 +100,8 @@
97
100
  # you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
98
101
  # require 'pagy/extras/shared'
99
102
  # require 'pagy/extras/metadata'
100
- # For performance reason, you should explicitly set ONLY the metadata you use in the frontend
101
- # 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
102
105
 
103
106
  # Searchkick extra: Paginate `Searchkick::Results` objects
104
107
  # See https://ddnexus.github.io/pagy/extras/searchkick
@@ -209,18 +212,18 @@
209
212
  #
210
213
  # load the "de", "en" and "es" built-in locales:
211
214
  # (the first passed :locale will be used also as the default_locale)
212
- # Pagy::I18n.load({locale: 'de'},
213
- # {locale: 'en'},
214
- # {locale: 'es'})
215
+ # Pagy::I18n.load({ locale: 'de' },
216
+ # { locale: 'en' },
217
+ # { locale: 'es' })
215
218
  #
216
219
  # load the "en" built-in locale, a custom "es" locale,
217
220
  # and a totally custom locale complete with a custom :pluralize proc:
218
221
  # (the first passed :locale will be used also as the default_locale)
219
- # Pagy::I18n.load({locale: 'en'},
220
- # {locale: 'es', filepath: 'path/to/pagy-es.yml'},
221
- # {locale: 'xyz', # not built-in
222
- # filepath: 'path/to/pagy-xyz.yml',
223
- # 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| ... } )
224
227
 
225
228
 
226
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.5.0'
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 = time_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 time_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
@@ -1,44 +1,16 @@
1
1
  # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
2
2
  # frozen_string_literal: true
3
3
 
4
+ require_relative 'month_mixin'
5
+
4
6
  class Pagy # :nodoc:
5
7
  class Calendar # :nodoc:
6
8
  # Calendar month subclass
7
9
  class Month < Calendar
8
10
  DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
9
11
  format: '%Y-%m' }
10
-
11
- protected
12
-
13
- # Setup the calendar variables
14
- def setup_unit_vars
15
- super
16
- @initial = new_time(@starting.year, @starting.month)
17
- @final = bump_month(@ending)
18
- @pages = @last = months(@final) - months(@initial)
19
- @from = time_for(@page)
20
- @to = bump_month(@from)
21
- end
22
-
23
- # Time for the page
24
- def time_for(page)
25
- bump_month(@initial, snap(page))
26
- end
27
-
28
- private
29
-
30
- # Months in local time
31
- def months(time)
32
- (time.year * 12) + time.month
33
- end
34
-
35
- # Add 1 or more months to local time
36
- def bump_month(time, months = 1)
37
- months += months(time)
38
- year = months / 12
39
- month = months % 12
40
- month.zero? ? new_time(year - 1, 12) : new_time(year, month)
41
- end
12
+ MONTHS = 1 # number of months in the unit
13
+ include MonthMixin
42
14
  end
43
15
  end
44
16
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+ class Calendar
5
+ # Mixin for month based unit periods
6
+ # It is used for month and quarter, but you could use it to implement less common unit of 6, 4, 2 months
7
+ # (see the https://ddnexus.github.io/pagy/api/calendar#custom-units sections for details).
8
+ # The including class must set the MONTHS duration for the unit and the usual DEFAULT.
9
+ module MonthMixin
10
+ protected
11
+
12
+ # Setup the calendar variables
13
+ def setup_unit_vars
14
+ super
15
+ @months = self.class::MONTHS # number of months in the unit
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
+ @pages = @last = (months_in(@final) - months_in(@initial)) / @months
19
+ @from = starting_time_for(@page)
20
+ @to = add_months_to(@from, @months)
21
+ end
22
+
23
+ # Starting time for the page
24
+ def starting_time_for(page)
25
+ add_months_to(@initial, snap(page) * @months)
26
+ end
27
+
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
+ end
32
+
33
+ private
34
+
35
+ # Number of months in time
36
+ def months_in(time)
37
+ (time.year * 12) + time.month
38
+ end
39
+
40
+ # Add months to time
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
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ # See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/api/calendar
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'month_mixin'
5
+
6
+ class Pagy # :nodoc:
7
+ class Calendar # :nodoc:
8
+ # Calendar quarter subclass
9
+ class Quarter < Calendar
10
+ DEFAULT = { order: :asc, # rubocop:disable Style/MutableConstant
11
+ format: '%Y-Q%q' } # '%q' token
12
+ MONTHS = 3 # number of months of the unit
13
+ include MonthMixin
14
+
15
+ # The label for any page, with the substitution of the '%q' token
16
+ def label_for(page, 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
+ end
21
+ end
22
+ end
23
+ end
@@ -18,18 +18,18 @@ 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 = time_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 time_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
 
30
30
  private
31
31
 
32
- # Return the start of the week for local time
32
+ # Return the start of the week for time
33
33
  def week_start(time)
34
34
  start = time - (((time.wday - @offset) * DAY) % WEEK)
35
35
  new_time(start.year, start.month, start.day)
@@ -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 = time_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 time_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
@@ -4,10 +4,12 @@
4
4
  require 'pagy'
5
5
 
6
6
  class Pagy # :nodoc:
7
- # Base class for time units subclasses (Year, Month, Week, Day)
7
+ # Base class for time units subclasses (Year, Quarter, Month, Week, Day)
8
8
  class Calendar < Pagy
9
- DAY = 60 * 60 * 24
10
- WEEK = DAY * 7
9
+ # List of units in desc order of duration. It can be used for custom units.
10
+ UNITS = %i[year quarter month week day] # rubocop:disable Style/MutableConstant
11
+ DAY = 60 * 60 * 24 # One day in seconds
12
+ WEEK = DAY * 7 # One week in seconds
11
13
 
12
14
  attr_reader :order
13
15
 
@@ -15,8 +17,8 @@ class Pagy # :nodoc:
15
17
  def initialize(vars) # rubocop:disable Lint/MissingSuper
16
18
  raise InternalError, 'Pagy::Calendar is a base class; use one of its subclasses' if instance_of?(Pagy::Calendar)
17
19
 
18
- normalize_vars(vars)
19
- @vars = self.class::DEFAULT.merge(@vars)
20
+ vars = self.class::DEFAULT.merge(vars) # subclass specific default
21
+ normalize_vars(vars) # general default
20
22
  setup_vars(page: 1)
21
23
  setup_unit_vars
22
24
  setup_params_var
@@ -27,19 +29,19 @@ class Pagy # :nodoc:
27
29
  end
28
30
 
29
31
  # The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
30
- def label(**opts)
31
- label_for(@page, **opts)
32
+ def label(opts = {})
33
+ label_for(@page, opts)
32
34
  end
33
35
 
34
36
  # The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
35
- def label_for(page, **opts)
37
+ def label_for(page, opts = {})
36
38
  opts[:format] ||= @vars[:format]
37
- localize(time_for(page.to_i), **opts)
39
+ localize(starting_time_for(page.to_i), opts) # page could be a string
38
40
  end
39
41
 
40
42
  # Period of the active page (used for nested units)
41
43
  def active_period
42
- [[@starting, @from].max, [@to - DAY, @ending].min] # include only last unit day
44
+ [[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
43
45
  end
44
46
 
45
47
  protected
@@ -61,8 +63,7 @@ class Pagy # :nodoc:
61
63
  time.strftime(opts[:format])
62
64
  end
63
65
 
64
- # Simple trick to snap the page into its ordered position, without actually reordering anything in the internal structure.
65
- # Tech note: use for @from but not for @to, which must be one period after @from also in :desc order!
66
+ # Simple trick to snap the page to its ordered start, without actually reordering anything in the internal structure
66
67
  def snap(page)
67
68
  @order == :asc ? page - 1 : @pages - page
68
69
  end
@@ -71,20 +72,18 @@ class Pagy # :nodoc:
71
72
  def new_time(year, month = 1, day = 1)
72
73
  Time.new(year, month, day, 0, 0, 0, @utc_offset)
73
74
  end
74
- end
75
- require 'pagy/calendar/year'
76
- require 'pagy/calendar/month'
77
- require 'pagy/calendar/week'
78
- require 'pagy/calendar/day'
79
-
80
- class Calendar # :nodoc:
81
- UNITS = { year: Year, month: Month, week: Week, day: Day }.freeze
82
75
 
83
- # Create a subclass instance by unit name (internal use)
84
- def self.create(unit, vars)
85
- raise InternalError, "unit must be in #{UNITS.keys.inspect}; got #{unit}" unless UNITS.key?(unit)
76
+ class << self
77
+ # Create a subclass instance by unit name (internal use)
78
+ def create(unit, vars)
79
+ raise InternalError, "unit must be in #{UNITS.inspect}; got #{unit}" unless UNITS.include?(unit)
86
80
 
87
- UNITS[unit].new(vars)
81
+ name = unit.to_s
82
+ name[0] = name[0].capitalize
83
+ Object.const_get("Pagy::Calendar::#{name}").new(vars)
84
+ end
88
85
  end
89
86
  end
87
+
88
+ Calendar::UNITS.each { |unit| require "pagy/calendar/#{unit}" }
90
89
  end
@@ -8,11 +8,11 @@ class Pagy # :nodoc:
8
8
  module CalendarExtra
9
9
  # Additions for the Backend module
10
10
  module Backend
11
- CONF_KEYS = %i[year month week day pagy active].freeze
11
+ CONF_KEYS = (Calendar::UNITS + %i[pagy active]).freeze
12
12
 
13
13
  private
14
14
 
15
- # Take a collection and a conf Hash with keys in [:year, :month: week, :day, :pagy: :active];
15
+ # Take a collection and a conf Hash with keys in [:year, :quarter, :month: week, :day, :pagy: :active];
16
16
  # The calendar is active by default, but it can be explicitly inactivated with `active: false`
17
17
  # Return a hash with 3 items:
18
18
  # 0. Array of pagy calendar unit objects
@@ -31,7 +31,7 @@ class Pagy # :nodoc:
31
31
 
32
32
  # Setup and return the calendar objects and the filtered collection
33
33
  def pagy_setup_calendar(collection, conf)
34
- units = Calendar::UNITS.keys & conf.keys
34
+ units = Calendar::UNITS & conf.keys # get the units in time length desc order
35
35
  page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
36
36
  units.each do |unit| # set all the :page_param vars for later deletion
37
37
  unit_page_param = :"#{unit}_#{page_param}"
@@ -47,7 +47,7 @@ class Pagy # :nodoc:
47
47
  params
48
48
  end
49
49
  conf[unit][:period] = period
50
- calendar[unit] = Calendar.create(unit, conf[unit])
50
+ calendar[unit] = Calendar.send(:create, unit, conf[unit])
51
51
  period = calendar[unit].active_period # set the period for the next unit
52
52
  end
53
53
  [calendar, pagy_calendar_filter(collection, calendar[units.last].from, calendar[units.last].to)]
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.5.0'
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
@@ -5,7 +5,7 @@
5
5
  The link variable is set to a proc that returns the link tag.
6
6
  Usage: link.call( page_number [, text [, extra_attributes_string ]])
7
7
  -%>
8
- <% link = pagy_link_proc(pagy, 'class="page-link"') -%>
8
+ <% link = pagy_link_proc(pagy, link_extra: 'class="page-link"') -%>
9
9
  <%# -%><nav aria-label="pager" class="pagy-bootstrap-nav" role="navigation">
10
10
  <%# -%> <ul class="pagination">
11
11
  <% if pagy.prev -%> <li class="page-item prev"><%== link.call(pagy.prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"') %></li>
@@ -4,7 +4,7 @@
4
4
  -# The link variable is set to a proc that returns the link tag.
5
5
  -# Usage: link.call( page_number [, text [, extra_attributes_string ]])
6
6
 
7
- - link = pagy_link_proc(pagy, 'class="page-link"')
7
+ - link = pagy_link_proc(pagy, link_extra: 'class="page-link"')
8
8
 
9
9
  %nav.pagy-bootstrap-nav{"aria-label" => "pager", :role => "navigation"}
10
10
 
@@ -4,7 +4,7 @@
4
4
  / The link variable is set to a proc that returns the link tag.
5
5
  / Usage: link.call( page_number [, text [, extra_attributes_string ]])
6
6
 
7
- - link = pagy_link_proc(pagy, 'class="page-link"')
7
+ - link = pagy_link_proc(pagy, link_extra: 'class="page-link"')
8
8
 
9
9
  nav.pagy-bootstrap-nav role="navigation" aria-label="pager"
10
10
 
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.5.0
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-22 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
@@ -56,6 +57,8 @@ files:
56
57
  - lib/pagy/calendar.rb
57
58
  - lib/pagy/calendar/day.rb
58
59
  - lib/pagy/calendar/month.rb
60
+ - lib/pagy/calendar/month_mixin.rb
61
+ - lib/pagy/calendar/quarter.rb
59
62
  - lib/pagy/calendar/week.rb
60
63
  - lib/pagy/calendar/year.rb
61
64
  - lib/pagy/console.rb