pagy 5.7.5 → 8.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/apps/calendar.ru +745 -0
  4. data/apps/demo.ru +435 -0
  5. data/apps/rails.ru +213 -0
  6. data/apps/repro.ru +177 -0
  7. data/apps/tmp/calendar.sqlite3 +0 -0
  8. data/apps/tmp/calendar.sqlite3-shm +0 -0
  9. data/apps/tmp/calendar.sqlite3-wal +0 -0
  10. data/apps/tmp/local_secret.txt +1 -0
  11. data/bin/pagy +100 -0
  12. data/{lib/config → config}/pagy.rb +72 -96
  13. data/javascripts/pagy-module.js +100 -0
  14. data/javascripts/pagy.d.ts +5 -0
  15. data/javascripts/pagy.js +4 -0
  16. data/javascripts/pagy.min.js +4 -0
  17. data/javascripts/pagy.min.js.map +10 -0
  18. data/javascripts/pagy.mjs +100 -0
  19. data/lib/optimist.rb +1022 -0
  20. data/lib/pagy/backend.rb +16 -4
  21. data/lib/pagy/calendar/day.rb +22 -10
  22. data/lib/pagy/calendar/month.rb +35 -9
  23. data/lib/pagy/calendar/quarter.rb +36 -10
  24. data/lib/pagy/calendar/unit.rb +106 -0
  25. data/lib/pagy/calendar/week.rb +16 -16
  26. data/lib/pagy/calendar/year.rb +15 -9
  27. data/lib/pagy/calendar.rb +60 -68
  28. data/lib/pagy/console.rb +3 -3
  29. data/lib/pagy/countless.rb +17 -12
  30. data/lib/pagy/exceptions.rb +1 -1
  31. data/lib/pagy/extras/arel.rb +2 -2
  32. data/lib/pagy/extras/array.rb +2 -2
  33. data/lib/pagy/extras/bootstrap.rb +57 -53
  34. data/lib/pagy/extras/bulma.rb +53 -57
  35. data/lib/pagy/extras/calendar.rb +54 -37
  36. data/lib/pagy/extras/countless.rb +3 -3
  37. data/lib/pagy/extras/elasticsearch_rails.rb +12 -11
  38. data/lib/pagy/extras/foundation.rb +59 -54
  39. data/lib/pagy/extras/gearbox.rb +32 -19
  40. data/lib/pagy/extras/headers.rb +11 -11
  41. data/lib/pagy/extras/i18n.rb +5 -5
  42. data/lib/pagy/extras/items.rb +34 -24
  43. data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +24 -24
  44. data/lib/pagy/extras/jsonapi.rb +79 -0
  45. data/lib/pagy/extras/materialize.rb +63 -47
  46. data/lib/pagy/extras/meilisearch.rb +26 -22
  47. data/lib/pagy/extras/metadata.rb +13 -9
  48. data/lib/pagy/extras/overflow.rb +13 -10
  49. data/lib/pagy/extras/pagy.rb +82 -0
  50. data/lib/pagy/extras/searchkick.rb +12 -11
  51. data/lib/pagy/extras/semantic.rb +57 -45
  52. data/lib/pagy/extras/size.rb +40 -0
  53. data/lib/pagy/extras/standalone.rb +12 -16
  54. data/lib/pagy/extras/trim.rb +13 -13
  55. data/lib/pagy/extras/uikit.rb +60 -46
  56. data/lib/pagy/frontend.rb +62 -45
  57. data/lib/pagy/i18n.rb +4 -3
  58. data/lib/pagy/url_helpers.rb +13 -25
  59. data/lib/pagy.rb +61 -59
  60. data/locales/ar.yml +28 -0
  61. data/locales/be.yml +25 -0
  62. data/locales/bg.yml +21 -0
  63. data/locales/bs.yml +25 -0
  64. data/locales/ca.yml +21 -0
  65. data/locales/ckb.yml +18 -0
  66. data/locales/cs.yml +23 -0
  67. data/locales/da.yml +21 -0
  68. data/locales/de.yml +21 -0
  69. data/locales/en.yml +21 -0
  70. data/locales/es.yml +21 -0
  71. data/locales/fr.yml +21 -0
  72. data/locales/hr.yml +25 -0
  73. data/locales/id.yml +19 -0
  74. data/locales/it.yml +21 -0
  75. data/locales/ja.yml +19 -0
  76. data/locales/km.yml +19 -0
  77. data/locales/ko.yml +17 -0
  78. data/locales/nb.yml +21 -0
  79. data/locales/nl.yml +21 -0
  80. data/locales/nn.yml +21 -0
  81. data/locales/pl.yml +25 -0
  82. data/locales/pt-BR.yml +21 -0
  83. data/locales/pt.yml +21 -0
  84. data/locales/ru.yml +25 -0
  85. data/locales/sr.yml +25 -0
  86. data/locales/sv-SE.yml +21 -0
  87. data/locales/sv.yml +21 -0
  88. data/locales/sw.yml +23 -0
  89. data/locales/ta.yml +23 -0
  90. data/locales/tr.yml +19 -0
  91. data/locales/uk.yml +25 -0
  92. data/locales/vi.yml +17 -0
  93. data/locales/zh-CN.yml +19 -0
  94. data/locales/zh-HK.yml +19 -0
  95. data/locales/zh-TW.yml +19 -0
  96. data/stylesheets/pagy.css +46 -0
  97. data/stylesheets/pagy.scss +48 -0
  98. data/stylesheets/pagy.tailwind.css +21 -0
  99. metadata +79 -66
  100. data/lib/javascripts/pagy-dev.js +0 -118
  101. data/lib/javascripts/pagy-module.d.ts +0 -30
  102. data/lib/javascripts/pagy-module.js +0 -117
  103. data/lib/javascripts/pagy.js +0 -1
  104. data/lib/locales/ar.yml +0 -26
  105. data/lib/locales/bg.yml +0 -22
  106. data/lib/locales/bs.yml +0 -24
  107. data/lib/locales/ca.yml +0 -22
  108. data/lib/locales/cs.yml +0 -22
  109. data/lib/locales/da.yml +0 -22
  110. data/lib/locales/de.yml +0 -22
  111. data/lib/locales/en.yml +0 -22
  112. data/lib/locales/es.yml +0 -22
  113. data/lib/locales/fr.yml +0 -22
  114. data/lib/locales/hr.yml +0 -24
  115. data/lib/locales/id.yml +0 -20
  116. data/lib/locales/it.yml +0 -22
  117. data/lib/locales/ja.yml +0 -20
  118. data/lib/locales/km.yml +0 -19
  119. data/lib/locales/ko.yml +0 -20
  120. data/lib/locales/nb.yml +0 -22
  121. data/lib/locales/nl.yml +0 -22
  122. data/lib/locales/pl.yml +0 -24
  123. data/lib/locales/pt-BR.yml +0 -22
  124. data/lib/locales/pt.yml +0 -22
  125. data/lib/locales/ru.yml +0 -24
  126. data/lib/locales/sr.yml +0 -23
  127. data/lib/locales/sv-SE.yml +0 -23
  128. data/lib/locales/sv.yml +0 -23
  129. data/lib/locales/sw.yml +0 -22
  130. data/lib/locales/ta.yml +0 -22
  131. data/lib/locales/tr.yml +0 -20
  132. data/lib/locales/uk.yml +0 -24
  133. data/lib/locales/zh-CN.yml +0 -20
  134. data/lib/locales/zh-HK.yml +0 -20
  135. data/lib/locales/zh-TW.yml +0 -20
  136. data/lib/pagy/calendar/month_mixin.rb +0 -49
  137. data/lib/pagy/extras/navs.rb +0 -63
  138. data/lib/pagy/extras/support.rb +0 -54
  139. data/lib/templates/bootstrap_nav.html.erb +0 -24
  140. data/lib/templates/bootstrap_nav.html.haml +0 -34
  141. data/lib/templates/bootstrap_nav.html.slim +0 -34
  142. data/lib/templates/bulma_nav.html.erb +0 -24
  143. data/lib/templates/bulma_nav.html.haml +0 -32
  144. data/lib/templates/bulma_nav.html.slim +0 -32
  145. data/lib/templates/foundation_nav.html.erb +0 -24
  146. data/lib/templates/foundation_nav.html.haml +0 -34
  147. data/lib/templates/foundation_nav.html.slim +0 -34
  148. data/lib/templates/nav.html.erb +0 -22
  149. data/lib/templates/nav.html.haml +0 -30
  150. data/lib/templates/nav.html.slim +0 -29
  151. data/lib/templates/uikit_nav.html.erb +0 -15
  152. data/lib/templates/uikit_nav.html.haml +0 -28
  153. data/lib/templates/uikit_nav.html.slim +0 -28
