From b0baaa58c97bd2d317d1f253c602e73d6b624877 Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Fri, 7 May 2021 08:50:57 +0700 Subject: [PATCH] simplified standalone_app.ru --- apps/standalone_app.ru | 53 ++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/apps/standalone_app.ru b/apps/standalone_app.ru index 2a73f77f9..1b44f9891 100644 --- a/apps/standalone_app.ru +++ b/apps/standalone_app.ru @@ -1,29 +1,27 @@ # frozen_string_literal: true -# Self-contained sinatra app usable to easily reproduce any pagy issue +# Self-contained, standalone sinatra app usable to easily reproduce any pagy issue # USAGE: rerun -- rackup -o 0.0.0.0 -p 8080 apps/basic_app.ru # Available at http://0.0.0.0:8080 -require "bundler/inline" +require 'bundler/inline' # edit this gemfile declaration as you need # and ensure to use gems updated to the latest versions gemfile true do - source "https://rubygems.org" + source 'https://rubygems.org' gem 'oj' gem 'rack' - gem 'rake' gem 'pagy' gem 'rerun' gem 'puma' gem 'sinatra' gem 'sinatra-contrib' end -puts "Pagy::VERSION: #{Pagy::VERSION}" -# edit this section adding/removing the extras and Pagy::VARS as you need +# edit this section adding/removing the extras and Pagy::VARS as needed # pagy initializer require 'pagy/extras/navs' require 'pagy/extras/items' @@ -33,12 +31,15 @@ Pagy::VARS[:trim] = false # opt-in trim # sinatra setup require 'sinatra/base' +# sinatra application class PagyApp < Sinatra::Base - # sinatra application - enable :inline_templates + configure do + enable :inline_templates + end + + include Pagy::Backend - include Pagy::Backend # rubocop:disable Style/MixinUsage # edit this section adding your own helpers as you need helpers do include Pagy::Frontend @@ -49,21 +50,18 @@ class PagyApp < Sinatra::Base send_file Pagy.root.join('javascripts', 'pagy.js') end - get '/' do - erb :welcome - end - # edit this action as you need - get '/pagy_issue' do + get '/' do collection = MockCollection.new @pagy, @records = pagy(collection) - erb :pagy_issue # template available in the __END__ section as @@ pagy_issue + erb :pagy_demo # template available in the __END__ section as @@ pagy_issue end + end # simple array-based collection that acts as standard DB collection # use it as a simple way to get a collection that acts as a AR scope, but without any DB -# Or use ActiveRecord if you prefer +# or create an ActiveRecord class or anything else that you need instead class MockCollection < Array def initialize(arr=Array(1..1000)) super @@ -99,15 +97,20 @@ __END__ -@@ welcome -

Pagy app

-

This app runs on Sinatra/Puma

- - -@@ pagy_issue -

Edit this view as you need

-

@records

-

<%= @records.join(',') %>

+@@ pagy_demo +

Pagy Standalone

+

Self-contained, standalone sinatra app usable to easily reproduce any pagy issue.

+

Please, report the following versions in any new issue.

+

Versions

+ +
+

Pagy Helpers

+

@records: <%= @records.join(',') %>


<%= pagy_nav(@pagy) %>