4 enable :inline_templates
6 def uploaded_file(file)
7 "#{options.root}/files/#{file}"
11 content_type 'text/css', :charset => 'utf-8'
19 get '/ready/:name' do |name|
20 path = uploaded_file(name)
21 unless File.exists? path then
24 base = request.url.gsub(/\/ready\/[^\/]*$/, '')
25 @url = "#{base}/#{name}"
29 get '/:name' do |name|
30 path = uploaded_file(name)
31 unless File.exists? path then
39 tmpfile = params[:file][:tempfile]
40 name = params[:file][:filename]
42 if tmpfile.nil? || name.nil? then
43 @error = "No file selected"
46 FileUtils::cp(tmpfile.path, uploaded_file(name))
47 redirect "ready/#{name}"
52 url = request.scheme + "://"
54 if request.scheme == "https" && request.port != 443 ||
55 request.scheme == "http" && request.port != 80
56 url << ":#{request.port}"
58 url << request.script_name
69 %base{ :href => base_href }
70 %link{ :rel => 'stylesheet', :href => "style.css", :type => 'text/css',
71 :media => "screen, projection" }
80 %form#upload{ :enctype => 'multipart/form-data',
81 :action => 'upload', :method => 'post' }
83 %input{ :type => 'file', :name => 'file' }
85 %input{ :type => 'submit', :value => 'Send file' }
90 %a{ :href => @url }= @url
96 background-color: $green
101 text-decoration: underline
105 background-color: red
107 border: black solid 1px