Skip to content

Instantly share code, notes, and snippets.

@locks
Created June 25, 2009 01:12
Show Gist options
  • Save locks/135628 to your computer and use it in GitHub Desktop.
Save locks/135628 to your computer and use it in GitHub Desktop.
Simple webserver
require 'rubygems'
require 'sinatra'
require 'haml'
require 'sass'
set :port, 8080
#set :views, File.expand_path(File.dirname(__FILE__) + '/')
set :public, File.dirname(__FILE__)
get '/' do
@files = Dir['*'].reject! { |file| File.directory?(file) }
haml :index
end
get '/site' do
redirect '/site/index.html'
end
get '/stylesheet.css' do
header 'Content-Type' => 'text/css; charset=utf-8'
sass :styles
end
post '/upload' do
filename = params[:file][:filename]
file = params[:file][:tempfile]
File.open("#{filename}", 'w') {|f| f.write file.read }
redirect '/'
end
__END__
@@index
!!! 1.1
%html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", 'xml:lang' => "en" }
%head
%title Locks' File Server
%link{:rel => 'stylesheet', :href => '/stylesheet.css', :type => 'text/css' }
%body
%h1 Welcome, <span style="color: red">TO THE WORLD OF TOMORROW~~</span>
%form{:method=>'post', :action=>'/upload', :enctype=>'multipart/form-data'}
Upload your file
%input{:type => 'file', :name => 'file'}
%input{:type => 'submit', :value => 'submit'}
#listing
- @files.each do |file|
%a{ :href => file }
= file
%br
@@styles
body
:margin 0px
:padding 0px
:width auto
:background-color yellow
:text-align center
h1
:padding 20px
:background-color black
:color white
a:link
:color white
a:visited
:color grey
a:hover
:color red
form
:background-color black
:color white
:padding 20px 0px
:margin 20px 0px
#listing
:padding 20px
:background-color black
:font white
:text-align center
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment