pagy 8.4.4 → 8.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/apps/calendar.ru +681 -2136
  3. data/apps/demo.ru +1 -1
  4. data/apps/rails.ru +3 -1
  5. data/apps/repro.ru +1 -1
  6. data/apps/tmp/calendar.sqlite3 +0 -0
  7. data/apps/tmp/calendar.sqlite3-shm +0 -0
  8. data/apps/tmp/calendar.sqlite3-wal +0 -0
  9. data/apps/tmp/local_secret.txt +1 -0
  10. data/apps/tmp/pagy-rails.sqlite3 +0 -0
  11. data/bin/pagy +9 -9
  12. data/config/pagy.rb +1 -1
  13. data/javascripts/pagy-module.js +1 -1
  14. data/javascripts/pagy.js +2 -2
  15. data/javascripts/pagy.min.js +2 -2
  16. data/javascripts/pagy.min.js.map +2 -2
  17. data/javascripts/pagy.mjs +1 -1
  18. data/lib/optimist.rb +1 -1
  19. data/lib/pagy/calendar/day.rb +2 -2
  20. data/lib/pagy/calendar/month.rb +2 -2
  21. data/lib/pagy/calendar/quarter.rb +2 -2
  22. data/lib/pagy/calendar/unit.rb +106 -0
  23. data/lib/pagy/calendar/week.rb +2 -2
  24. data/lib/pagy/calendar/year.rb +2 -2
  25. data/lib/pagy/calendar.rb +54 -97
  26. data/lib/pagy/extras/calendar.rb +34 -4
  27. data/lib/pagy/extras/i18n.rb +1 -1
  28. data/lib/pagy/extras/js_tools.rb +1 -1
  29. data/lib/pagy/extras/metadata.rb +5 -1
  30. data/lib/pagy/extras/overflow.rb +3 -2
  31. data/lib/pagy/frontend.rb +8 -5
  32. data/lib/pagy.rb +2 -3
  33. data/locales/ar.yml +1 -1
  34. data/locales/be.yml +1 -1
  35. data/locales/bg.yml +1 -1
  36. data/locales/bs.yml +1 -1
  37. data/locales/ca.yml +4 -6
  38. data/locales/ckb.yml +1 -1
  39. data/locales/cs.yml +1 -1
  40. data/locales/da.yml +1 -1
  41. data/locales/de.yml +1 -1
  42. data/locales/en.yml +1 -1
  43. data/locales/es.yml +1 -1
  44. data/locales/fr.yml +1 -1
  45. data/locales/hr.yml +1 -1
  46. data/locales/id.yml +1 -1
  47. data/locales/it.yml +1 -1
  48. data/locales/ja.yml +1 -1
  49. data/locales/km.yml +1 -1
  50. data/locales/ko.yml +1 -1
  51. data/locales/nb.yml +1 -1
  52. data/locales/nl.yml +1 -1
  53. data/locales/nn.yml +1 -1
  54. data/locales/pl.yml +1 -1
  55. data/locales/pt-BR.yml +1 -1
  56. data/locales/pt.yml +1 -1
  57. data/locales/ru.yml +1 -1
  58. data/locales/sr.yml +1 -1
  59. data/locales/sv-SE.yml +1 -1
  60. data/locales/sv.yml +1 -1
  61. data/locales/sw.yml +1 -1
  62. data/locales/ta.yml +1 -1
  63. data/locales/tr.yml +1 -1
  64. data/locales/uk.yml +1 -1
  65. data/locales/vi.yml +1 -1
  66. data/locales/zh-CN.yml +1 -1
  67. data/locales/zh-HK.yml +1 -1
  68. data/locales/zh-TW.yml +1 -1
  69. metadata +8 -3
  70. data/lib/pagy/calendar/helper.rb +0 -65
@@ -17,7 +17,11 @@ class Pagy # :nodoc:
17
17
  def pagy_metadata(pagy, absolute: nil)
18
18
  scaffold_url = pagy_url_for(pagy, PAGE_TOKEN, absolute:)
19
19
  {}.tap do |metadata|
