pagy 4.11.0 → 6.0.0

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/config/pagy.rb +119 -58
  4. data/lib/javascripts/pagy-dev.js +114 -0
  5. data/lib/javascripts/pagy-module.d.ts +5 -0
  6. data/lib/javascripts/pagy-module.js +113 -0
  7. data/lib/javascripts/pagy.js +1 -121
  8. data/lib/locales/de.yml +1 -1
  9. data/lib/locales/ko.yml +1 -1
  10. data/lib/locales/nn.yml +22 -0
  11. data/lib/locales/ta.yml +22 -0
  12. data/lib/pagy/backend.rb +10 -13
  13. data/lib/pagy/calendar/day.rb +39 -0
  14. data/lib/pagy/calendar/helper.rb +61 -0
  15. data/lib/pagy/calendar/month.rb +40 -0
  16. data/lib/pagy/calendar/quarter.rb +47 -0
  17. data/lib/pagy/calendar/week.rb +39 -0
  18. data/lib/pagy/calendar/year.rb +33 -0
  19. data/lib/pagy/calendar.rb +100 -0
  20. data/lib/pagy/console.rb +6 -4
  21. data/lib/pagy/countless.rb +22 -23
  22. data/lib/pagy/exceptions.rb +14 -16
  23. data/lib/pagy/extras/arel.rb +11 -7
  24. data/lib/pagy/extras/array.rb +9 -9
  25. data/lib/pagy/extras/bootstrap.rb +45 -38
  26. data/lib/pagy/extras/bulma.rb +50 -38
  27. data/lib/pagy/extras/calendar.rb +49 -0
  28. data/lib/pagy/extras/countless.rb +15 -18
  29. data/lib/pagy/extras/elasticsearch_rails.rb +67 -48
  30. data/lib/pagy/extras/foundation.rb +39 -35
  31. data/lib/pagy/extras/frontend_helpers.rb +72 -0
  32. data/lib/pagy/extras/gearbox.rb +54 -0
  33. data/lib/pagy/extras/headers.rb +30 -20
  34. data/lib/pagy/extras/i18n.rb +15 -13
  35. data/lib/pagy/extras/items.rb +42 -40
  36. data/lib/pagy/extras/materialize.rb +40 -38
  37. data/lib/pagy/extras/meilisearch.rb +53 -44
  38. data/lib/pagy/extras/metadata.rb +15 -20
  39. data/lib/pagy/extras/navs.rb +35 -34
  40. data/lib/pagy/extras/overflow.rb +62 -61
  41. data/lib/pagy/extras/searchkick.rb +54 -46
  42. data/lib/pagy/extras/semantic.rb +42 -40
  43. data/lib/pagy/extras/standalone.rb +50 -46
  44. data/lib/pagy/extras/support.rb +24 -16
  45. data/lib/pagy/extras/trim.rb +15 -14
  46. data/lib/pagy/extras/uikit.rb +41 -38
  47. data/lib/pagy/frontend.rb +36 -59
  48. data/lib/pagy/i18n.rb +164 -0
  49. data/lib/pagy/url_helpers.rb +24 -0
  50. data/lib/pagy.rb +90 -31
  51. data/lib/templates/bootstrap_nav.html.erb +2 -2
  52. data/lib/templates/bootstrap_nav.html.haml +2 -2
  53. data/lib/templates/bootstrap_nav.html.slim +2 -2
  54. data/lib/templates/foundation_nav.html.erb +1 -1
  55. data/lib/templates/foundation_nav.html.haml +1 -1
  56. data/lib/templates/foundation_nav.html.slim +1 -1
  57. data/lib/templates/nav.html.erb +1 -1
  58. data/lib/templates/nav.html.haml +1 -1
  59. data/lib/templates/nav.html.slim +1 -1
  60. data/lib/templates/uikit_nav.html.erb +2 -2
  61. data/lib/templates/uikit_nav.html.haml +1 -1
  62. data/lib/templates/uikit_nav.html.slim +2 -2
  63. metadata +29 -13
  64. data/lib/locales/utils/i18n.rb +0 -17
  65. data/lib/locales/utils/loader.rb +0 -31
  66. data/lib/locales/utils/p11n.rb +0 -112
  67. data/lib/pagy/deprecation.rb +0 -27
  68. data/lib/pagy/extras/shared.rb +0 -52
