pagy 4.8.1 → 4.10.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: c87ea4c3c1bf0dbfb6ae76db111177cda391165a844ff3302f8ee2722249ef2f
4
- data.tar.gz: 26618714b6555f46cb9c140166b3407efb350bf8263cfcb8bdd4bde293265ca9
3
+ metadata.gz: af9dd0bcf50c1a54209d29f8a13318fc72f0cb76f07a1ff4e5df04c42e2a0712
4
+ data.tar.gz: 16ec5ce47444e7ef5adc3a3db977dbdf9a518cbec5da0e3d0454c1e33433faae
5
5
  SHA512:
6
- metadata.gz: 5e0026cc9cb9051f43c3b89a3d68bde3fbb738ea21055117da0427e0dba9eae6c1d501dcd76d5dadd68890609fde321d33372fe8c949cf8c03c3388e4aa61317
7
- data.tar.gz: 643f315b5de922a30f47f70465e7e13d7a5837835b6da90cf52cdf491eaec75f66450678094a3cbef0f38d65afd280ddafec0e0dc16dc52a479e324b896655dd
6
+ metadata.gz: eb9bcf0b26ef773511e98ab5985a9ce0b4639e79deb60ca2a45ed79cbf6beca5145e032d30907cd4453085a6f2b8072580c4ec4fabd8a788c61037d243e51dc0
7
+ data.tar.gz: 2219496ad2c296a6fe3a93b7380696b29b7c77e16a6b4731d5322aa9df4be0bbf3433355f8780122be72c3149242d52afb617328d14c53522ec1b2f697b39323
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (4.8.1)
3
+ # Pagy initializer file (4.10.2)
4
4
  # Customize only what you really need and notice that 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
 
@@ -56,6 +56,9 @@
56
56
  # also the elasticsearch_rails extra that defines the same
57
57
  # VARS[:searchkick_search_method] = :pagy_search
58
58
  # require 'pagy/extras/searchkick'
59
+ # uncomment if you are going to use Searchkick.pagy_search
60
+ # Searchkick.extend Pagy::Searchkick
61
+
59
62
 
60
63
  # Frontend Extras
61
64
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '4.8.1'
5
+ Pagy.version = '4.10.2'
6
6
 
7
7
  Pagy.delay = 100
8
8
 
@@ -114,4 +114,8 @@ Pagy.waitForMe =
114
114
  Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay)
115
115
  }
116
116
 
