@@ -29,7 +29,6 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
29
29
gem 'groupdate'
30
30
gem 'puma'
31
31
gem 'sinatra'
32
- gem 'sinatra-contrib'
33
32
gem 'sqlite3'
34
33
end
35
34
@@ -42,12 +41,6 @@ Pagy::DEFAULT.freeze
42
41
require 'sinatra/base'
43
42
# Sinatra application
44
43
class PagyCalendar < Sinatra ::Base
45
- configure do
46
- # Templates defined in the __END__ section as @@ ...
47
- enable :inline_templates
48
- end
49
-
50
- # Controller
51
44
include Pagy ::Backend
52
45
53
46
# This method must be implemented by the application.
@@ -76,6 +69,7 @@ class PagyCalendar < Sinatra::Base
76
69
unless params [ :skip_counts ] == 'true'
77
70
end
78
71
72
+ # Root route/action
79
73
get '/' do
80
74
# Groupdate does not support time zones with SQLite.
81
75
# 'UTC' does not work on certain machines config (pulling the actual local time zone utc_offset)
@@ -98,6 +92,103 @@ class PagyCalendar < Sinatra::Base
98
92
helpers do
99
93
include Pagy ::Frontend
100
94
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
101
192
end
102
193
103
194
# ActiveRecord setup
644
735
Event . insert_all ( events )
645
736
646
737
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