Compare commits

...

13 Commits
main ... pagy

  1. 10
      Gemfile
  2. 30
      Gemfile.lock
  3. 2
      Procfile.dev
  4. 3
      README.md
  5. 5
      app/assets/stylesheets/application.css
  6. 15
      app/assets/stylesheets/application.tailwind.css
  7. 34
      app/assets/stylesheets/tailwind/pagy.css
  8. 0
      app/assets/stylesheets/toastify.css
  9. 0
      app/assets/stylesheets/turbo.css
  10. 5
      app/controllers/scores_controller.rb
  11. 1
      app/helpers/application_helper.rb
  12. 5
      app/views/layouts/application.html.erb
  13. 8
      app/views/scores/index.html.erb
  14. 2
      config/credentials.yml.enc
  15. 14
      config/initializers/monkey_patcher.rb
  16. 230
      config/initializers/pagy.rb
  17. 14
      lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb

10
Gemfile

@ -1,8 +1,10 @@
source 'https://rubygems.org'
ruby '3.1.2'
source 'https://rubygems.org'
gem 'bootsnap', require: false
gem 'importmap-rails'
gem 'pagy'
gem 'pg'
gem 'puma'
gem 'rackup'
@ -11,15 +13,14 @@ gem 'rails_semantic_logger'
gem 'sprockets-rails'
gem 'stimulus-rails'
gem 'tailwindcss-rails'
gem 'turbo-rails'
group :development do
gem 'rails_live_reload'
gem 'turbo-rails', '~> 1' # works well with rails_live_reload
gem 'amazing_print'
gem 'debug'
gem 'error_highlight'
gem 'htmlbeautifier'
gem 'rails_live_reload'
gem 'rainbow'
gem 'rubocop', require: false
gem 'rubocop-packaging'
@ -28,7 +29,6 @@ group :development do
gem 'rubocop-shopify'
gem 'rubocop-thread_safety'
gem 'ruby-lsp-rails'
gem 'web-console'
end
group :test do

30
Gemfile.lock

@ -81,7 +81,6 @@ GEM
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.7)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
builder (3.2.4)
@ -118,7 +117,7 @@ GEM
irb (1.12.0)
rdoc
reline (>= 0.4.2)
json (2.7.1)
json (2.7.2)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
@ -159,6 +158,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.3-x86_64-linux)
racc (~> 1.4)
pagy (8.0.1)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
@ -218,7 +218,7 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.0)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
@ -250,7 +250,7 @@ GEM
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.28.0)
rubocop-rspec (2.29.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
@ -261,15 +261,12 @@ GEM
rubocop (~> 1.51)
rubocop-thread_safety (0.5.1)
rubocop (>= 0.90.0)
ruby-lsp (0.14.6)
ruby-lsp (0.16.2)
language_server-protocol (~> 3.17.0)
prism (>= 0.22.0, < 0.25)
sorbet-runtime (>= 0.5.10782)
ruby-lsp-rails (0.3.3)
actionpack (>= 6.0)
activerecord (>= 6.0)
railties (>= 6.0)
ruby-lsp (>= 0.14.2, < 0.15.0)
ruby-lsp-rails (0.3.5)
ruby-lsp (>= 0.16.0, < 0.17.0)
sorbet-runtime (>= 0.5.9897)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
@ -280,7 +277,7 @@ GEM
websocket (~> 1.0)
semantic_logger (4.15.0)
concurrent-ruby (~> 1.0)
sorbet-runtime (0.5.11323)
sorbet-runtime (0.5.11332)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
@ -305,18 +302,13 @@ GEM
railties (>= 6.0.0)
thor (1.3.1)
timeout (0.4.1)
turbo-rails (1.5.0)
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
@ -342,6 +334,7 @@ DEPENDENCIES
error_highlight
htmlbeautifier
importmap-rails
pagy
pg
puma
rackup
@ -360,8 +353,7 @@ DEPENDENCIES
sprockets-rails
stimulus-rails
tailwindcss-rails
turbo-rails (~> 1)
web-console
turbo-rails
RUBY VERSION
ruby 3.1.2p20

2
Procfile.dev

@ -1,3 +1,3 @@
web: RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}"
web: RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}" -b 127.0.0.1
css: BROWSERSLIST_IGNORE_OLD_DATA=true bundle exec -- rails tailwindcss:watch

3
README.md

@ -39,8 +39,9 @@ rails db:migrate
* [ ] ./bin/prod
* [ ] Syslog
* [x] Pagy
* [ ] Pagination through Turbo Frame
* [ ] Pagy
## Featuring

5
app/assets/stylesheets/application.css

@ -10,6 +10,7 @@
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*= require_directory .
*/
@import "./tailwind/main.css";

15
app/assets/stylesheets/application.tailwind.css

@ -1,13 +1,6 @@
@import "./tailwind/pagy.css";
/* important to be the last 3 lines */
@tailwind base;
@tailwind components;
@tailwind utilities;
/*
@layer components {
.btn-primary {
@apply py-2 px-4 bg-blue-200;
}
}
*/
@tailwind utilities;

34
app/assets/stylesheets/tailwind/pagy.css

@ -0,0 +1,34 @@
.pagy {
@apply flex space-x-1 font-semibold text-sm text-gray-500;
.page {
a {
@apply block rounded-lg px-3 py-1 bg-gray-200;
&:hover {
@apply bg-gray-300;
}
}
&.active a {
@apply text-white bg-gray-400 cursor-default;
}
&.disabled a {
@apply text-gray-300 bg-gray-100 cursor-default;
}
&.gap {}
}
.pagy-combo-input,
&.pagy-items-selector-js {
@apply inline-block whitespace-nowrap bg-gray-200 rounded-lg px-3 py-0.5;
input {
@apply bg-gray-100 border-none rounded-md;
}
}
}

