Initial commit of 'coquelicot'
authorLunar <lunar@anargeek.net>
Sat, 26 Jun 2010 16:40:33 +0000 (18:40 +0200)
committerLunar <lunar@anargeek.net>
Sat, 26 Jun 2010 16:40:33 +0000 (18:40 +0200)
Really, really basic and stupid one-click upload application for now.

.gitignore [new file with mode: 0644]
config.ru [new file with mode: 0644]
coquelicot.rb [new file with mode: 0644]
files/.placeholder [new file with mode: 0644]
tmp/.placeholder [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..5119549
--- /dev/null
@@ -0,0 +1,3 @@
+files/
+tmp/restart.txt
+tmp/always_restart.txt
diff --git a/config.ru b/config.ru
new file mode 100644 (file)
index 0000000..10b7abc
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,8 @@
+require 'sinatra'
+
+set :environment, :development
+set :raise_errors, true
+disable :run
+
+require 'coquelicot'
+run Sinatra::Application
diff --git a/coquelicot.rb b/coquelicot.rb
new file mode 100644 (file)
index 0000000..796deb8
--- /dev/null
@@ -0,0 +1,92 @@
+require 'sinatra'
+require 'haml'
+
+enable :inline_templates
+
+def uploaded_file(file)
+  "#{options.root}/files/#{file}"
+end
+
+get '/style.css' do
+  sass :style
+end
+
+get '/' do
+  haml :index
+end
+
+get '/ready/:name' do |name|
+  path = uploaded_file(name)
+  unless File.exists? path then
+    return 404
+  end
+  base = request.url.gsub(/\/ready\/[^\/]*$/, '')
+  @url = "#{base}/#{name}"
+  haml :ready
+end
+
+get '/:name' do |name|
+  path = uploaded_file(name)
+  unless File.exists? path then
+    return 404
+  end
+  send_file path
+end
+
+post '/upload' do
+  if params[:file] then
+    tmpfile = params[:file][:tempfile]
+    name = params[:file][:filename]
+  end
+  if tmpfile.nil? || name.nil? then
+    @error = "No file selected"
+    return haml(:index)
+  end
+  FileUtils::cp(tmpfile.path, uploaded_file(name))
+  redirect "ready/#{name}"
+end
+
+__END__
+
+@@ layout
+%html
+  %head
+    %title coquelicot
+    %link{ :rel => 'stylesheet', :href => "#{request.script_name}/style.css", :type => 'text/css',
+           :media => "screen, projection" }
+  %body
+    #container
+      = yield
+
+@@ index
+%h1 Upload!
+- unless @error.nil?
+  .error= @error
+%form#upload{ :enctype => 'multipart/form-data',
+              :action  => 'upload', :method => 'post' }
+  .field
+    %input{ :type => 'file', :name => 'file' }
+  .field
+    %input{ :type => 'submit', :value => 'Send file' }
+
+@@ ready
+%h1 Pass this on!
+.url
+  %a{ :href => @url }= @url
+
+@@ style
+$green: #00ff26
+
+body
+  background-color: $green
+  font-family: Georgia
+  color: darkgreen
+
+a, a:visited
+  text-decoration: underline
+  color: white
+
+.error
+  background-color: red
+  color: white
+  border: black solid 1px
diff --git a/files/.placeholder b/files/.placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tmp/.placeholder b/tmp/.placeholder
new file mode 100644 (file)
index 0000000..e69de29