Blame view

vendor/bower-asset/yii2-pjax/test/app.rb 1.42 KB
2e86c939   xu   “首次提交”
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
require 'sinatra'
require 'json'

set :public_folder, File.dirname(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 '/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
  if params[:anchor]
    path = "/hello.html##{params[:anchor]}"
    if pjax?
      response.headers['X-PJAX-URL'] = uri(path)
      status 200
    else
      redirect path
    end
  else
    redirect "/hello.html"
  end
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 '/boom_sans_pjax.html' do
  status 500
  erb :boom_sans_pjax, :layout => false
end

get '/:page.html' do
  erb :"#{params[:page]}", :layout => !pjax?
end

get '/some-&-path/hello.html' do
  erb :hello, :layout => !pjax?
end