2009-11-09 23:09:51 +01:00
|
|
|
require 'sinatra/base'
|
|
|
|
require 'rack'
|
2009-12-19 11:52:08 +01:00
|
|
|
require 'yaml'
|
2009-11-09 23:09:51 +01:00
|
|
|
|
2009-11-04 23:32:35 +01:00
|
|
|
class TestApp < Sinatra::Base
|
2009-11-05 17:35:45 +01:00
|
|
|
set :root, File.dirname(__FILE__)
|
|
|
|
set :static, true
|
2009-11-04 23:32:35 +01:00
|
|
|
|
|
|
|
get '/' do
|
|
|
|
'Hello world!'
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/foo' do
|
|
|
|
'Another World'
|
|
|
|
end
|
2009-11-24 21:32:25 +01:00
|
|
|
|
2009-11-12 18:58:27 +01:00
|
|
|
get '/redirect' do
|
|
|
|
redirect '/redirect_again'
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/redirect_again' do
|
|
|
|
redirect '/landed'
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/landed' do
|
|
|
|
"You landed"
|
|
|
|
end
|
2009-11-29 00:32:16 +01:00
|
|
|
|
|
|
|
get '/with-quotes' do
|
|
|
|
%q{"No," he said, "you can't do that."}
|
|
|
|
end
|
|
|
|
|
2009-11-24 21:32:25 +01:00
|
|
|
get '/form/get' do
|
2009-11-14 10:44:46 +01:00
|
|
|
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
2009-11-08 01:13:16 +01:00
|
|
|
end
|
2009-11-17 23:36:27 +01:00
|
|
|
|
2009-11-24 21:32:25 +01:00
|
|
|
get '/favicon.ico' do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/:view' do |view|
|
|
|
|
erb view.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
post '/redirect' do
|
|
|
|
redirect '/redirect_again'
|
|
|
|
end
|
|
|
|
|
|
|
|
post '/form' do
|
2009-11-17 23:36:27 +01:00
|
|
|
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
|
|
|
end
|
2009-11-12 17:07:43 +01:00
|
|
|
|
|
|
|
post '/upload' do
|
2010-01-06 17:30:48 +01:00
|
|
|
begin
|
|
|
|
buffer = []
|
|
|
|
buffer << "Content-type: #{params[:form][:document][:type]}"
|
|
|
|
buffer << "File content: #{params[:form][:document][:tempfile].read}"
|
|
|
|
buffer.join(' | ')
|
|
|
|
rescue
|
|
|
|
'No file uploaded'
|
|
|
|
end
|
2009-11-12 17:07:43 +01:00
|
|
|
end
|
2009-11-08 01:13:16 +01:00
|
|
|
end
|
2009-11-09 23:09:51 +01:00
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
Rack::Handler::Mongrel.run TestApp, :Port => 8070
|
|
|
|
end
|