Skip to content

Commit f41db2c

Browse files
committed
Replace inline templates with template block in sinatra apps
1 parent e8c1ef2 commit f41db2c

File tree

8 files changed

+608
-605
lines changed

8 files changed

+608
-605
lines changed

.idea/runConfigurations/Rubocop_Autocorrect.xml

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ group :playground do
3333
gem 'rouge'
3434
gem 'sequel'
3535
gem 'sinatra'
36-
gem 'sinatra-contrib'
3736
gem 'sqlite3'
3837
end
3938

Gemfile.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ GEM
150150
builder
151151
minitest (>= 5.0)
152152
ruby-progressbar
153-
multi_json (1.15.0)
154153
mustermann (3.0.3)
155154
ruby2_keywords (~> 0.0.1)
156155
mutex_m (0.2.0)
@@ -242,7 +241,7 @@ GEM
242241
rematch (3.1.0)
243242
rerun (0.14.0)
244243
listen (~> 3.0)
245-
rouge (4.4.0)
244+
rouge (4.5.0)
246245
rubocop (1.68.0)
247246
json (~> 2.3)
248247
language_server-protocol (>= 3.17.0)
@@ -282,12 +281,6 @@ GEM
282281
rack-protection (= 4.0.0)
283282
rack-session (>= 2.0.0, < 3)
284283
tilt (~> 2.0)
285-
sinatra-contrib (4.0.0)
286-
multi_json (>= 0.0.2)
287-
mustermann (~> 3.0)
288-
rack-protection (= 4.0.0)
289-
sinatra (= 4.0.0)
290-
tilt (~> 2.0)
291284
sqlite3 (2.2.0-aarch64-linux-gnu)
292285
sqlite3 (2.2.0-aarch64-linux-musl)
293286
sqlite3 (2.2.0-arm-linux-gnu)
@@ -353,7 +346,6 @@ DEPENDENCIES
353346
sequel
354347
simplecov
355348
sinatra
356-
sinatra-contrib
357349
sqlite3
358350

359351
BUNDLED WITH

gem/apps/calendar.ru

Lines changed: 98 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
2929
gem 'groupdate'
3030
gem 'puma'
3131
gem 'sinatra'
32-
gem 'sinatra-contrib'
3332
gem 'sqlite3'
3433
end
3534

@@ -42,12 +41,6 @@ Pagy::DEFAULT.freeze
4241
require 'sinatra/base'
4342
# Sinatra application
4443
class PagyCalendar < Sinatra::Base
45-
configure do
46-
# Templates defined in the __END__ section as @@ ...
47-
enable :inline_templates
48-
end
49-
50-
# Controller
5144
include Pagy::Backend
5245

5346
# This method must be implemented by the application.
@@ -76,6 +69,7 @@ class PagyCalendar < Sinatra::Base
7669
unless params[:skip_counts] == 'true'
7770
end
7871

72+
# Root route/action
7973
get '/' do
8074
# Groupdate does not support time zones with SQLite.
8175
# 'UTC' does not work on certain machines config (pulling the actual local time zone utc_offset)
@@ -98,6 +92,103 @@ class PagyCalendar < Sinatra::Base
9892
helpers do
9993
include Pagy::Frontend
10094
end
95+
96+
# Views
97+
template :layout do
98+
<<~ERB
99+
<!DOCTYPE html>
100+
<html lang="en">
101+
<html>
102+
<head>
103+
<title>Pagy Calendar App</title>
104+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
105+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
106+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
107+
108+
<style type="text/css">
109+
@media screen { html, body {
110+
font-size: .8rem;
111+
line-height: 1.1s;
112+
padding: 0;
113+
margin: 0;
114+
} }
115+
body {
116+
background-color: #f7f7f7;
117+
color: #51585F;"
118+
font-family: sans-serif;
119+
}
120+
.content {
121+
padding: 1rem 1.5rem 2rem;
122+
}
123+
/* added with the pagy counts feature */
124+
a.empty-page {
125+
color: #888888;
126+
}
127+
</style>
128+
</head>
129+
130+
<body>
131+
<%= yield %>
132+
</body>
133+
</html>
134+
ERB
135+
end
136+
template :main do
137+
<<~ERB
138+
<div class="container">
139+
<h1>Pagy Calendar App</h1>
140+
<p>Self-contained, standalone app implementing nested calendar pagination for year, month, day units.</p>
141+
<p>See the <a href="https://ddnexus.github.io/pagy/docs/extras/calendar">Pagy Calendar Extra</a> for details.</p>
142+
<p>Please, report the following versions in any new issue.</p>
143+
<h2>Versions</h2>
144+
<ul>
145+
<li>Ruby: <%= RUBY_VERSION %></li>
146+
<li>Rack: <%= Rack::RELEASE %></li>
147+
<li>Sinatra: <%= Sinatra::VERSION %></li>
148+
<li>Pagy: <%= Pagy::VERSION %></li>
149+
</ul>
150+
<hr>
151+
152+
<!-- calendar UI manual toggle -->
153+
<p>
154+
<% if params[:skip] %>
155+
<a id="toggle" href="/" >Show Calendar</a>
156+
<% else %>
157+
<a id="toggle" href="?skip=true" >Hide Calendar</a>
158+
<br>
159+
<a id="go-to-day" href="<%= pagy_calendar_url_at(@calendar, Time.zone.parse('2022-03-02')) %>">Go to the 2022-03-02 Page</a>
160+
<!-- You can use Time.zone.now to find the current page if your time period include today -->
161+
<% end %>
162+
</p>
163+
164+
<!-- calendar filtering navs -->
165+
<% if @calendar %>
166+
<p>Showtime: <%= @calendar.showtime %></p>
167+
<%= pagy_bootstrap_nav(@calendar[:year], id: "year-nav", aria_label: "Years") %> <!-- year nav -->
168+
<%= pagy_bootstrap_nav(@calendar[:month], id: "month-nav", aria_label: "Months") %> <!-- month nav -->
169+
<%= pagy_bootstrap_nav(@calendar[:day], id: "day-nav", aria_label: "Days") %> <!-- day nav -->
170+
<% end %>
171+
172+
<!-- page info extended for the calendar unit -->
173+
<div class="alert alert-primary" role="alert">
174+
<%= pagy_info(@pagy, id: 'pagy-info') %>
175+
<% if @calendar %>
176+
for <b><%= @calendar.showtime.strftime('%Y-%m-%d') %></b>
177+
<% end %>
178+
</div>
179+
180+
<!-- page records (time converted in your local time)-->
181+
<div id="records" class="list-group">
182+
<% @events.each do |event| %>
183+
<p class="list-group-item"><%= event.title %> - <%= event.time.to_s %></p>
184+
<% end %>
185+
</div>
186+
187+
<!-- standard pagination of the selected month -->
188+
<p><%= pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
189+
</div>
190+
ERB
191+
end
101192
end
102193