data/apps/repro.ru ADDED
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Starting point app to try pagy or reproduce issues
4
+
5
+ # DEV USAGE
6
+ # pagy clone repro
7
+ # pagy ./repro.ru
8
+
9
+ # URL
10
+ # http://0.0.0.0:8000
11
+
12
+ # HELP
13
+ # pagy -h
14
+
15
+ # DOC
16
+ # https://ddnexus.github.io/pagy/playground/#1-repro-app
17
+
18
+ VERSION = '8.6.2'
19
+
20
+ require 'bundler/inline'
21
+ require 'bundler'
22
+ Bundler.configure
23
+ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
24
+ source 'https://rubygems.org'
25
+ gem 'oj'
26
+ gem 'puma'
27
+ gem 'sinatra'
28
+ gem 'sinatra-contrib'
29
+ end
30
+
31
+ # Edit this section adding/removing the extras and Pagy::DEFAULT as needed
32
+ # pagy initializer
33
+ require 'pagy/extras/pagy'
34
+ require 'pagy/extras/items'
35
+ require 'pagy/extras/overflow'
36
+ Pagy::DEFAULT[:overflow] = :empty_page
37
+ Pagy::DEFAULT.freeze
38
+
39
+ require 'sinatra/base'
40
+ # Sinatra application
41
+ class PagyRepro < Sinatra::Base
42
+ configure do
43
+ enable :inline_templates
44
+ end
45
+ include Pagy::Backend
46
+
47
+ get('/javascripts/:file') do
48
+ format = params[:file].split('.').last
49
+ if format == 'js'
50
+ content_type 'application/javascript'
51
+ elsif format == 'map'
52
+ content_type 'application/json'
53
+ end
54
+ send_file Pagy.root.join('javascripts', params[:file])
55
+ end
56
+
57
+ # Edit this action as needed
58
+ get '/' do
59
+ collection = MockCollection.new
60
+ @pagy, @records = pagy(collection)
61
+ erb :main # template available in the __END__ section as @@ main
62
+ end
63
+ # Edit this section adding your own helpers as needed
64
+ helpers do
65
+ include Pagy::Frontend
66
+ end
67
+ end
68
+
69
+ # Simple array-based collection that acts as a standard DB collection.
70
+ # Use it as a simple way to get a collection that acts as a AR scope, but without any DB
71
+ # or create an ActiveRecord class or anything else that you need instead
72
+ class MockCollection < Array
73
+ def initialize(arr = Array(1..1000))
74
+ super
75
+ @collection = clone
76
+ end
77
+
78
+ def offset(value)
79
+ @collection = self[value..]
80
+ self
81
+ end
82
+
83
+ def limit(value)
84
+ @collection[0, value]
85
+ end
86
+
87
+ def count(*)
88
+ size
89
+ end
90
+ end
91
+
92
+ run PagyRepro
93
+
94
+ __END__
95
+
96
+ @@ layout
97
+ <!DOCTYPE html>
98
+ <html lang="en">
99
+ <html>
100
+ <head>
101
+ <title>Pagy Repro App</title>
102
+ <script src="javascripts/pagy.min.js"></script>
103
+ <script>
104
+ window.addEventListener("load", Pagy.init);
105
+ </script>
106
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
107
+ <style type="text/css">
108
+ @media screen { html, body {
109
+ font-size: 1rem;
110
+ line-height: 1.2s;
111
+ padding: 0;
112
+ margin: 0;
113
+ } }
114
+ body {
115
+ background: white !important;
116
+ margin: 0 !important;
117
+ font-family: sans-serif !important;
118
+ }
119
+ .content {
120
+ padding: 1rem 1.5rem 2rem !important;
121
+ }
122
+
123
+ /* Quick demo for overriding the element style attribute of certain pagy helpers
124
+ .pagy input[style] {
125
+ width: 5rem !important;
126
+ }
127
+ */
128
+
129
+ /*
130
+ If you want to customize the style,
131
+ please replace the line below with the actual file content
132
+ */
133
+ <%= Pagy.root.join('stylesheets', 'pagy.css').read %>
134
+ </style>
135
+ </head>
136
+ <body>
137
+ <%= yield %>
138
+ </body>
139
+ </html>
140
+
141
+ @@ main
142
+ <div class="content">
143
+ <h1>Pagy Repro App</h1>
144
+ <p> Self-contained, standalone Sinatra app usable to easily reproduce any pagy issue.</p>
145
+ <p>Please, report the following versions in any new issue.</p>
146
+ <h2>Versions</h4>
147
+ <ul>
148
+ <li>Ruby: <%= RUBY_VERSION %></li>
149
+ <li>Rack: <%= Rack::RELEASE %></li>
150
+ <li>Sinatra: <%= Sinatra::VERSION %></li>
151
+ <li>Pagy: <%= Pagy::VERSION %></li>
152
+ </ul>
153
+
154
+ <h3>Collection</h3>
155
+ <p id="records">@records: <%= @records.join(',') %></p>
156
+
157
+ <hr>
158
+
159
+ <h4>pagy_nav</h4>
160
+ <%= pagy_nav(@pagy, id: 'nav', aria_label: 'Pages nav') %>
161
+
162
+ <h4>pagy_nav_js</h4>
163
+ <%= pagy_nav_js(@pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
164
+
165
+ <h4>pagy_nav_js</h4>
166
+ <%= pagy_nav_js(@pagy, id: 'nav-js-responsive', aria_label: 'Pages nav_js_responsove',
167
+ steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
168
+
169
+ <h4>pagy_combo_nav_js</h4>
170
+ <%= pagy_combo_nav_js(@pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
171
+
172
+ <h4>pagy_items_selector_js</h4>
173
+ <%= pagy_items_selector_js(@pagy, id: 'items-selector-js') %>
174
+
175
+ <h4>pagy_info</h4>
176
+ <%= pagy_info(@pagy, id: 'pagy-info') %>
177
+ </div>
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ 4c57eebd7544c7f0acc9943ab614ab3da71d2461f5581ed8d41e9b8aa1bf23bff831f82e934eed96c608da0feac2c3dd21383c269d896cf01fcd6fa81aca2462
data/bin/pagy ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ VERSION = '8.6.2'
5
+ APPS = %w[repro rails demo calendar].freeze
6
+ LINUX = RbConfig::CONFIG['host_os'].include?('linux')
7
+ HOST = '0.0.0.0'
8
+ PORT = '8000'
9
+
10
+ require_relative '../lib/optimist'
11
+ opts = Optimist.options do
12
+ text <<~HEAD
13
+ Pagy #{VERSION} (https://ddnexus.github.io/pagy/playground)
14
+ Playground to showcase, clone and develop pagy APPs
15
+ APPs
16
+ repro Reproduce generic/simple issues
17
+ rails Reproduce rails related issues
18
+ demo Showcase all the helpers and styles
19
+ calendar Showcase the calendar; reproduce related issues
20
+ USAGE
21
+ pagy APP [options] Showcase APP from the installed gem
22
+ pagy clone APP Clone APP to the current dir
23
+ pagy APPFILE [options] Develop APPFILE from local path
24
+ EXAMPLES
25
+ pagy demo Showcase demo at http://#{HOST}:#{PORT}
26
+ pagy clone repro Clone repro to ./repro.ru
27
+ pagy ~/my-repro.ru Develop ~/my-repro.ru at#{HOST}:#{PORT}
28
+ HEAD
29
+ text 'Rackup options'
30
+ opt :env, 'Environment', default: 'development'
31
+ opt :host, 'Host', default: HOST, short: :o
32
+ opt :port, 'Port', default: PORT
33
+ opt :install, 'Install bundle for users', default: true
34
+ if LINUX
35
+ text 'Rerun options'
36
+ opt :rerun, 'Enable rerun for development', default: true
37
+ opt :clear, 'Clear screen before each rerun'
38
+ end
39
+ text 'Other options'
40
+ opt :quiet, 'Quiet mode for development'
41
+ version VERSION
42
+ end
43
+ Optimist.educate if ARGV.empty?
44
+
45
+ run_from_repo = File.exist?(File.expand_path('../pagy.gemspec', __dir__))
46
+
47
+ # Handles gems
48
+ require 'bundler/inline'
49
+ require 'bundler'
50
+ Bundler.configure
51
+ gemfile(opts[:install]) do
52
+ source 'https://rubygems.org'
53
+ gem 'rackup'
54
+ gem 'rerun' if LINUX
55
+ end
56
+
57
+ path = ->(app) { File.expand_path("../apps/#{app}.ru", __dir__) }
58
+ arg = ARGV.shift
59
+ if arg.eql?('clone')
60
+ arg = ARGV.shift
61
+ Optimist.die("Expected APP to be in [#{APPS.join(', ')}]; got #{arg.inspect}") unless APPS.include?(arg)
62
+ file = path.(arg)
63
+ name = File.basename(file)
64
+ if File.exist?(name)
65
+ print "Do you want to overwrite the #{name.inspect} file? (y/n)> "
66
+ answer = gets.chomp
67
+ Optimist.die("#{name.inspect} file already present") unless answer.start_with?(/y/i)
68
+ end
69
+ require 'fileutils'
70
+ FileUtils.cp(file, '.', verbose: true)
71
+ else
72
+ if APPS.include?(arg) # showcase env
73
+ opts[:env] = 'showcase'
74
+ opts[:rerun] = false
75
+ opts[:quiet] = true
76
+ # Avoid the creation of './tmp/local_secret.txt' for showcase env
77
+ ENV['SECRET_KEY_BASE'] = 'absolute secret!' if arg.eql?('rails')
78
+ file = path.(arg)
79
+ else # development env
80
+ file = arg
81
+ end
82
+ Optimist.die("#{file.inspect} app not found") unless File.exist?(file)
83
+ # Run command
84
+ gem_dir = File.expand_path('..', __dir__)
85
+ rackup = "rackup -I #{gem_dir}/lib -r pagy -o #{opts[:host]} -p #{opts[:port]} -E #{opts[:env]} #{file}"
86
+ rackup << ' -q' if opts[:quiet]
87
+ if opts[:rerun]
88
+ name = File.basename(file)
89
+ dir = File.dirname(file)
90
+ rerun = if run_from_repo # rerun app also when gem dir files change (for pagy devs)
91
+ "rerun --name #{name} -d #{dir},#{gem_dir} -p **/*.{rb,js,css,scss,ru,yml}"
92
+ else
93
+ "rerun --name #{name} -d #{dir} -p #{name}" # rerun only when app.ru changes
94
+ end
95
+ rerun << ' -q' if opts[:quiet]
96
+ rerun << ' -c' if opts[:clear]
97
+ rerun << " -- #{rackup}"
98
+ end
99
+ exec("PAGY_INSTALL_BUNDLE='#{opts[:install]}' #{rerun || rackup}")
100
+ end
@@ -1,64 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (5.7.5)
3
+ # Pagy initializer file (8.6.2)
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
 
7
7
 
8
- # Pagy DEFAULT Variables
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 by just passing them to
8
+ # Pagy Variables
9
+ # See https://ddnexus.github.io/pagy/docs/api/pagy#variables
10
+ # You can set any pagy variable as a Pagy::DEFAULT. They can also be overridden per instance by just passing them to
11
11
  # Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
12
+ # Here are the few that make more sense as DEFAULTs:
13
+ # Pagy::DEFAULT[:items] = 20 # default
14
+ # Pagy::DEFAULT[:size] = 7 # default
15
+ # Pagy::DEFAULT[:ends] = true # default
16
+ # Pagy::DEFAULT[:page_param] = :page # default
17
+ # Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
12
18
 
13
19
 
14
- # Instance variables
15
- # See https://ddnexus.github.io/pagy/api/pagy#instance-variables
16
- # Pagy::DEFAULT[:page] = 1 # default
17
- # Pagy::DEFAULT[:items] = 20 # default
18
- # Pagy::DEFAULT[:outset] = 0 # default
19
-
20
+ # Extras
21
+ # See https://ddnexus.github.io/pagy/categories/extra
20
22
 
21
- # Other Variables
22
- # See https://ddnexus.github.io/pagy/api/pagy#other-variables
23
- # Pagy::DEFAULT[:size] = [1,4,4,1] # default
24
- # Pagy::DEFAULT[:page_param] = :page # default
25
- # The :params can be also set as a lambda e.g ->(params){ params.exclude('useless').merge!('custom' => 'useful') }
26
- # Pagy::DEFAULT[:params] = {} # default
27
- # Pagy::DEFAULT[:fragment] = '#fragment' # example
28
- # Pagy::DEFAULT[:link_extra] = 'data-remote="true"' # example
29
- # Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
30
- # Pagy::DEFAULT[:cycle] = true # example
31
23
 
24
+ # Legacy Compatibility Extras
32
25
 
33
- # Extras
34
- # See https://ddnexus.github.io/pagy/extras
26
+ # Size extra: Enable the Array type for the `:size` variable (e.g. `size: [1,4,4,1]`)
27
+ # See https://ddnexus.github.io/pagy/docs/extras/size
28
+ # require 'pagy/extras/size' # must be required before the other extras
35
29
 
36
30
 
37
31
  # Backend Extras
38
32
 
33
+ # Arel extra: For better performance utilizing grouped ActiveRecord collections:
34
+ # See: https://ddnexus.github.io/pagy/docs/extras/arel
35
+ # require 'pagy/extras/arel'
36
+
39
37
  # Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
40
- # See https://ddnexus.github.io/pagy/extras/array
38
+ # See https://ddnexus.github.io/pagy/docs/extras/array
41
39
  # require 'pagy/extras/array'
42
40
 
43
41
  # Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
44
- # See https://ddnexus.github.io/pagy/extras/calendar
42
+ # See https://ddnexus.github.io/pagy/docs/extras/calendar
45
43
  # require 'pagy/extras/calendar'
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
49
- #
50
- # Pagy::Calendar::Quarter::DEFAULT[:order] = :asc # Time direction of pagination
51
- # Pagy::Calendar::Quarter::DEFAULT[:format] = '%Y-Q%q' # strftime format
52
- #
53
- # Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
54
- # Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
55
- #
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
- #
60
- # Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
61
- # Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
44
+ # Default for each calendar unit class in IRB:
45
+ # >> Pagy::Calendar::Year::DEFAULT
46
+ # >> Pagy::Calendar::Quarter::DEFAULT
47
+ # >> Pagy::Calendar::Month::DEFAULT
48
+ # >> Pagy::Calendar::Week::DEFAULT
49
+ # >> Pagy::Calendar::Day::DEFAULT
62
50
  #
63
51
  # Uncomment the following lines, if you need calendar localization without using the I18n extra
64
52
  # module LocalizePagyCalendar
@@ -69,15 +57,17 @@
69
57
  # Pagy::Calendar.prepend LocalizePagyCalendar
70
58
 
71
59
  # Countless extra: Paginate without any count, saving one query per rendering
72
- # See https://ddnexus.github.io/pagy/extras/countless
60
+ # See https://ddnexus.github.io/pagy/docs/extras/countless
73
61
  # require 'pagy/extras/countless'
74
62
  # Pagy::DEFAULT[:countless_minimal] = false # default (eager loading)
75
63
 
76
64
  # Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
77
- # See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
78
- # default :pagy_search method: change only if you use also
65
+ # See https://ddnexus.github.io/pagy/docs/extras/elasticsearch_rails
66
+ # Default :pagy_search method: change only if you use also
79
67
  # the searchkick or meilisearch extra that defines the same
80
- # Pagy::DEFAULT[:elasticsearch_rails_search_method] = :pagy_search
68
+ # Pagy::DEFAULT[:elasticsearch_rails_pagy_search] = :pagy_search
69
+ # Default original :search method called internally to do the actual search
70
+ # Pagy::DEFAULT[:elasticsearch_rails_search] = :search
81
71
  # require 'pagy/extras/elasticsearch_rails'
82
72
 
83
73
  # Headers extra: http response headers (and other helpers) useful for API pagination
@@ -89,25 +79,29 @@
89
79
  # pages: 'Total-Pages' } # default
90
80
 
91
81
  # Meilisearch extra: Paginate `Meilisearch` result objects
92
- # See https://ddnexus.github.io/pagy/extras/meilisearch
93
- # default :pagy_search method: change only if you use also
82
+ # See https://ddnexus.github.io/pagy/docs/extras/meilisearch
83
+ # Default :pagy_search method: change only if you use also
94
84
  # the elasticsearch_rails or searchkick extra that define the same method
95
- # Pagy::DEFAULT[:meilisearch_search_method] = :pagy_search
85
+ # Pagy::DEFAULT[:meilisearch_pagy_search] = :pagy_search
86
+ # Default original :search method called internally to do the actual search
87
+ # Pagy::DEFAULT[:meilisearch_search] = :ms_search
96
88
  # require 'pagy/extras/meilisearch'
97
89
 
98
90
  # Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
99
- # See https://ddnexus.github.io/pagy/extras/metadata
100
- # you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
101
- # require 'pagy/extras/shared'
91
+ # See https://ddnexus.github.io/pagy/docs/extras/metadata
92
+ # you must require the JS Tools internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
93
+ # require 'pagy/extras/js_tools'
102
94
  # require 'pagy/extras/metadata'
103
95
  # For performance reasons, you should explicitly set ONLY the metadata you use in the frontend
104
96
  # Pagy::DEFAULT[:metadata] = %i[scaffold_url page prev next last] # example
105
97
 
106
98
  # Searchkick extra: Paginate `Searchkick::Results` objects
107
- # See https://ddnexus.github.io/pagy/extras/searchkick
108
- # default :pagy_search method: change only if you use also
99
+ # See https://ddnexus.github.io/pagy/docs/extras/searchkick
100
+ # Default :pagy_search method: change only if you use also
109
101
  # the elasticsearch_rails or meilisearch extra that defines the same
110
- # DEFAULT[:searchkick_search_method] = :pagy_search
102
+ # DEFAULT[:searchkick_pagy_search] = :pagy_search
103
+ # Default original :search method called internally to do the actual search
104
+ # Pagy::DEFAULT[:searchkick_search] = :search
111
105
  # require 'pagy/extras/searchkick'
112
106
  # uncomment if you are going to use Searchkick.pagy_search
113
107
  # Searchkick.extend Pagy::Searchkick
@@ -116,51 +110,34 @@
116
110
  # Frontend Extras
117
111
 
118
112
  # Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
119
- # See https://ddnexus.github.io/pagy/extras/bootstrap
113
+ # See https://ddnexus.github.io/pagy/docs/extras/bootstrap
120
114
  # require 'pagy/extras/bootstrap'
121
115
 
122
116
  # Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
123
- # See https://ddnexus.github.io/pagy/extras/bulma
117
+ # See https://ddnexus.github.io/pagy/docs/extras/bulma
124
118
  # require 'pagy/extras/bulma'
125
119
 
126
- # Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination
127
- # See https://ddnexus.github.io/pagy/extras/foundation
128
- # require 'pagy/extras/foundation'
129
-
130
- # Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination
131
- # See https://ddnexus.github.io/pagy/extras/materialize
132
- # require 'pagy/extras/materialize'
133
-
134
- # Navs extra: Add nav_js and combo_nav_js javascript helpers
135
- # Notice: the other frontend extras add their own framework-styled versions,
136
- # so require this extra only if you need the unstyled version
137
- # See https://ddnexus.github.io/pagy/extras/navs
138
- # require 'pagy/extras/navs'
139
-
140
- # Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination
141
- # See https://ddnexus.github.io/pagy/extras/semantic
142
- # require 'pagy/extras/semantic'
143
-
144
- # UIkit extra: Add nav helper and templates for UIkit pagination
145
- # See https://ddnexus.github.io/pagy/extras/uikit
146
- # require 'pagy/extras/uikit'
120
+ # Pagy extra: Add the pagy styled versions of the javascript-powered navs
121
+ # and a few other components to the Pagy::Frontend module.
122
+ # See https://ddnexus.github.io/pagy/docs/extras/pagy
123
+ # require 'pagy/extras/pagy'
147
124
 
148
125
  # Multi size var used by the *_nav_js helpers
149
- # See https://ddnexus.github.io/pagy/extras/navs#steps
150
- # Pagy::DEFAULT[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
126
+ # See https://ddnexus.github.io/pagy/docs/extras/pagy#steps
127
+ # Pagy::DEFAULT[:steps] = { 0 => 5, 540 => 7, 720 => 9 } # example
151
128
 
152
129
 
153
130
  # Feature Extras
154
131
 
155
132
  # Gearbox extra: Automatically change the number of items per page depending on the page number
156
- # See https://ddnexus.github.io/pagy/extras/gearbox
133
+ # See https://ddnexus.github.io/pagy/docs/extras/gearbox
157
134
  # require 'pagy/extras/gearbox'
158
135
  # set to false only if you want to make :gearbox_extra an opt-in variable
159
136
  # Pagy::DEFAULT[:gearbox_extra] = false # default true
160
137
  # Pagy::DEFAULT[:gearbox_items] = [15, 30, 60, 100] # default
161
138
 
162
139
  # Items extra: Allow the client to request a custom number of items per page with an optional selector UI
163
- # See https://ddnexus.github.io/pagy/extras/items
140
+ # See https://ddnexus.github.io/pagy/docs/extras/items
164
141
  # require 'pagy/extras/items'
165
142
  # set to false only if you want to make :items_extra an opt-in variable
166
143
  # Pagy::DEFAULT[:items_extra] = false # default true
@@ -168,38 +145,40 @@
168
145
  # Pagy::DEFAULT[:max_items] = 100 # default
169
146
 
170
147
  # Overflow extra: Allow for easy handling of overflowing pages
171
- # See https://ddnexus.github.io/pagy/extras/overflow
148
+ # See https://ddnexus.github.io/pagy/docs/extras/overflow
172
149
  # require 'pagy/extras/overflow'
173
150
  # Pagy::DEFAULT[:overflow] = :empty_page # default (other options: :last_page and :exception)
174
151
 
175
- # Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination
176
- # See https://ddnexus.github.io/pagy/extras/support
177
- # require 'pagy/extras/support'
178
-
179
152
  # Trim extra: Remove the page=1 param from links
180
- # See https://ddnexus.github.io/pagy/extras/trim
153
+ # See https://ddnexus.github.io/pagy/docs/extras/trim
181
154
  # require 'pagy/extras/trim'
182
155
  # set to false only if you want to make :trim_extra an opt-in variable
183
156
  # Pagy::DEFAULT[:trim_extra] = false # default true
184
157
 
185
158
  # Standalone extra: Use pagy in non Rack environment/gem
186
- # See https://ddnexus.github.io/pagy/extras/standalone
159
+ # See https://ddnexus.github.io/pagy/docs/extras/standalone
187
160
  # require 'pagy/extras/standalone'
188
161
  # Pagy::DEFAULT[:url] = 'http://www.example.com/subdir' # optional default
189
162
 
163
+ # Jsonapi extra: Implements JSON:API specifications
164
+ # See https://ddnexus.github.io/pagy/docs/extras/jsonapi
165
+ # require 'pagy/extras/jsonapi' # must be required after the other extras
166
+ # set to false only if you want to make :jsonapi an opt-in variable
167
+ # Pagy::DEFAULT[:jsonapi] = false # default true
190
168
 
191
169
  # Rails
192
-
193
- # Rails: extras assets path required by the helpers that use javascript
170
+ # Enable the .js file required by the helpers that use javascript
194
171
  # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
195
- # See https://ddnexus.github.io/pagy/extras#javascript
196
- # Rails.application.config.assets.paths << Pagy.root.join('javascripts')
172
+ # See https://ddnexus.github.io/pagy/docs/api/javascript
197
173
 
174
+ # With the asset pipeline
175
+ # Sprockets need to look into the pagy javascripts dir, so add it to the assets paths
176
+ # Rails.application.config.assets.paths << Pagy.root.join('javascripts')
198
177
 
199
178
  # I18n
200
179
 
201
180
  # Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
202
- # See https://ddnexus.github.io/pagy/api/frontend#i18n
181
+ # See https://ddnexus.github.io/pagy/docs/api/i18n
203
182
  # Notice: No need to configure anything in this section if your app uses only "en"
204
183
  # or if you use the i18n extra below
205
184
  #
@@ -228,12 +207,9 @@
228
207
 
229
208
  # I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
230
209
  # than the default pagy internal i18n (see above)
231
- # See https://ddnexus.github.io/pagy/extras/i18n
210
+ # See https://ddnexus.github.io/pagy/docs/extras/i18n
232
211
  # require 'pagy/extras/i18n'
233
212
 
234
- # Default i18n key
235
- # Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default
236
-
237
213
 
238
214
  # When you are done setting your own default freeze it, so it will not get changed accidentally
239
215
  Pagy::DEFAULT.freeze
@@ -0,0 +1,100 @@
1
+ const Pagy = (() => {
2
+ const rjsObserver = new ResizeObserver((entries) => entries.forEach((e) => e.target.querySelectorAll(".pagy-rjs").forEach((el) => el.pagyRender())));
3
+ const initNav = (el, [tokens, sequels, labelSequels, trimParam]) => {
4
+ const container = el.parentElement ?? el;
5
+ const widths = Object.keys(sequels).map((w) => parseInt(w)).sort((a, b) => b - a);
6
+ let lastWidth = -1;
7
+ const fillIn = (a, page, label) => a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);
8
+ (el.pagyRender = function() {
9
+ const width = widths.find((w) => w < container.clientWidth) || 0;
10
+ if (width === lastWidth) {
11
+ return;
12
+ }
13
+ let html = tokens.before;
14
+ const series = sequels[width.toString()];
15
+ const labels = labelSequels?.[width.toString()] ?? series.map((l) => l.toString());
16
+ series.forEach((item, i) => {
17
+ const label = labels[i];
18
+ let filled;
19
+ if (typeof item === "number") {
20
+ filled = fillIn(tokens.a, item.toString(), label);
21
+ } else if (item === "gap") {
22
+ filled = tokens.gap;
23
+ } else {
24
+ filled = fillIn(tokens.current, item, label);
25
+ }
26
+ html += typeof trimParam === "string" && item == 1 ? trim(filled, trimParam) : filled;
27
+ });
28
+ html += tokens.after;
29
+ el.innerHTML = "";
30
+ el.insertAdjacentHTML("afterbegin", html);
31
+ lastWidth = width;
32
+ })();
33
+ if (el.classList.contains("pagy-rjs")) {
34
+ rjsObserver.observe(container);
35
+ }
36
+ };
37
+ const initCombo = (el, [url_token, trimParam]) => initInput(el, (inputValue) => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);
38
+ const initSelector = (el, [from, url_token, trimParam]) => {
39
+ initInput(el, (inputValue) => {
40
+ const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();
41
+ const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);
42
+ return [page, url];
43
+ }, trimParam);
44
+ };
45
+ const initInput = (el, getVars, trimParam) => {
46
+ const input = el.querySelector("input");
47
+ const link = el.querySelector("a");
48
+ const initial = input.value;
49
+ const action = function() {
50
+ if (input.value === initial) {
51
+ return;
52
+ }
53
+ const [min, val, max] = [input.min, input.value, input.max].map((n) => parseInt(n) || 0);
54
+ if (val < min || val > max) {
55
+ input.value = initial;
56
+ input.select();
57
+ return;
58
+ }
59
+ let [page, url] = getVars(input.value);
60
+ if (typeof trimParam === "string" && page === "1") {
61
+ url = trim(url, trimParam);
62
+ }
63
+ link.href = url;
64
+ link.click();
65
+ };
66
+ ["change", "focus"].forEach((e) => input.addEventListener(e, () => input.select()));
67
+ input.addEventListener("focusout", action);
68
+ input.addEventListener("keypress", (e) => {
69
+ if (e.key === "Enter") {
70
+ action();
71
+ }
72
+ });
73
+ };
74
+ const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), "");
75
+ return {
76
+ version: "8.6.2",
77
+ init(arg) {
78
+ const target = arg instanceof Element ? arg : document;
79
+ const elements = target.querySelectorAll("[data-pagy]");
80
+ for (const el of elements) {
81
+ try {
82
+ const uint8array = Uint8Array.from(atob(el.getAttribute("data-pagy")), (c) => c.charCodeAt(0));
83
+ const [keyword, ...args] = JSON.parse(new TextDecoder().decode(uint8array));
84
+ if (keyword === "nav") {
85
+ initNav(el, args);
86
+ } else if (keyword === "combo") {
87
+ initCombo(el, args);
88
+ } else if (keyword === "selector") {
89
+ initSelector(el, args);
90
+ } else {
91
+ console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'", el, keyword);
92
+ }
93
+ } catch (err) {
94
+ console.warn("Skipped Pagy.init() for: %o\n%s", el, err);
95
+ }
96
+ }
97
+ }
98
+ };
99
+ })();
100
+ export default Pagy;
@@ -0,0 +1,5 @@
1
+ declare const Pagy: {
2
+ version: string;
3
+ init(arg?: Element | never): void;
4
+ };
5
+ export default Pagy;