20
- keys = defined?(Calendar) && pagy.is_a?(Calendar) ? pagy.vars[:metadata] - %i[count items] : pagy.vars[:metadata]
20
+ keys = if defined?(Calendar::Unit) && pagy.is_a?(Calendar::Unit)
21
+ pagy.vars[:metadata] - %i[count items]
22
+ else
23
+ pagy.vars[:metadata]
24
+ end
21
25
  keys.each do |key|
22
26
  metadata[key] = case key
23
27
  when :scaffold_url then scaffold_url
@@ -28,7 +28,8 @@ class Pagy # :nodoc:
28
28
  @vars[:page] = requested_page # restore the requested page
29
29
  when :empty_page
30
30
  @offset = @items = @in = @from = @to = 0 # vars relative to the actual page
31
- if defined?(Calendar) && is_a?(Calendar) # only for Calendar instances
31
+ if defined?(Calendar::Unit) \
32
+ && is_a?(Calendar::Unit) # only for Calendar::Units instances
32
33
  edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but any time would do)
33
34
  @from = @to = edge # set both to the edge utc time (a >=&&< query will get no records)
34
35
  end
@@ -51,7 +52,7 @@ class Pagy # :nodoc:
51
52
  end
52
53
  end
53
54
  Pagy.prepend PagyOverride
54
- Pagy::Calendar.prepend PagyOverride if defined?(Calendar)
55
+ Pagy::Calendar::Unit.prepend PagyOverride if defined?(Calendar::Unit)
55
56
 
56
57
  # Support for Pagy::Countless class
57
58
  module CountlessOverride
data/lib/pagy/frontend.rb CHANGED
@@ -20,7 +20,7 @@ class Pagy
20
20
  a = pagy_anchor(pagy)
21
21
 
22
22
  html = %(<nav#{id} class="pagy nav" #{nav_aria_label(pagy, aria_label:)}>#{
23
- prev_a(pagy, a)})
23
+ prev_a(pagy, a)})
24
24
  pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
25
25
  html << case item
26
26
  when Integer
@@ -40,9 +40,12 @@ class Pagy
40
40
  def pagy_info(pagy, id: nil, item_name: nil)
41
41
  id = %( id="#{id}") if id
42
42
  p_count = pagy.count
43
- key = if p_count.zero? then 'pagy.info.no_items'
44
- elsif pagy.pages == 1 then 'pagy.info.single_page'
45
- else 'pagy.info.multiple_pages' # rubocop:disable Lint/ElseLayout
43
+ key = if p_count.zero?
44
+ 'pagy.info.no_items'
45
+ elsif pagy.pages == 1
46
+ 'pagy.info.single_page'
47
+ else
48
+ 'pagy.info.multiple_pages'
46
49
  end
47
50
 
48
51
  %(<span#{id} class="pagy info">#{
@@ -51,7 +54,7 @@ class Pagy
51
54
  }</span>)
52
55
  end
53
56
 
54
- # Return a performance optimized lambda to generate the HtML anchor element (a tag)
57
+ # Return a performance optimized lambda to generate the HTML anchor element (a tag)
55
58
  # Benchmarked on a 20 link nav: it is ~22x faster and uses ~18x less memory than rails' link_to
56
59
  def pagy_anchor(pagy)
57
60
  a_string = pagy.vars[:anchor_string]
data/lib/pagy.rb CHANGED
@@ -5,19 +5,18 @@ require 'pathname'
5
5
 
6
6
  # Core class
7
7
  class Pagy
8
- VERSION = '8.4.4'
8
+ VERSION = '8.5.0'
9
9
 
10
10
  # Gem root pathname to get the path of Pagy files stylesheets, javascripts, apps, locales, etc.
11
11
  def self.root
12
12
  @root ||= Pathname.new(__dir__).parent.freeze
13
13
  end
14
14
 
