pagy 5.6.4 → 5.6.5

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: 5436ee5b008a1f9db93ba52363fbae559f6444600c5925fcd87541b606e2a8ad
4
- data.tar.gz: 6159c1b56724cf1e10af6c15c2a141200d1795ed3da6fa6655cb1e7ee3f7056c
3
+ metadata.gz: 3bc0ec346bfde6c907da343d7c3f7ad611cbb69f4ed8e36aa09b69b48276ecb6
4
+ data.tar.gz: 9d936c804c00f7eb530c9a7f5d1ecf763704daf84e35b9a3288eae2f88d3e3be
5
5
  SHA512:
6
- metadata.gz: 6d2e0aa3e7a4a9bfee7b4360b1d6ae35d931a1aa7fd4959436adf78cb43c153149ebb80455d9a63f7ef36558c5d673191fcd5ad10ce7e4be2e75ca42be645d05
7
- data.tar.gz: ee07cd90d3908f52c879cebf1956ee5cb1c12739b21e4a0519e7a8432e3ead0304a2bca94ca6a9444035e72563e2de2dd4a5191c279183fad39d22b7703babae
6
+ metadata.gz: a2e92a735ed04def206a2cdd81577ff39042cc03f98a4343b6e8889c008bb5ba8277bd76168b1d3f39067bc68b9e9b4b1805721cac9a12cded2a491b106023db
7
+ data.tar.gz: 825ad4c0c076d4dae52ba69772b0c827662181ddd9bd077c41ec5a167b0da506bf7153493a99ab5a704043f08918b1d0e460430c8fa7ee08d0675b1f3d1a5619
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.6.4)
3
+ # Pagy initializer file (5.6.5)
4
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
 
@@ -5,7 +5,7 @@
5
5
  // Container for the whole pagy stuff
6
6
  function Pagy(){}
7
7
 
8
- Pagy.version = '5.6.4'
8
+ Pagy.version = '5.6.5'
9
9
 
10
10
  // Used by the waitForMe function
11
11
  Pagy.delay = 100
data/lib/pagy/backend.rb CHANGED
@@ -8,7 +8,7 @@ class Pagy
8
8
  module Backend
9
9
  private
10
10
 
11
- # Return Pagy object and items
11
+ # Return Pagy object and paginated items/results
12
12
  def pagy(collection, vars = {})
13
13
  pagy = Pagy.new(pagy_get_vars(collection, vars))
14
14
  [pagy, pagy_get_items(collection, pagy)]
data/lib/pagy/calendar.rb CHANGED
@@ -41,7 +41,7 @@ class Pagy # :nodoc:
41
41
 
42
42
  protected
43
43
 
44
- # Base class method for the setup of the unit variables
44
+ # Base class method for the setup of the unit variables (subclasses must implement it and call super)
45
45
  def setup_unit_vars
46
46
  raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
47
47
  raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
@@ -85,6 +85,6 @@ class Pagy # :nodoc:
85
85
  end
86
86
  end
87
87
  end
88
-
88
+ # Require the subclass files in UNITS (no custom unit at this point yet)
89
89
  Calendar::UNITS.each { |unit| require "pagy/calendar/#{unit}" }
90
90
  end
@@ -6,11 +6,13 @@ class Pagy # :nodoc:
6
6
  module ArelExtra
7
7
  private
8
8
 
9
+ # Return Pagy object and paginated collection/results
9
10
  def pagy_arel(collection, vars = {})
10
11
  pagy = Pagy.new(pagy_arel_get_vars(collection, vars))
11
12
  [pagy, pagy_get_items(collection, pagy)]
12
13
  end
13
14
 
15
+ # Sub-method called only by #pagy_arel: here for easy customization of variables by overriding
14
16
  def pagy_arel_get_vars(collection, vars)
15
17
  pagy_set_items_from_params(vars) if defined?(ItemsExtra)
16
18
  vars[:count] ||= pagy_arel_count(collection)
@@ -18,6 +20,7 @@ class Pagy # :nodoc:
18
20
  vars
19
21
  end
20
22
 
23
+ # Count using Arel when grouping
21
24
  def pagy_arel_count(collection)
22
25
  if collection.group_values.empty?
23
26
  # COUNT(*)
@@ -6,7 +6,7 @@ class Pagy # :nodoc:
6
6
  module ArrayExtra
7
7
  private
8
8
 
9
- # Return Pagy object and items
9
+ # Return Pagy object and paginated items
10
10
  def pagy_array(array, vars = {})
11
11
  pagy = Pagy.new(pagy_array_get_vars(array, vars))
12
12
  [pagy, array[pagy.offset, pagy.items]]
@@ -26,7 +26,9 @@ class Pagy # :nodoc:
26
26
 
27
27
  # Setup and return the calendar objects and the filtered collection
28
28
  def pagy_setup_calendar(collection, conf)
29
- units = Calendar::UNITS & conf.keys # get the units in time length desc order
29
+ units = Calendar::UNITS & conf.keys # get the units in time length desc order
30
+ raise ArgumentError, 'no calendar unit found in pagy_calendar configuration' if units.empty?
31
+
30
32
  page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
31
33
  units.each do |unit| # set all the :page_param vars for later deletion
32
34
  unit_page_param = :"#{unit}_#{page_param}"
@@ -4,14 +4,14 @@
4
4
  class Pagy # :nodoc:
5
5
  # Use ::I18n gem
6
6
  module I18nExtra
7
- # Frontend overriding
7
+ # Frontend overriding for translation
8
8
  module Frontend
9
9
  def pagy_t(key, **opts)
10
10
  ::I18n.t(key, **opts)
11
11
  end
12
12
  end
13
13
 
14
- # Calendar overriding
14
+ # Calendar overriding for localization (see also the block in the calendar section of the config/pagy.rb initializer)
15
15
  module Calendar
16
16
  def localize(time, opts)
17
17
  ::I18n.l(time, **opts)
data/lib/pagy/frontend.rb CHANGED
@@ -77,7 +77,7 @@ class Pagy
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
79
  def pagy_t(key, opts = {})
80
- Pagy::I18n.t(@pagy_locale ||= nil, key, opts)
80
+ Pagy::I18n.translate(@pagy_locale ||= nil, key, opts)
81
81
  end
82
82
  end
83
83
  end
data/lib/pagy/i18n.rb CHANGED
@@ -153,11 +153,12 @@ class Pagy
153
153
  end
154
154
 
155
155
  # Translate and pluralize the key with the locale DATA
156
- def t(locale, key, opts = {})
156
+ def translate(locale, key, opts = {})
157
157
  data, pluralize = DATA[locale]
158
158
  translation = data[key] || (opts[:count] && data[key += ".#{pluralize.call(opts[:count])}"]) \
159
159
  or return %([translation missing: "#{key}"])
160
160
  translation.gsub(/%{[^}]+?}/) { |match| opts[:"#{match[2..-2]}"] || match }
161
161
  end
162
+ alias t translate
162
163
  end
163
164
  end
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.4'
8
+ VERSION = '5.6.5'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -76,6 +76,7 @@ class Pagy
76
76
  page.to_s
77
77
  end
78
78
 
79
+ # Allow the customization of the output (overridden by the calendar extra)
79
80
  def label
80
81
  @page.to_s
81
82
  end
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.4
4
+ version: 5.6.5
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-12-03 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Agnostic pagination in plain ruby. It does it all. Better.
14
14
  email: