Skip to content

Commit

Permalink
simplified standalone_app.ru
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed May 7, 2021
1 parent 5442b34 commit b0baaa5
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions apps/standalone_app.ru
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -99,15 +97,20 @@ __END__
</html>


@@ welcome
<h3>Pagy app</h3>
<p>This app runs on Sinatra/Puma</p>


@@ pagy_issue
<h3>Edit this view as you need</h3>
<p>@records</p>
<p><%= @records.join(',') %></p>
@@ pagy_demo
<h3>Pagy Standalone</h3>
<p> Self-contained, standalone sinatra app usable to easily reproduce any pagy issue.</p>
<p>Please, report the following versions in any new issue.</p>
<h4>Versions</h4>
<ul>
<li>Ruby: <%= RUBY_VERSION %></li>
<li>Rack: <%= Rack::RELEASE %></li>
<li>Sinatra: <%= Sinatra::VERSION %></li>
<li>Pagy: <%= Pagy::VERSION %></li>
</ul>
<hr>
<h4>Pagy Helpers</h4>
<p>@records: <%= @records.join(',') %></p>
<br>
<%= pagy_nav(@pagy) %>
<br>
Expand Down

0 comments on commit b0baaa5

Please sign in to comment.