15
- # Core defult: constant for easy access, but mutable for customizable defaults
15
+ # Core default: constant for easy access, but mutable for customizable defaults
16
16
  DEFAULT = { page: 1, # rubocop:disable Style/MutableConstant
17
17
  items: 20,
18
18
  outset: 0,
19
19
  size: 7,
20
- cycle: false,
21
20
  count_args: [:all], # AR friendly
22
21
  page_param: :page }
23
22
 
data/locales/ar.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ar:
3
3
  pagy:
4
4
  aria_label:
data/locales/be.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  be:
3
3
  pagy:
4
4
  aria_label:
data/locales/bg.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  bg:
3
3
  pagy:
4
4
  aria_label:
data/locales/bs.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  bs:
3
3
  pagy:
4
4
  aria_label:
data/locales/ca.yml CHANGED
@@ -1,12 +1,10 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ca:
3
3
  pagy:
4
4
  aria_label:
5
- # please add a comment in the https://github.com/ddnexus/pagy/issues/581
6
- # posting the translation of the following "Page"/"Pages" with the plurals for this locale
7
- nav: "Pages"
8
- # one: ""
9
- # other: ""
5
+ nav:
6
+ one: "Pàgina"
7
+ other: "Pàgines"
10
8
  prev: "Anterior"
11
9
  next: "Següent"
12
10
  prev: "&lt;"
data/locales/ckb.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
 
3
3
  ckb:
4
4
  pagy:
data/locales/cs.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :west_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :west_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  cs:
3
3
  pagy:
4
4
  aria_label:
data/locales/da.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  da:
3
3
  pagy:
4
4
  aria_label:
data/locales/de.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  de:
3
3
  pagy:
4
4
  aria_label:
data/locales/en.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  en:
3
3
  pagy:
4
4
  aria_label:
data/locales/es.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  es:
3
3
  pagy:
4
4
  aria_label:
data/locales/fr.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_upto_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_upto_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  fr:
3
3
  pagy:
4
4
  aria_label:
data/locales/hr.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  hr:
3
3
  pagy:
4
4
  aria_label:
data/locales/id.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  id:
3
3
  pagy:
4
4
  aria_label:
data/locales/it.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  it:
3
3
  pagy:
4
4
  aria_label:
data/locales/ja.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ja:
3
3
  pagy:
4
4
  aria_label:
data/locales/km.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  km:
3
3
  pagy:
4
4
  aria_label:
data/locales/ko.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ko:
3
3
  pagy:
4
4
  aria_label:
data/locales/nb.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  nb:
3
3
  pagy:
4
4
  aria_label:
data/locales/nl.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  nl:
3
3
  pagy:
4
4
  aria_label:
data/locales/nn.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  nn:
3
3
  pagy:
4
4
  aria_label:
data/locales/pl.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :polish pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :polish pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  pl:
3
3
  pagy:
4
4
  aria_label:
data/locales/pt-BR.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  pt-BR:
3
3
  pagy:
4
4
  aria_label:
data/locales/pt.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  pt:
3
3
  pagy:
4
4
  aria_label:
data/locales/ru.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ru:
3
3
  pagy:
4
4
  aria_label:
data/locales/sr.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  sr:
3
3
  pagy:
4
4
  aria_label:
data/locales/sv-SE.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  sv-SE:
3
3
  pagy:
4
4
  aria_label:
data/locales/sv.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  sv:
3
3
  pagy:
4
4
  aria_label:
data/locales/sw.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  sw:
3
3
  pagy:
4
4
  # please add a comment in the https://github.com/ddnexus/pagy/issues/603
data/locales/ta.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  ta:
3
3
  pagy:
4
4
  aria_label:
data/locales/tr.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  tr:
3
3
  pagy:
4
4
  aria_label:
data/locales/uk.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :east_slavic pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  uk:
3
3
  pagy:
4
4
  aria_label:
data/locales/vi.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  vi:
3
3
  pagy:
4
4
  aria_label:
data/locales/zh-CN.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  zh-CN:
3
3
  pagy:
4
4
  aria_label:
data/locales/zh-HK.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  zh-HK:
3
3
  pagy:
4
4
  aria_label:
