forked from defunkt/jquery-pjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
88 lines (71 loc) · 1.22 KB
/
app.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
require 'sinatra'
require 'json'
set :public_folder, settings.root
enable :static
helpers do
def pjax?
env['HTTP_X_PJAX'] && !params[:layout]
end
def title(str)
if pjax?
"<title>#{str}</title>"
else
@title = str
nil
end
end
end
after do
if pjax?
response.headers['X-PJAX-URL'] = request.url
response.headers['X-PJAX-Version'] = 'v1'
end
end
get '/' do
erb :qunit
end
get '/jquery.pjax.js' do
send_file "#{settings.root}/../jquery.pjax.js"
end
get '/test/:file' do
send_file "#{settings.root}/../test/#{params[:file]}"
end
get '/env.html' do
erb :env, :layout => !pjax?
end
post '/env.html' do
erb :env, :layout => !pjax?
end
put '/env.html' do
erb :env, :layout => !pjax?
end
delete '/env.html' do
erb :env, :layout => !pjax?
end
get '/redirect.html' do
redirect "/hello.html"
end
get '/timeout.html' do
if pjax?
sleep 1
erb :timeout, :layout => false
else
erb :timeout
end
end
post '/timeout.html' do
if pjax?
sleep 1
erb :timeout, :layout => false
else
status 500
erb :boom
end
end
get '/boom.html' do
status 500
erb :boom, :layout => !pjax?
end
get '/:page.html' do
erb :"#{params[:page]}", :layout => !pjax?
end