/
isitblankyet.rb
196 lines (182 loc) · 4.92 KB
/
isitblankyet.rb
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#use latest version of sinatra
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/vendor/sinatra/lib')
# isitblankyet.rb
require 'rubygems'
require 'sinatra'
not_found do
headers["Status"] = "301 Moved Permanently"
redirect("/")
end
helpers do
def countdown_name
if params[:name]
@name = params[:name]
else
if params[:hour]
@name = "#{params[:year]}/#{params[:month]}/#{params[:day]} #{params[:hour]}:#{params[:minute]}"
else
@name = "#{params[:year]}/#{params[:month]}/#{params[:day]}"
end
end
end
end
# === routes ===
# index, today
get '/' do
t = Time.now
uri = t.strftime("%Y/%m/%d/today")
redirect(uri)
end
# date
get '/:year/:month/:day' do
countdown_name
haml :index
end
# date,name
get '/:year/:month/:day/:name' do
countdown_name
haml :index
end
# time
get '/:year/:month/:day/:hour::minute' do
countdown_name
haml :index
end
# time,name
get '/:year/:month/:day/:hour::minute/:name' do
countdown_name
haml :index
end
# special dates
get '/timetofork' do
t = Time.now
uri = t.strftime("%Y/%m/%d/time to fork this code")
redirect(uri)
end
get '/valentine' do
uri = "2009/02/14/valentine's%20day"
redirect(uri)
end
get '/timeforlost' do
uri = "2009/1/21/21:00/time%20for%20lost"
redirect(uri)
end
# stylesheets
get '/main.css' do
content_type 'text/css', :charset => 'utf-8'
sass :main
end
# === templates ===
use_in_file_templates!
__END__
@@ layout
!!! XML
!!! Strict
%html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", 'xml:lang' => "en" }
%head
%title= "is it #{@name} yet?"
%meta{'http-equiv'=>"content-type", :content=>"text/html; charset=UTF-8"}/
%link{:href=>"/main.css", :media=>"all", :rel=>"stylesheet", :type=>"text/css"}/
%body
.container
#content
= yield
#footer
%p
%span.copyright
something nifty from <a href="http://www.seaofclouds.com">seaofclouds</a>™ |
%a{:href=>"http://github.com/seaofclouds/is-it-blank-yet"} contribute
@@ index
%h2#status.content-header thinking
.content-body
%h3#notifier
%h4#countdown
%script{:type=>"text/javascript"}
:plain
var countdown_d = new Date();
var countdown_timenow = countdown_d.getTime();
var countdown_targetdate = Date.parse("#{params[:year]}/#{params[:month]}/#{params[:day]} #{params[:hour]}:#{params[:minute]}")
var countdown_timeleft = Math.floor((countdown_targetdate-countdown_timenow)/1000);
function countdown(remain,messages) {
var
status = document.getElementById("status"),
notifier = document.getElementById("notifier"),
countdown = document.getElementById("countdown"),
timer = setInterval( function () {
var day = (Math.floor(remain/86400))%86400;
var hour = (Math.floor(remain/3600))%24;
var minute = (Math.floor(remain/60))%60;
var second = (Math.floor(remain/1))%60;
countdown.innerHTML = (day > 0 ? "<span class='countdown_day'><strong>"+day+"</strong> days</span> " : "") + (hour > 0 ? "<span class='countdown_hour'><strong>"+hour+"</strong> hours</span> " : "") + (minute > 0 ? "<span class='countdown_minute'><strong>"+minute+"</strong> minutes</span> " : "") + (second > 0 ? "<span class='countdown_second'><strong>"+second+"</strong> seconds</span> " : "")
if (--remain < 0 ) {
clearInterval(timer);
document.body.id = "yes";
status.innerHTML = "yes";
notifier.innerHTML = "it is <strong>#{@name}</strong>"
} else {
document.body.id = "no";
status.innerHTML = "no";
notifier.innerHTML = "it is not <strong>#{@name}</strong>, but it will be in"
}
},1000);
}
countdown(countdown_timeleft,
{
86400: "it will be #{@name} tomorrow.",
10: "it will be #{@name} in ten seconds",
0: "it is #{@name}"
}
);
@@ main
!green = #2E7F3A
!red = #7f0100
*
:margin 0
:padding 0
body
:background-color #555
:text-align center
:color #fff
:font-size 80%
:font-family helvetica, arial, sans-serif
a
:color #fff
.container
#content
:padding-top 4em
:padding-bottom 2em
h2
:font-weight normal
:font-size 13em
:font-family georgia, serif
h3
:font-weight normal
:font-size 1.5em
:padding-top .5em
h4
:font-size 1.3em
:font-weight normal
:margin-top 1em
strong
:font-size 1.2em
.content-body
:padding-top 3em
:padding-bottom 8em
a
:color #fff
#no
:background-color = !red
#footer
:color = !red + #777
a
:color = !red + #777
#yes
:background-color = !green
#footer
:color = !green + #777
a
:color = !green + #777
#footer
:font-size .85em
:padding-bottom 1em
:font-family verdana, sans-serif