117
- window.addEventListener('resize', Pagy.waitForMe, true)
117
+
118
+ if (typeof window !== "undefined") {
119
+ window.addEventListener('resize', Pagy.waitForMe, true)
120
+ }
121
+
@@ -0,0 +1,26 @@
1
+ # :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
3
+ ar:
4
+ pagy:
5
+
6
+ item_name:
7
+ zero: "صفر"
8
+ one: "عنصر"
9
+ two: "عنصرين"
10
+ few: "قليل"
11
+ many: "كثير"
12
+ other: "عناصر"
13
+
14
+ nav:
15
+ prev: "‹ السابق"
16
+ next: "التالي ›"
17
+ gap: "…"
18
+
19
+ info:
20
+ no_items: "لا يوجد %{item_name}"
21
+ single_page: "عرض <b>%{count}</b> %{item_name}"
22
+ multiple_pages: "عرض %{item_name} <b>%{from}-%{to}</b> من اجمالي <b>%{count}</b>"
23
+
24
+ combo_nav_js: "الصفحة %{page_input} من %{pages}"
25
+
26
+ items_selector_js: "عرض %{items_input} %{item_name} لكل صفحة"
@@ -19,6 +19,20 @@ from12to14 = [12,13,14].freeze
19
19
  p11n = {
20
20
  one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
21
21
 
22
+ arabic: lambda do |n|
23
+ n ||= 0
24
+ mod100 = n % 100
25
+
26
+ 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'
33
+ end
34
+ end,
35
+
22
36
  east_slavic: lambda do |n|
23
37
  n ||= 0
24
38
  mod10 = n % 10
@@ -32,14 +46,6 @@ p11n = {
32
46
  end
33
47
  end,
34
48
 
35
- west_slavic: lambda do |n|
36
- case n
37
- when 1 then 'one'
38
- when 2, 3, 4 then 'few'
39
- else 'other'
40
- end
41
- end,
42
-
43
49
  one_two_other: lambda do |n|
44
50
  case n
45
51
  when 1 then 'one'
@@ -63,7 +69,16 @@ p11n = {
63
69
  when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
64
70
  else 'other'
65
71
  end
72
+ end,
73
+
74
+ west_slavic: lambda do |n|
75
+ case n
76
+ when 1 then 'one'
77
+ when 2, 3, 4 then 'few'
78
+ else 'other'
79
+ end
66
80
  end
81
+
67
82
  }
68
83
 
69
84
  # Hash of locale/pluralization pairs
@@ -71,6 +86,7 @@ p11n = {
71
86
  # The default pluralization for locales not explicitly listed here
72
87
  # is the :one_other pluralization proc (used for English)
73
88
  plurals = Hash.new(p11n[:one_other]).tap do |hash|
89
+ hash['ar'] = p11n[:arabic]
74
90
  hash['bs'] = p11n[:east_slavic]
75
91
  hash['cs'] = p11n[:west_slavic]
76
92
  hash['id'] = p11n[:other]
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # main class
7
7
  class Pagy
8
- VERSION = '4.8.1'
8
+ VERSION = '4.10.2'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+
5
+ VARS[:meilisearch_search_method] ||= :pagy_search
6
+
7
+ module Meilisearch
8
+ # returns an array used to delay the call of #search
9
+ # after the pagination variables are merged to the options
10
+ def pagy_meilisearch(term = nil, **vars)
11
+ [self, term, vars]
12
+ end
13
+ alias_method VARS[:meilisearch_search_method], :pagy_meilisearch
14
+ end
15
+
16
+ # create a Pagy object from a Meilisearch results
17
+ def self.new_from_meilisearch(results, vars={})
18
+ vars[:items] = results.raw_answer['limit']
19
+ vars[:page] = [results.raw_answer['offset'] / vars[:items], 1].max
20
+ vars[:count] = results.raw_answer['nbHits']
21
+ new(vars)
22
+ end
23
+
24
+ # Add specialized backend methods to paginate Meilisearch results
25
+ module Backend
26
+ private
27
+
28
+ # Return Pagy object and results
29
+ def pagy_meilisearch(pagy_search_args, vars = {})
30
+ model, term, options = pagy_search_args
31
+ vars = pagy_meilisearch_get_vars(nil, vars)
32
+ options[:limit] = vars[:items]
33
+ options[:offset] = (vars[:page] - 1) * vars[:items]
34
+ results = model.search(term, **options)
35
+ vars[:count] = results.raw_answer['nbHits']
36
+
37
+ pagy = Pagy.new(vars)
38
+ # with :last_page overflow we need to re-run the method in order to get the hits
39
+ return pagy_meilisearch(pagy_search_args, vars.merge(page: pagy.page)) \
40
+ if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
41
+
42
+ [ pagy, results ]
43
+ end
44
+
45
+ # Sub-method called only by #pagy_meilisearch: here for easy customization of variables by overriding
46
+ # the _collection argument is not available when the method is called
47
+ def pagy_meilisearch_get_vars(_collection, vars)
48
+ pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
49
+ vars[:items] ||= VARS[:items]
50
+ vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
51
+ vars
52
+ end
53
+
54
+ end
55
+ end
@@ -14,10 +14,14 @@ class Pagy
14
14
  lambda do |num, text=num, extra=''|
15
15
  link = +link_proc.call(num, text, extra)
16
16
  return link unless num == 1
17
- link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
17
+ pagy_trim(pagy, link)
18
18
  end
19
19
  end
20
20
 
21
+ def pagy_trim(pagy, link)
22
+ link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
23
+ end
24
+
21
25
  end
22
26
  Frontend.prepend UseTrimExtra
23
27
 
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: 4.8.1
4
+ version: 4.10.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-06-14 00:00:00.000000000 Z
11
+ date: 2021-08-18 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,
@@ -22,6 +22,7 @@ files:
22
22
  - LICENSE.txt
23
23
  - lib/config/pagy.rb
24
24
  - lib/javascripts/pagy.js
25
+ - lib/locales/ar.yml
25
26
  - lib/locales/bg.yml
26
27
  - lib/locales/bs.yml
27
28
  - lib/locales/ca.yml
@@ -72,6 +73,7 @@ files:
72
73
  - lib/pagy/extras/i18n.rb
73
74
  - lib/pagy/extras/items.rb
74
75
  - lib/pagy/extras/materialize.rb
76
+ - lib/pagy/extras/meilisearch.rb
75
77
  - lib/pagy/extras/metadata.rb
76
78
  - lib/pagy/extras/navs.rb
77
79
  - lib/pagy/extras/overflow.rb
@@ -117,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  - !ruby/object:Gem::Version
118
120
  version: '0'
119
121
  requirements: []
120
- rubygems_version: 3.2.15
122
+ rubygems_version: 3.2.3
121
123
  signing_key:
122
124
  specification_version: 4
123
125
  summary: The Ultimate Pagination Ruby Gem