From 6bf5b9125bc593da9c25f5f975c4cd360908889e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Morais?= <385232+gnclmorais@users.noreply.github.com> Date: Fri, 19 Dec 2025 22:12:02 +0100 Subject: [PATCH 1/2] Updade pagy gem --- Gemfile | 2 +- Gemfile.lock | 7 +- app/controllers/admin/members_controller.rb | 2 +- app/controllers/application_controller.rb | 2 +- app/helpers/application_helper.rb | 1 - app/views/shared/_pagination.html.haml | 4 +- config/initializers/pagy.rb | 252 +------------------- 7 files changed, 15 insertions(+), 255 deletions(-) diff --git a/Gemfile b/Gemfile index 99ad6b26f..b1cbf35ab 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem 'simple_form' gem 'terser' -gem 'pagy' +gem 'pagy', '~> 43.2' gem 'icalendar' gem 'tzinfo-data' diff --git a/Gemfile.lock b/Gemfile.lock index e7ff1f025..7ac1bb04e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -329,7 +329,9 @@ GEM actionpack (>= 4.2) omniauth (~> 2.0) ostruct (0.6.3) - pagy (6.4.3) + pagy (43.2.2) + json + yaml parallel (1.27.0) parser (3.3.10.0) ast (~> 2.4.1) @@ -581,6 +583,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) + yaml (0.4.0) zeitwerk (2.7.4) PLATFORMS @@ -634,7 +637,7 @@ DEPENDENCIES omniauth omniauth-github omniauth-rails_csrf_protection - pagy + pagy (~> 43.2) pg pickadate-rails premailer-rails diff --git a/app/controllers/admin/members_controller.rb b/app/controllers/admin/members_controller.rb index 2600de475..16dc202f1 100644 --- a/app/controllers/admin/members_controller.rb +++ b/app/controllers/admin/members_controller.rb @@ -16,7 +16,7 @@ def events load_attendance_data(@member) past_rsvps = @member.past_rsvps - @pagy, @past_rsvps = pagy_array(past_rsvps) + @pagy, @past_rsvps = pagy(:offset, items: past_rsvps) end def update_subscriptions diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f41c5acd6..6339dd9f2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception include Pundit::Authorization - include Pagy::Backend + include Pagy::Method if Rails.env.production? rescue_from Exception do |ex| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 292acb5cc..f4e86f1c4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,4 @@ module ApplicationHelper - include Pagy::Frontend def humanize_date(datetime, end_time = nil, with_time: false, with_year: false) return I18n.l(datetime, format: :humanised_with_year) if with_year diff --git a/app/views/shared/_pagination.html.haml b/app/views/shared/_pagination.html.haml index 47b088e37..625783dbd 100644 --- a/app/views/shared/_pagination.html.haml +++ b/app/views/shared/_pagination.html.haml @@ -1,6 +1,6 @@ .row.align-items-center.justify-content-between .col-auto %p.mb-3 - != pagy_info(pagy, item_name: model.pluralize(pagy.count)) + != @pagy.info_tag(item_name: model.pluralize(@pagy.count)) .col-auto - != pagy_bootstrap_nav(pagy) if pagy.pages > 1 \ No newline at end of file + != @pagy.series_nav(:bootstrap) if @pagy.pages > 1 \ No newline at end of file diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index c556ffccb..38b9750ea 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -1,250 +1,8 @@ # frozen_string_literal: true -# Pagy initializer file (6.2.0) -# 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 options +Pagy.options[:size] = [1, 3, 3, 1] +Pagy.options[:overflow] = :empty_page - -# Pagy DEFAULT Variables -# See https://ddnexus.github.io/pagy/docs/api/pagy#variables -# All the Pagy::DEFAULT are set for all the Pagy instances but can be overridden per instance by just passing them to -# Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods - - -# Instance variables -# See https://ddnexus.github.io/pagy/docs/api/pagy#instance-variables -# Pagy::DEFAULT[:page] = 1 # default -# Pagy::DEFAULT[:items] = 20 # default -# Pagy::DEFAULT[:outset] = 0 # default - - -# Other Variables -# See https://ddnexus.github.io/pagy/docs/api/pagy#other-variables -Pagy::DEFAULT[:size] = [1,3,3,1] # default -# Pagy::DEFAULT[:page_param] = :page # default -# The :params can be also set as a lambda e.g ->(params){ params.exclude('useless').merge!('custom' => 'useful') } -# Pagy::DEFAULT[:params] = {} # default -# Pagy::DEFAULT[:fragment] = '#fragment' # example -# Pagy::DEFAULT[:link_extra] = 'data-remote="true"' # example -# Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default -# Pagy::DEFAULT[:cycle] = true # example -# Pagy::DEFAULT[:request_path] = "/foo" # example - - -# Extras -# See https://ddnexus.github.io/pagy/categories/extra - - -# 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 unit -# Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination -# Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format -# -# Pagy::Calendar::Quarter::DEFAULT[:order] = :asc # Time direction of pagination -# Pagy::Calendar::Quarter::DEFAULT[:format] = '%Y-Q%q' # strftime format -# -# Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination -# Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format -# -# Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination -# Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format -# -# Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination -# Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format -# -# 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 http://ddnexus.github.io/pagy/extras/headers -# require 'pagy/extras/headers' -# Pagy::DEFAULT[:headers] = { page: 'Current-Page', -# items: 'Page-Items', -# count: 'Total-Count', -# pages: 'Total-Pages' } # default - -# 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 frontend helpers internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels -# require 'pagy/extras/frontend_helpers' -# 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 -# 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 - - -# 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' - -# Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination -# See https://ddnexus.github.io/pagy/docs/extras/foundation -# require 'pagy/extras/foundation' - -# Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination -# See https://ddnexus.github.io/pagy/docs/extras/materialize -# require 'pagy/extras/materialize' - -# Navs extra: Add nav_js and combo_nav_js javascript helpers -# Notice: the other frontend extras add their own framework-styled versions, -# so require this extra only if you need the unstyled version -# See https://ddnexus.github.io/pagy/docs/extras/navs -# require 'pagy/extras/navs' - -# Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination -# See https://ddnexus.github.io/pagy/docs/extras/semantic -# require 'pagy/extras/semantic' - -# UIkit extra: Add nav helper and templates for UIkit pagination -# See https://ddnexus.github.io/pagy/docs/extras/uikit -# require 'pagy/extras/uikit' - -# Multi size var used by the *_nav_js helpers -# See https://ddnexus.github.io/pagy/docs/extras/navs#steps -# Pagy::DEFAULT[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example - - -# Feature Extras - -# Gearbox extra: Automatically change the number of items 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_items] = [15, 30, 60, 100] # default - -# Items extra: Allow the client to request a custom number of items per page with an optional selector UI -# See https://ddnexus.github.io/pagy/docs/extras/items -# require 'pagy/extras/items' -# set to false only if you want to make :items_extra an opt-in variable -# Pagy::DEFAULT[:items_extra] = false # default true -# Pagy::DEFAULT[:items_param] = :items # default -# Pagy::DEFAULT[:max_items] = 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) - -# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination -# See https://ddnexus.github.io/pagy/docs/extras/support -# require 'pagy/extras/support' - -# 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 - - -# Rails -# Enable the .js file required by the helpers that use javascript -# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_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') - -# 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') -# -# 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| ... } ) - - -# 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' - -# Default i18n key -# Pagy::DEFAULT[:i18n_key] = 'pagy.item_name' # default - - -# When you are done setting your own default freeze it, so it will not get changed accidentally -Pagy::DEFAULT.freeze \ No newline at end of file +# Freeze options so they don't get changed accidentally +Pagy.options.freeze From 57e4b6fd84b26eea9cc8a54257720ecad9c1a77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Morais?= <385232+gnclmorais@users.noreply.github.com> Date: Tue, 23 Dec 2025 11:22:34 +0100 Subject: [PATCH 2/2] Change Pagy use on partial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suggestion was “we can pass in a local variable named pagy to this and other partials. That prepares us for Strict Locals in the future.” --- app/views/shared/_pagination.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/shared/_pagination.html.haml b/app/views/shared/_pagination.html.haml index 625783dbd..2c937447d 100644 --- a/app/views/shared/_pagination.html.haml +++ b/app/views/shared/_pagination.html.haml @@ -1,6 +1,6 @@ .row.align-items-center.justify-content-between .col-auto %p.mb-3 - != @pagy.info_tag(item_name: model.pluralize(@pagy.count)) + != pagy.info_tag(item_name: model.pluralize(pagy.count)) .col-auto - != @pagy.series_nav(:bootstrap) if @pagy.pages > 1 \ No newline at end of file + != pagy.series_nav(:bootstrap) if pagy.pages > 1