-
Notifications
You must be signed in to change notification settings - Fork 394
/
repro.ru
168 lines (140 loc) Β· 3.59 KB
/
repro.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# 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.2.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
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<script src="<%= %(/#{PAGY_JS}) %>"></script>
<script type="application/javascript">
window.addEventListener("load", Pagy.init);
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
@media screen { html, body {
font-size: 1rem;
line-heigth: 1.2s;
padding: 0;
margin: 0;
} }
body {
background: white !important;
margin: 0 !important;
font-family: sans-serif !important;
}
.content {
padding: 1rem 1.5rem 2rem !important;
}
/* Quick demo for overriding the element style attribute of certain pagy helpers
.pagy input[style] {
width: 5rem !important;
}
*/
/*
If you want to customize the style,
please replace the line below with the actual file content
*/
<%= Pagy.root.join('stylesheets', 'pagy.css').read %>
</style>
</head>
<body>
<%= yield %>
</body>
</html>
@@ main
<div class="content">
<h3>Pagy Repro App</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>
<h4>Collection</h4>
<p>@records: <%= @records.join(',') %></p>
<hr>
<h4>pagy_nav</h4>
<%= pagy_nav(@pagy) %>
<h4>pagy_nav_js</h4>
<%= pagy_nav_js(@pagy) %>
<h4>pagy_combo_nav_js</h4>
<%= pagy_combo_nav_js(@pagy) %>
<h4>pagy_items_selector_js</h4>
<%= pagy_items_selector_js(@pagy) %>
<h4>pagy_info</h4>
<%= pagy_info(@pagy) %>
</div>