# frozen_string_literal: true
# Starting point app to try pagy or reproduce issues
# DEV USAGE
# pagy clone repro
# pagy ./repro.ru
# URL
# http://0.0.0.0:8000
# HELP
# pagy -h
# DOC
# https://ddnexus.github.io/pagy/playground/#1-repro-app
VERSION = '8.1.0'
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'oj'
gem 'puma'
gem 'sinatra'
gem 'sinatra-contrib'
end
# Edit this section adding/removing the extras and Pagy::DEFAULT as needed
# pagy initializer
require 'pagy/extras/pagy'
require 'pagy/extras/items'
require 'pagy/extras/overflow'
Pagy::DEFAULT[:overflow] = :empty_page
Pagy::DEFAULT[:size] = [1, 4, 4, 1]
Pagy::DEFAULT.freeze
require 'sinatra/base'
# Sinatra application
class PagyRepro < Sinatra::Base
PAGY_JS = "pagy#{'-dev' if ENV['DEBUG']}.js".freeze
configure do
enable :inline_templates
end
include Pagy::Backend
# Serve pagy.js or pagy-dev.js
get("/#{PAGY_JS}") do
content_type 'application/javascript'
send_file Pagy.root.join('javascripts', PAGY_JS)
end
# Edit this action as needed
get '/' do
collection = MockCollection.new
@pagy, @records = pagy(collection)
erb :main # template available in the __END__ section as @@ main
end
# Edit this section adding your own helpers as needed
helpers do
include Pagy::Frontend
end
end
# Simple array-based collection that acts as a standard DB collection.
# Use it as a simple way to get a collection that acts as a AR scope, but without any DB
# or create an ActiveRecord class or anything else that you need instead
class MockCollection < Array
def initialize(arr = Array(1..1000))
super
@collection = clone
end
def offset(value)
@collection = self[value..]
self
end
def limit(value)
@collection[0, value]
end
def count(*)
size
end
end
run PagyRepro
__END__
@@ layout
Pagy Repro App
Self-contained, standalone Sinatra app usable to easily reproduce any pagy issue.
Please, report the following versions in any new issue.
Versions
- Ruby: <%= RUBY_VERSION %>
- Rack: <%= Rack::RELEASE %>
- Sinatra: <%= Sinatra::VERSION %>
- Pagy: <%= Pagy::VERSION %>
Collection
@records: <%= @records.join(',') %>
pagy_nav
<%= pagy_nav(@pagy) %>
pagy_nav_js
<%= pagy_nav_js(@pagy) %>
pagy_combo_nav_js
<%= pagy_combo_nav_js(@pagy) %>
pagy_items_selector_js
<%= pagy_items_selector_js(@pagy) %>
pagy_info
<%= pagy_info(@pagy) %>