0
app/assets/stylesheets/application.toastify.css → app/assets/stylesheets/toastify.css

0
app/assets/stylesheets/application.turbo.css → app/assets/stylesheets/turbo.css

5
app/controllers/scores_controller.rb

@ -1,10 +1,11 @@
# ScoresController define Score and Grade interactions
class ScoresController < ApplicationController
include Pagy::Backend
before_action :set_score, only: %i[show edit update destroy]
# GET /scores
def index
@scores = Score.all
logger.info 'this is a normal message'
# logger.info({ one: 1, two: 2 })
# logger.info 'this is an information', { four: 4, five: 5 }
@ -15,6 +16,8 @@ class ScoresController < ApplicationController
logger.info 'end of normal message'
# logger.debug @scores
# sleep 0.5
#
@pagy, @records = pagy(Score.all)
end
# GET /scores/1

1
app/helpers/application_helper.rb

@ -1,3 +1,4 @@
# global helper
module ApplicationHelper
include Pagy::Frontend
end

5
app/views/layouts/application.html.erb

@ -8,12 +8,13 @@
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= turbo_refreshes_with method: :morph, scroll: :preserve %>
<%= content_for :head %>
</head>
<body>
<%=render '/layouts/notification' %>
<main class="m-8 flex flex-col">
<%= yield %>
</main>

8
app/views/scores/index.html.erb

@ -5,7 +5,13 @@
<%= link_to "New score", new_score_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
</div>
<%== pagy_nav(@pagy) %>
<div id="scores" class="min-w-full ">
<%= render @scores %>
<% @records.each do |score| %>
<%= render score %>
<%end%>
</div>
<%== pagy_nav(@pagy) %>
</div>

2
config/credentials.yml.enc

@ -1 +1 @@
ovaxoKSdeiJV/0e9nt/RCPbgD4eLKQx5geprTnxq0T78p96rxxS3qunfyIbgObLgcysLKbDi1qoJ33Z+U4j+eWa7t5kquJgLl3bo/AcHyRyCmUy4dCaxwb0bJ2PP5RPlhDzGIoCY1AZay7wCw9+ePnarGVsFcRgC6B9NdDocb3EQZ3g0eISCS8v7jiMBhxknThj2pVePl2ixcghcUAPA4JP6p0ePcWsBEpNGN18RSyDnkVh4eWVSHU1c7owQspeWKeshUs70NiIO4JlntKlnRIW6mO9iibU87k/oRsCZHvlYAc7gKDVB8P6B18qFFnSy6+rfblO3Mn3SdIpa8jaOZBREUt01RBg69Hln2pKiJq0k96Ozlx5z/XtMsHZUBJaKn1vGR1Qc1JzSJIJbiEvpVYxpuler--ZJsF6A9JzD2mo1Sn--1If3OCLqzTlwiT3Gp+u1EQ==
1Rb1o453hQQroeISPYLdIlAlIyzt2nl95+s0mU+FZSLp/CEf2/ZnBa2v5kbAXT7bbsEljSooDEuu4bqUQA5WNbZnt2xe6xWUHgNZxv/+ld41UsvLMLBZZFuXmBzkoCgFdu7wLGpdwW9tdgEe0F8ZKSMincw0qV/vwMmjFxoZAFNo7wvFSYGRHLAjLqveTXK/OFg+/IPs5A==--JBdCkXXdqAJNTYWv--ZMPm5yF9Hw+Jo2g6pcolVQ==

14
config/initializers/monkey_patcher.rb

@ -0,0 +1,14 @@
return unless defined?(Rails::Server)
puts 'MonkeyPatcher runs:'
patches = Dir.glob(Rails.root.join('lib', 'monkey_patches', '**', '*.rb'))
patches.each do |file|
puts "🐵 patching... #{Pathname.new(file).relative_path_from Rails.root}"
require file
end
puts case patches.count
when 0 then 'No patch found'
when 1 then '1 successful patch applied'
else "#{patches.count} successful patches applied"
end

230
config/initializers/pagy.rb

@ -0,0 +1,230 @@
# frozen_string_literal: true
# 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,4,4,1] # default in pagy < 7.0
# Pagy::DEFAULT[:page_param] = :page # default
# Pagy::DEFAULT[:fragment] = '#fragment' # example
# Pagy::DEFAULT[:link_extra] = 'data-remote="true"' # example
# Pagy::DEFAULT[:cycle] = true # example
# Pagy::DEFAULT[:request_path] = '/foo' # example
# Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
# Pagy::DEFAULT[:params] = {} # default
# NOTICE: The :params can be also set as a lambda e.g:
# ->(params){ params.exclude('useless').merge!('custom' => 'useful') }
# 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'
# 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'
# 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/pagy#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)
# 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
# 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: 'fr')
#
# 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'
# When you are done setting your own default freeze it, so it will not get changed accidentally
Pagy::DEFAULT.freeze

14
lib/monkey_patches/rails_semantic_logger/debug_exceptions.rb

@ -0,0 +1,14 @@
require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions'
module ActionDispatch
# patched class to prevent deprecated message
class DebugExceptions
private
def log_error(_request, wrapper)
Rails.application.deprecators.silence do
ActionController::Base.logger.fatal(wrapper.exception)
end
end
end
end
Loading…
Cancel
Save