diff --git a/Gemfile.lock b/Gemfile.lock
index fa34bb91..5d0e2ed8 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -364,7 +364,9 @@ GEM
ostruct (0.6.3)
ox (2.14.23)
bigdecimal (>= 3.0)
- pagy (9.4.0)
+ pagy (43.2.4)
+ json
+ yaml
parallel (1.27.0)
parser (3.3.10.0)
ast (~> 2.4.1)
@@ -587,6 +589,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
+ yaml (0.4.0)
zeitwerk (2.7.4)
PLATFORMS
diff --git a/app/controllers/import_reports_controller.rb b/app/controllers/import_reports_controller.rb
index fc03f3fe..7b6fcf5b 100644
--- a/app/controllers/import_reports_controller.rb
+++ b/app/controllers/import_reports_controller.rb
@@ -1,5 +1,5 @@
class ImportReportsController < ApplicationController
- include Pagy::Backend
+ include Pagy::Method
before_action :redirect_contributors
before_action :set_import_report, only: [ :show ]
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 8c5819dd..15c123a3 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -1,6 +1,6 @@
class TagsController < ApplicationController
- include Pagy::Backend
+ include Pagy::Method
before_action :redirect_contributors
before_action :set_tag, only: [ :show, :edit, :update, :destroy ]
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index d1bb6584..b1767ef5 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -1,6 +1,6 @@
class TopicsController < ApplicationController
include ActiveStorage::SetCurrent
- include Pagy::Backend
+ include Pagy::Method
before_action :set_topic, only: [ :show, :edit, :update, :destroy, :archive, :unarchive ]
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 4ab08a35..b08f6a1c 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
- include Pagy::Backend
+ include Pagy::Method
before_action :redirect_contributors
before_action :set_user, only: %i[ edit update destroy ]
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 716bfe3e..d956a996 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,6 +1,4 @@
module ApplicationHelper
- include Pagy::Frontend
-
def flash_class(level)
case level
when "notice" then "alert-light-success"
diff --git a/app/views/import_reports/index.html.erb b/app/views/import_reports/index.html.erb
index b9c70555..0a1de716 100644
--- a/app/views/import_reports/index.html.erb
+++ b/app/views/import_reports/index.html.erb
@@ -69,7 +69,7 @@
- <%== pagy_nav(@pagy) if @pagy.pages > 1 %>
+ <%== @pagy.series_nav if @pagy.pages > 1 %>
diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb
index fc1cf13c..87cad5c1 100644
--- a/app/views/tags/index.html.erb
+++ b/app/views/tags/index.html.erb
@@ -46,7 +46,7 @@
diff --git a/app/views/topics/index.html.erb b/app/views/topics/index.html.erb
index 7460154f..5d57ca1d 100644
--- a/app/views/topics/index.html.erb
+++ b/app/views/topics/index.html.erb
@@ -36,7 +36,7 @@
<% end %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index 39d23fcd..b1e95769 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -72,7 +72,7 @@
diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb
index 18a6fa61..6f15dea9 100644
--- a/config/initializers/pagy.rb
+++ b/config/initializers/pagy.rb
@@ -1,220 +1,51 @@
# frozen_string_literal: true
-# Pagy initializer file (9.3.3)
-# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
-# Should you just cherry pick part of this file, please maintain the require-order of the extras
+# Pagy initializer file (43.2.4)
+# See https://ddnexus.github.io/pagy/resources/initializer/
-
-# Pagy Variables
-# See https://ddnexus.github.io/pagy/docs/api/pagy#variables
-# You can set any pagy variable as a Pagy::DEFAULT. They can also be overridden per instance by just passing them to
-# Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
-# Here are the few that make more sense as DEFAULTs:
-# Pagy::DEFAULT[:limit] = 20 # default
-# Pagy::DEFAULT[:size] = 7 # default
-# Pagy::DEFAULT[:ends] = true # default
-# Pagy::DEFAULT[:page_param] = :page # default
-# Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
-# Pagy::DEFAULT[:max_pages] = 3000 # example
-
-
-# Extras
-# See https://ddnexus.github.io/pagy/categories/extra
-
-
-# Legacy Compatibility Extras
-
-# Size extra: Enable the Array type for the `:size` variable (e.g. `size: [1,4,4,1]`)
-# See https://ddnexus.github.io/pagy/docs/extras/size
-# require 'pagy/extras/size' # must be required before the other extras
-
-
-# Backend Extras
-
-# Arel extra: For better performance utilizing grouped ActiveRecord collections:
-# See: https://ddnexus.github.io/pagy/docs/extras/arel
-# require 'pagy/extras/arel'
-
-# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
-# See https://ddnexus.github.io/pagy/docs/extras/array
-# require 'pagy/extras/array'
-
-# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
-# See https://ddnexus.github.io/pagy/docs/extras/calendar
-# require 'pagy/extras/calendar'
-# Default for each calendar unit class in IRB:
-# >> Pagy::Calendar::Year::DEFAULT
-# >> Pagy::Calendar::Quarter::DEFAULT
-# >> Pagy::Calendar::Month::DEFAULT
-# >> Pagy::Calendar::Week::DEFAULT
-# >> Pagy::Calendar::Day::DEFAULT
+############ Global Options ################################################################
+# See https://ddnexus.github.io/pagy/toolbox/options/ for details.
+# Add your global options below. They will be applied globally.
+# For example:
#
-# Uncomment the following lines, if you need calendar localization without using the I18n extra
-# module LocalizePagyCalendar
-# def localize(time, opts)
-# ::I18n.l(time, **opts)
-# end
-# end
-# Pagy::Calendar.prepend LocalizePagyCalendar
-
-# Countless extra: Paginate without any count, saving one query per rendering
-# See https://ddnexus.github.io/pagy/docs/extras/countless
-# require 'pagy/extras/countless'
-# Pagy::DEFAULT[:countless_minimal] = false # default (eager loading)
-
-# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
-# See https://ddnexus.github.io/pagy/docs/extras/elasticsearch_rails
-# Default :pagy_search method: change only if you use also
-# the searchkick or meilisearch extra that defines the same
-# Pagy::DEFAULT[:elasticsearch_rails_pagy_search] = :pagy_search
-# Default original :search method called internally to do the actual search
-# Pagy::DEFAULT[:elasticsearch_rails_search] = :search
-# require 'pagy/extras/elasticsearch_rails'
-
-# Headers extra: http response headers (and other helpers) useful for API pagination
-# See https://ddnexus.github.io/pagy/docs/extras/headers
-# require 'pagy/extras/headers'
-# Pagy::DEFAULT[:headers] = { page: 'Current-Page',
-# limit: 'Page-Items',
-# count: 'Total-Count',
-# pages: 'Total-Pages' } # default
-
-# Keyset extra: Paginate with the Pagy keyset pagination technique
-# See https://ddnexus.github.io/pagy/docs/extras/keyset
-# require 'pagy/extras/keyset'
-
-# Meilisearch extra: Paginate `Meilisearch` result objects
-# See https://ddnexus.github.io/pagy/docs/extras/meilisearch
-# Default :pagy_search method: change only if you use also
-# the elasticsearch_rails or searchkick extra that define the same method
-# Pagy::DEFAULT[:meilisearch_pagy_search] = :pagy_search
-# Default original :search method called internally to do the actual search
-# Pagy::DEFAULT[:meilisearch_search] = :ms_search
-# require 'pagy/extras/meilisearch'
-
-# Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
-# See https://ddnexus.github.io/pagy/docs/extras/metadata
-# you must require the JS Tools internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
-# require 'pagy/extras/js_tools'
-# require 'pagy/extras/metadata'
-# For performance reasons, you should explicitly set ONLY the metadata you use in the frontend
-# Pagy::DEFAULT[:metadata] = %i[scaffold_url page prev next last] # example
-
-# Searchkick extra: Paginate `Searchkick::Results` objects
-# See https://ddnexus.github.io/pagy/docs/extras/searchkick
-# Default :pagy_search method: change only if you use also
-# the elasticsearch_rails or meilisearch extra that defines the same
-# Pagy::DEFAULT[:searchkick_pagy_search] = :pagy_search
-# Default original :search method called internally to do the actual search
-# Pagy::DEFAULT[:searchkick_search] = :search
-# require 'pagy/extras/searchkick'
-# uncomment if you are going to use Searchkick.pagy_search
-# Searchkick.extend Pagy::Searchkick
-
+# Pagy.options[:limit] = 10 # Limit the items per page
+# Pagy.options[:client_max_limit] = 100 # The client can request a limit up to 100
+# Pagy.options[:max_pages] = 200 # Allow only 200 pages
+# Pagy.options[:jsonapi] = true # Use JSON:API compliant URLs
-# Frontend Extras
-# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
-# See https://ddnexus.github.io/pagy/docs/extras/bootstrap
-require "pagy/extras/bootstrap"
-
-# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
-# See https://ddnexus.github.io/pagy/docs/extras/bulma
-# require 'pagy/extras/bulma'
-
-# Pagy extra: Add the pagy styled versions of the javascript-powered navs
-# and a few other components to the Pagy::Frontend module.
-# See https://ddnexus.github.io/pagy/docs/extras/pagy
-# require 'pagy/extras/pagy'
-
-# Multi size var used by the *_nav_js helpers
-# See https://ddnexus.github.io/pagy/docs/extras/pagy#steps
-# Pagy::DEFAULT[:steps] = { 0 => 5, 540 => 7, 720 => 9 } # example
-
-
-# Feature Extras
-
-# Gearbox extra: Automatically change the limit per page depending on the page number
-# See https://ddnexus.github.io/pagy/docs/extras/gearbox
-# require 'pagy/extras/gearbox'
-# set to false only if you want to make :gearbox_extra an opt-in variable
-# Pagy::DEFAULT[:gearbox_extra] = false # default true
-# Pagy::DEFAULT[:gearbox_limit] = [15, 30, 60, 100] # default
-
-# Limit extra: Allow the client to request a custom limit per page with an optional selector UI
-# See https://ddnexus.github.io/pagy/docs/extras/limit
-# require 'pagy/extras/limit'
-# set to false only if you want to make :limit_extra an opt-in variable
-# Pagy::DEFAULT[:limit_extra] = false # default true
-# Pagy::DEFAULT[:limit_param] = :limit # default
-# Pagy::DEFAULT[:limit_max] = 100 # default
-
-# Overflow extra: Allow for easy handling of overflowing pages
-# See https://ddnexus.github.io/pagy/docs/extras/overflow
-# require 'pagy/extras/overflow'
-# Pagy::DEFAULT[:overflow] = :empty_page # default (other options: :last_page and :exception)
-
-# Trim extra: Remove the page=1 param from links
-# See https://ddnexus.github.io/pagy/docs/extras/trim
-# require 'pagy/extras/trim'
-# set to false only if you want to make :trim_extra an opt-in variable
-# Pagy::DEFAULT[:trim_extra] = false # default true
-
-# Standalone extra: Use pagy in non Rack environment/gem
-# See https://ddnexus.github.io/pagy/docs/extras/standalone
-# require 'pagy/extras/standalone'
-# Pagy::DEFAULT[:url] = 'http://www.example.com/subdir' # optional default
-
-# Jsonapi extra: Implements JSON:API specifications
-# See https://ddnexus.github.io/pagy/docs/extras/jsonapi
-# require 'pagy/extras/jsonapi' # must be required after the other extras
-# set to false only if you want to make :jsonapi an opt-in variable
-# Pagy::DEFAULT[:jsonapi] = false # default true
+############ JavaScript ####################################################################
+# See https://ddnexus.github.io/pagy/resources/javascript/ for details.
+# Examples for Rails:
+# For apps with an assets pipeline
+# Rails.application.config.assets.paths << Pagy::ROOT.join('javascripts')
+#
+# For apps with a javascript builder (e.g. esbuild, webpack, etc.)
+# javascript_dir = Rails.root.join('app/javascript')
+# Pagy.sync_javascript(javascript_dir, 'pagy.mjs') if Rails.env.development?
-# Rails
-# Enable the .js file required by the helpers that use javascript
-# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_limit_selector_js)
-# See https://ddnexus.github.io/pagy/docs/api/javascript
-# With the asset pipeline
-# Sprockets need to look into the pagy javascripts dir, so add it to the assets paths
-# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
+############# Overriding Pagy::I18n Lookup #################################################
+# Refer to https://ddnexus.github.io/pagy/resources/i18n/ for details.
+# Override the I18n lookup by dropping your custom dictionary in some pagy dir.
+# Example for Rails:
+#
+# Pagy::I18n.pathnames << Rails.root.join('config/locales/pagy')
-# I18n
-# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
-# See https://ddnexus.github.io/pagy/docs/api/i18n
-# Notice: No need to configure anything in this section if your app uses only "en"
-# or if you use the i18n extra below
-#
-# Examples:
-# load the "de" built-in locale:
-# Pagy::I18n.load(locale: 'de')
+############# I18n Gem Translation #########################################################
+# See https://ddnexus.github.io/pagy/resources/i18n/ for details.
#
-# load the "de" locale defined in the custom file at :filepath:
-# Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml')
-#
-# load the "de", "en" and "es" built-in locales:
-# (the first passed :locale will be used also as the default_locale)
-# Pagy::I18n.load({ locale: 'de' },
-# { locale: 'en' },
-# { locale: 'es' })
-#
-# load the "en" built-in locale, a custom "es" locale,
-# and a totally custom locale complete with a custom :pluralize proc:
-# (the first passed :locale will be used also as the default_locale)
-# Pagy::I18n.load({ locale: 'en' },
-# { locale: 'es', filepath: 'path/to/pagy-es.yml' },
-# { locale: 'xyz', # not built-in
-# filepath: 'path/to/pagy-xyz.yml',
-# pluralize: lambda{ |count| ... } )
+Pagy.translate_with_the_slower_i18n_gem!
-# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
-# than the default pagy internal i18n (see above)
-# See https://ddnexus.github.io/pagy/docs/extras/i18n
-require "pagy/extras/i18n"
-
+############# Calendar Localization for non-en locales ####################################
+# See https://ddnexus.github.io/pagy/toolbox/paginators/calendar#localization for details.
+# Add your desired locales to the list and uncomment the following line to enable them,
+# regardless of whether you use the I18n gem for translations or not, whether with
+# Rails or not.
+#
+# Pagy::Calendar.localize_with_rails_i18n_gem(*your_locales)
# When you are done setting your own default freeze it, so it will not get changed accidentally
-Pagy::DEFAULT.freeze
+Pagy.options.freeze
diff --git a/config/locales/pagy.en.yml b/config/locales/pagy.en.yml
index b89680f3..27549a1e 100644
--- a/config/locales/pagy.en.yml
+++ b/config/locales/pagy.en.yml
@@ -1,4 +1,4 @@
en:
pagy:
- prev: "Previous"
+ previous: "Previous"
next: "Next"
\ No newline at end of file
diff --git a/spec/views/tags/index.html.erb_spec.rb b/spec/views/tags/index.html.erb_spec.rb
index fb41e2af..88b84dfd 100644
--- a/spec/views/tags/index.html.erb_spec.rb
+++ b/spec/views/tags/index.html.erb_spec.rb
@@ -1,9 +1,18 @@
require "rails_helper"
RSpec.describe "tags/index", type: :view do
+ let(:request) do
+ request_hash = { base_url: "http://test.host", path: "/tags", params: {}, cookie: nil }
+ Pagy::Request.new(request: request_hash)
+ end
+
+ before(:each) do
+ allow(view).to receive(:params).and_return(ActionController::Parameters.new)
+ end
+
context "when there are no tags" do
before(:each) do
- assign(:pagy, Pagy.new(count: 0))
+ assign(:pagy, Pagy::Offset.new(count: 0, request:))
assign(:tags, [])
end
@@ -15,7 +24,7 @@
context "when there are tags but only one page" do
before(:each) do
- assign(:pagy, Pagy.new(count: 1))
+ assign(:pagy, Pagy::Offset.new(count: 1, request:))
assign(:tags, [ create(:tag, name: "Tag 1") ])
end
@@ -33,7 +42,7 @@
context "when there are multiple pages of tags" do
before(:each) do
# Simulate being on page 2 with 10 items per page and 25 total items
- pagy = Pagy.new(count: 25, page: 2, items: 10)
+ pagy = Pagy::Offset.new(count: 25, page: 2, items: 10, request:)
assign(:pagy, pagy)
assign(:tags, create_list(:tag, 10))
end
diff --git a/spec/views/topics/index.html.erb_spec.rb b/spec/views/topics/index.html.erb_spec.rb
index 13fa09e7..23f921f5 100644
--- a/spec/views/topics/index.html.erb_spec.rb
+++ b/spec/views/topics/index.html.erb_spec.rb
@@ -1,6 +1,11 @@
require "rails_helper"
RSpec.describe "topics/index", type: :view do
+ let(:request) do
+ request_hash = { base_url: "http://test.host", path: "/topics", params: {}, cookie: nil }
+ Pagy::Request.new(request: request_hash)
+ end
+
before(:each) do
def view.search_params = {}
def view.topics_title = "Topics"
@@ -15,7 +20,7 @@ def view.topics_title = "Topics"
context "when there are no topics" do
before(:each) do
- assign(:pagy, Pagy.new(count: 0))
+ assign(:pagy, Pagy::Offset.new(count: 0, request:))
assign(:topics, [])
end
@@ -27,7 +32,7 @@ def view.topics_title = "Topics"
context "when there are topics but only one page" do
before(:each) do
- assign(:pagy, Pagy.new(count: 1))
+ assign(:pagy, Pagy::Offset.new(count: 1, request:))
assign(:topics, [ create(:topic, title: "Topic 1") ])
end
@@ -45,7 +50,7 @@ def view.topics_title = "Topics"
context "when there are multiple pages of topics" do
before(:each) do
# Simulate being on page 2 with 10 items per page and 25 total items
- pagy = Pagy.new(count: 25, page: 2, items: 10)
+ pagy = Pagy::Offset.new(count: 25, page: 2, items: 10, request:)
assign(:pagy, pagy)
assign(:topics, create_list(:topic, 10))
end
diff --git a/spec/views/users/index.html.erb_spec.rb b/spec/views/users/index.html.erb_spec.rb
index 9b984046..68bf3116 100644
--- a/spec/views/users/index.html.erb_spec.rb
+++ b/spec/views/users/index.html.erb_spec.rb
@@ -1,9 +1,14 @@
require "rails_helper"
RSpec.describe "users/index", type: :view do
+ let(:request) do
+ request_hash = { base_url: "http://test.host", path: "/users", params: {}, cookie: nil }
+ Pagy::Request.new(request: request_hash)
+ end
+
context "when there are no users" do
before(:each) do
- assign(:pagy, Pagy.new(count: 0))
+ assign(:pagy, Pagy::Offset.new(count: 0, request:))
assign(:users, [])
end
@@ -15,7 +20,7 @@
context "when there are users but only one page" do
before(:each) do
- assign(:pagy, Pagy.new(count: 1))
+ assign(:pagy, Pagy::Offset.new(count: 1, request:))
assign(:users, [ create(:user, email: "user@test.local") ])
end
@@ -33,7 +38,7 @@
context "when there are multiple pages of users" do
before(:each) do
# Simulate being on page 2 with 10 items per page and 25 total items
- pagy = Pagy.new(count: 25, page: 2, items: 10)
+ pagy = Pagy::Offset.new(count: 25, page: 2, items: 10, request:)
assign(:pagy, pagy)
assign(:users, create_list(:user, 10))
end