Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial implementation.

  • Loading branch information...
commit a03fd9dbb5d1b2ab16da6487b23db89529eb04b4 0 parents
@cwninja cwninja authored
4 config.ru
@@ -0,0 +1,4 @@
+$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
+require "gembox"
+
+run Gembox
38 lib/gembox.rb
@@ -0,0 +1,38 @@
+require 'sinatra/base'
+require 'rubygems'
+
+
+class Gembox < Sinatra::Base
+ set :sessions, true
+ set :public, File.join(File.dirname(__FILE__), *%w[.. public])
+ enable :static
+
+ get '/' do
+ @gems = Marshal.load(Gem.gunzip(Gem.read_binary( File.join(options.public, "specs.#{Gem.marshal_version}.gz")) ))
+ erb :index
+ end
+
+ get '/upload' do
+ erb :upload
+ end
+
+ post '/upload' do
+ unless params[:file] && (tmpfile = params[:file][:tempfile]) && (name = params[:file][:filename])
+ @error = "No file selected"
+ return erb(:upload)
+ end
+
+ File.open(File.join(options.public, "gems", File.basename(name)), "w") do |f|
+ while blk = tmpfile.read(65536)
+ f << blk
+ end
+ end
+
+ redirect "/"
+ end
+
+private
+ def reindex
+ Gem::Indexer.new(options.public).generate_index
+ end
+end
1  public/gems/.gitignore
@@ -0,0 +1 @@
+[^.]*
7 views/index.erb
@@ -0,0 +1,7 @@
+<ul>
+ <% @gems.each do |name, version| %>
+ <li><a href="/gems/<%= name %>-<%= version %>.gem"><%= name %> (<%= version %>)</a></li>
+ <% end %>
+</ul>
+
+<a href="upload">Upload More</a>
8 views/layout.erb
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ </head>
+ <body>
+ <h1>Gembox</h1>
+ <%= yield %>
+ </body>
+</html>
4 views/upload.erb
@@ -0,0 +1,4 @@
+<form method="POST" enctype="multipart/form-data">
+ <input type="file" name="file">
+ <input type="submit" value="Upload">
+</form>
Please sign in to comment.
Something went wrong with that request. Please try again.