data/locales/zh-TW.yml CHANGED
@@ -1,4 +1,4 @@
1
- # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/pagy/i18n.rb)
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/gem/lib/pagy/i18n.rb)
2
2
  zh-TW:
3
3
  pagy:
4
4
  aria_label:
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: 8.4.4
4
+ version: 8.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Agnostic pagination in plain ruby. It does it all. Better.
14
14
  email:
@@ -23,6 +23,11 @@ files:
23
23
  - apps/demo.ru
24
24
  - apps/rails.ru
25
25
  - apps/repro.ru
26
+ - apps/tmp/calendar.sqlite3
27
+ - apps/tmp/calendar.sqlite3-shm
28
+ - apps/tmp/calendar.sqlite3-wal
29
+ - apps/tmp/local_secret.txt
30
+ - apps/tmp/pagy-rails.sqlite3
26
31
  - bin/pagy
27
32
  - config/pagy.rb
28
33
  - javascripts/pagy-module.js
@@ -36,9 +41,9 @@ files:
36
41
  - lib/pagy/backend.rb
37
42
  - lib/pagy/calendar.rb
38
43
  - lib/pagy/calendar/day.rb
39
- - lib/pagy/calendar/helper.rb
40
44
  - lib/pagy/calendar/month.rb
41
45
  - lib/pagy/calendar/quarter.rb
46
+ - lib/pagy/calendar/unit.rb
42
47
  - lib/pagy/calendar/week.rb
43
48
  - lib/pagy/calendar/year.rb
44
49
  - lib/pagy/console.rb
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Pagy # :nodoc:
4
- class Calendar # :nodoc:
5
- # Initializes the calendar objects, reducing complexity in the extra
6
- # The returned calendar is a simple hash of units/objects
7
- class Helper < Hash
8
- class << self
9
- private
10
-
11
- def init(conf, period, params)
12
- new.send(:init, conf, period, params)
13
- end
14
- end
15
-
16
- private
17
-
18
- # Create the calendar
19
- def init(conf, period, params)
20
- @conf = Marshal.load(Marshal.dump(conf)) # store a copy
21
- @units = Calendar::UNITS & @conf.keys # get the units in time length desc order
22
- raise ArgumentError, 'no calendar unit found in pagy_calendar @configuration' if @units.empty?
23
-
24
- @period = period
25
- @params = params
26
- @page_param = conf[:pagy][:page_param] || DEFAULT[:page_param]
27
- @units.each do |unit| # set all the :page_param vars for later deletion
28
- unit_page_param = :"#{unit}_#{@page_param}"
29
- conf[unit][:page_param] = unit_page_param
30
- conf[unit][:page] = @params[unit_page_param]
31
- end
32
- calendar = {}
33
- object = nil
34
- @units.each_with_index do |unit, index|
35
- params_to_delete = @units[(index + 1), @units.size].map { |sub| conf[sub][:page_param] } + [@page_param]
36
- conf[unit][:params] = lambda { |up| up.except(*params_to_delete.map(&:to_s)) } # rubocop:disable Style/Lambda
37
- conf[unit][:period] = object&.send(:active_period) || @period
38
- calendar[unit] = object = Calendar.send(:create, unit, conf[unit])
39
- end
40
- [replace(calendar), object.from, object.to]
41
- end
42
-
43
- # Return the calendar object at time
44
- def calendar_at(time, **opts)
45
- conf = Marshal.load(Marshal.dump(@conf))
46
- page_params = {}
47
- @units.inject(nil) do |object, unit|
48
- conf[unit][:period] = object&.send(:active_period) || @period
49
- conf[unit][:page] = page_params[:"#{unit}_#{@page_param}"] \
50
- = Calendar.send(:create, unit, conf[unit]).send(:page_at, time, **opts)
51
- conf[unit][:params] ||= {}
52
- conf[unit][:params].merge!(page_params)
53
- Calendar.send(:create, unit, conf[unit])
54
- end
55
- end
56
-
57
- public
58
-
59
- # Return the current time of the smallest time unit shown
60
- def showtime
61
- self[@units.last].from
62
- end
63
- end
64
- end
65
- end