@@ -1,112 +0,0 @@
1
- # See https://ddnexus.github.io/pagy/api/frontend#i18n
2
- # frozen_string_literal: true
3
-
4
- # This file adds support for multiple built-in plualization types.
5
- # It defines the pluralization procs and gets eval(ed) and gc-collected at Pagy::I18n.load time.
6
-
7
- # utility variables
8
- from0to1 = [0,1].freeze
9
- from2to4 = [2,3,4].freeze
10
- from5to9 = [5,6,7,8,9].freeze
11
- from11to14 = [11,12,13,14].freeze
12
- from12to14 = [12,13,14].freeze
13
-
14
- # Pluralization (p11n)
15
- # Compliant with the I18n gem
16
- # A pluralization proc returns a plural type string based on the passed count
17
- # Each proc may apply to one or more locales below.
18
- # Pluralization logic adapted from https://github.com/svenfuchs/rails-i18n
19
- p11n = {
20
- one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
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
-
36
- east_slavic: lambda do |n|
37
- n ||= 0
38
- mod10 = n % 10
39
- mod100 = n % 100
40
-
41
- case
42
- when mod10 == 1 && mod100 != 11 then 'one'
43
- when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
44
- when mod10 == 0 || from5to9.include?(mod10) || from11to14.include?(mod100) then 'many' # rubocop:disable Style/NumericPredicate
45
- else 'other'
46
- end
47
- end,
48
-
49
- one_two_other: lambda do |n|
50
- case n
51
- when 1 then 'one'
52
- when 2 then 'two'
53
- else 'other'
54
- end
55
- end,
56
-
57
- one_upto_two_other: -> (n){ n && n >= 0 && n < 2 ? 'one' : 'other' },
58
-
59
- other: -> (*){ 'other' },
60
-
61
- polish: lambda do |n|
62
- n ||= 0
63
- mod10 = n % 10
64
- mod100 = n % 100
65
-
66
- case
67
- when n == 1 then 'one'
68
- when from2to4.include?(mod10) && !from12to14.include?(mod100) then 'few'
69
- when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
70
- else 'other'
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
80
- end
81
-
82
- }
83
-
84
- # Hash of locale/pluralization pairs
85
- # It contains all the entries for all the locales defined as dictionaries.
86
- # The default pluralization for locales not explicitly listed here
87
- # is the :one_other pluralization proc (used for English)
88
- plurals = Hash.new(p11n[:one_other]).tap do |hash|
89
- hash['ar'] = p11n[:arabic]
90
- hash['bs'] = p11n[:east_slavic]
91
- hash['cs'] = p11n[:west_slavic]
92
- hash['id'] = p11n[:other]
93
- hash['fr'] = p11n[:one_upto_two_other]
94
- hash['hr'] = p11n[:east_slavic]
95
- hash['ja'] = p11n[:other]
96
- hash['km'] = p11n[:other]
97
- hash['ko'] = p11n[:other]
98
- hash['pl'] = p11n[:polish]
99
- hash['ru'] = p11n[:east_slavic]
100
- hash['sr'] = p11n[:east_slavic]
101
- hash['sv'] = p11n[:one_two_other]
102
- hash['sv-SE'] = p11n[:one_two_other]
103
- hash['tr'] = p11n[:other]
104
- hash['uk'] = p11n[:east_slavic]
105
- hash['zh-CN'] = p11n[:other]
106
- hash['zh-HK'] = p11n[:other]
107
- hash['zh-TW'] = p11n[:other]
108
- end
109
-
110
- [ plurals, p11n ]
111
-
112
- # PR for other locales and pluralizations are very welcome. Thanks!
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
- class Pagy
3
- class << self
4
-
5
- # deprecated variables
6
- def deprecated_var(var, val, new_var, new_val)
7
- value = val || new_val
8
- Warning.warn %([PAGY WARNING] deprecated use of '#{var}' var will not be supported in 5.0! Use '#{new_var}: #{value.inspect}' instead.)
9
- value
10
- end
11
-
12
- # deprecated pagy_url_for argument order
13
- def deprecated_order(pagy, page)
14
- Warning.warn %([PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.)
15
- [page, pagy]
16
- end
17
-
18
-
19
- # deprecated posiitioal arguments
20
- def deprecated_arg(arg, val, new_key, new_val)
21
- value = val || new_val # we use the new_val if present
22
- Warning.warn %([PAGY WARNING] deprecated use of positional '#{arg}' arg will not be supported in 5.0! Use only the keyword arg '#{new_key}: #{value.inspect}' instead.)
23
- value
24
- end
25
-
26
- end
27
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
-
5
- class Pagy
6
-
7
- # default :steps: false will use {0 => @vars[:size]}
8
- VARS[:steps] = false
9
-
10
- # `Pagy` instance method used by the `pagy*_nav_js` helpers.
11
- # It returns the sequels of width/series generated from the :steps hash
12
- # Example:
13
- # >> pagy = Pagy.new(count:1000, page: 20, steps: {0 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3]})
14
- # >> pagy.sequels
15
- # #=> { "0" => [1, :gap, 18, 19, "20", 21, 22, :gap, 50],
16
- # "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
17
- # "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
18
- # Notice: if :steps is false it will use the single {0 => @vars[:size]} size
19
- def sequels(steps=nil)
20
- steps ||= @vars[:steps] || {0 => @vars[:size]}
21
- raise VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}" \
22
- unless steps.key?(0)
23
- {}.tap do |sequels|
24
- steps.each {|width, size| sequels[width.to_s] = series(size)}
25
- end
26
- end
27
-
28
- module Frontend
29
-
30
- if defined?(Oj)
31
- # it returns a script tag with the JSON-serialized args generated with the faster oj gem
32
- def pagy_json_attr(pagy, *args)
33
- args << pagy.vars[:page_param] if pagy.vars[:enable_trim_extra]
34
- %(data-pagy-json="#{Oj.dump(args, mode: :strict).gsub('"', '&quot;')}")
35
- end
36
- else
37
- require 'json'
38
- # it returns a script tag with the JSON-serialized args generated with the slower to_json
39
- def pagy_json_attr(pagy, *args)
40
- args << pagy.vars[:page_param] if pagy.vars[:enable_trim_extra]
41
- %(data-pagy-json="#{args.to_json.gsub('"', '&quot;')}")
42
- end
43
- end
44
-
45
- # it returns the marked link to used by pagy.js
46
- def pagy_marked_link(link)
47
- link.call PAGE_PLACEHOLDER, '', 'style="display: none;"'
48
- end
49
-
50
- end
51
-
52
- end