103194
# ActiveRecord setup
@@ -644,96 +735,3 @@ end
644735
Event.insert_all(events)
645736

646737
run PagyCalendar
647-
648-
__END__
649-
650-
@@ layout
651-
<!DOCTYPE html>
652-
<html lang="en">
653-
<html>
654-
<head>
655-
<title>Pagy Calendar App</title>
656-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
657-
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
658-
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
659-
660-
<style type="text/css">
661-
@media screen { html, body {
662-
font-size: .8rem;
663-
line-height: 1.1s;
664-
padding: 0;
665-
margin: 0;
666-
} }
667-
body {
668-
background-color: #f7f7f7;
669-
color: #51585F;"
670-
font-family: sans-serif;
671-
}
672-
.content {
673-
padding: 1rem 1.5rem 2rem;
674-
}
675-
/* added with the pagy counts feature */
676-
a.empty-page {
677-
color: #888888;
678-
}
679-
</style>
680-
</head>
681-
682-
<body>
683-
<%= yield %>
684-
</body>
685-
</html>
686-
687-
@@ main
688-
<div class="container">
689-
<h1>Pagy Calendar App</h1>
690-
<p>Self-contained, standalone app implementing nested calendar pagination for year, month, day units.</p>
691-
<p>See the <a href="https://ddnexus.github.io/pagy/docs/extras/calendar">Pagy Calendar Extra</a> for details.</p>
692-
<p>Please, report the following versions in any new issue.</p>
693-
<h2>Versions</h2>
694-
<ul>
695-
<li>Ruby: <%= RUBY_VERSION %></li>
696-
<li>Rack: <%= Rack::RELEASE %></li>
697-
<li>Sinatra: <%= Sinatra::VERSION %></li>
698-
<li>Pagy: <%= Pagy::VERSION %></li>
699-
</ul>
700-
<hr>
701-
702-
<!-- calendar UI manual toggle -->
703-
<p>
704-
<% if params[:skip] %>
705-
<a id="toggle" href="/" >Show Calendar</a>
706-
<% else %>
707-
<a id="toggle" href="?skip=true" >Hide Calendar</a>
708-
<br>
709-
<a id="go-to-day" href="<%= pagy_calendar_url_at(@calendar, Time.zone.parse('2022-03-02')) %>">Go to the 2022-03-02 Page</a>
710-
<!-- You can use Time.zone.now to find the current page if your time period include today -->
711-
<% end %>
712-
</p>
713-
714-
<!-- calendar filtering navs -->
715-
<% if @calendar %>
716-
<p>Showtime: <%= @calendar.showtime %></p>
717-
<%= pagy_bootstrap_nav(@calendar[:year], id: "year-nav", aria_label: "Years") %> <!-- year nav -->
718-
<%= pagy_bootstrap_nav(@calendar[:month], id: "month-nav", aria_label: "Months") %> <!-- month nav -->
719-
<%= pagy_bootstrap_nav(@calendar[:day], id: "day-nav", aria_label: "Days") %> <!-- day nav -->
720-
<% end %>
721-
722-
<!-- page info extended for the calendar unit -->
723-
<div class="alert alert-primary" role="alert">
724-
<%= pagy_info(@pagy, id: 'pagy-info') %>
725-
<% if @calendar %>
726-
for <b><%= @calendar.showtime.strftime('%Y-%m-%d') %></b>
727-
<% end %>
728-
</div>
729-
730-
<!-- page records (time converted in your local time)-->
731-
<div id="records" class="list-group">
732-
<% @events.each do |event| %>
733-
<p class="list-group-item"><%= event.title %> - <%= event.time.to_s %></p>
734-
<% end %>
735-
</div>
736-
737-
<!-- standard pagination of the selected month -->
738-
<p><%= pagy_bootstrap_nav(@pagy, id: 'pages-nav', aria_label: 'Pages') if @pagy.pages > 1 %><p/>
739-
</div>

0 commit comments

Comments
 (0)