Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

It seems to work!

  • Loading branch information...
commit 601acdc83e4149949dc85bc594854059e8d0b6e9 1 parent a03fd9d
@cwninja cwninja authored
View
0  public/gems/.gitignore → data/.gitignore
File renamed without changes
View
34 lib/gembox.rb
@@ -1,14 +1,24 @@
require 'sinatra/base'
require 'rubygems'
+require "rubygems/indexer"
+require 'hostess'
class Gembox < Sinatra::Base
set :sessions, true
set :public, File.join(File.dirname(__FILE__), *%w[.. public])
+ set :data, File.join(File.dirname(__FILE__), *%w[.. data])
+ use Hostess, self.data
+
enable :static
get '/' do
- @gems = Marshal.load(Gem.gunzip(Gem.read_binary( File.join(options.public, "specs.#{Gem.marshal_version}.gz")) ))
+ begin
+ @gems = Marshal.load(Gem.gunzip(Gem.read_binary( File.join(options.data, "specs.#{Gem.marshal_version}.gz")) ))
+ rescue
+ @gems = []
+ end
+
erb :index
end
@@ -22,17 +32,33 @@ class Gembox < Sinatra::Base
return erb(:upload)
end
- File.open(File.join(options.public, "gems", File.basename(name)), "w") do |f|
+ Dir.mkdir(File.join(options.data, "gems")) unless File.directory? File.join(options.data, "gems")
+
+ File.open(File.join(options.data, "gems", File.basename(name)), "w") do |f|
while blk = tmpfile.read(65536)
f << blk
end
end
-
+ reindex
redirect "/"
end
private
def reindex
- Gem::Indexer.new(options.public).generate_index
+ Gem::Indexer.new(options.data).generate_index
+ end
+
+ helpers do
+ def url_for(path)
+ url = request.scheme + "://"
+ url << request.host
+
+ if request.scheme == "https" && request.port != 443 ||
+ request.scheme == "http" && request.port != 80
+ url << ":#{request.port}"
+ end
+
+ url << path
+ end
end
end
View
47 lib/hostess.rb
@@ -0,0 +1,47 @@
+require 'sinatra/base'
+
+class Hostess < Sinatra::Base
+ def initialize(app, path)
+ @path = path
+ super(app)
+ end
+
+ def serve
+ send_file(File.expand_path(File.join(@path, *request.path_info)))
+ end
+
+ %w[/specs.4.8.gz
+ /latest_specs.4.8.gz
+ /prerelease_specs.4.8.gz
+ ].each do |index|
+ get index do
+ content_type('application/x-gzip')
+ serve
+ end
+ end
+
+ %w[/quick/Marshal.4.8/*.gemspec.rz
+ /yaml.Z
+ /Marshal.4.8.Z
+ ].each do |deflated_index|
+ get deflated_index do
+ content_type('application/x-deflate')
+ serve
+ end
+ end
+
+ %w[/yaml
+ /Marshal.4.8
+ /specs.4.8
+ /latest_specs.4.8
+ /prerelease_specs.4.8
+ ].each do |old_index|
+ get old_index do
+ serve
+ end
+ end
+
+ get "/gems/*.gem" do
+ serve
+ end
+end
View
63 public/master.css
@@ -0,0 +1,63 @@
+body {
+ background: #a00;
+ color: #444;
+ font-size: 1.2em;
+ font-family: sans-serif;
+ margin: 0;
+}
+
+a {
+ text-decoration: none;
+ color: #00a;
+}
+
+a:hover {
+ color: #00f;
+}
+
+code {
+ font-size: 0.7em;
+}
+
+#content {
+ background: #fff;
+ width: 600px;
+ position: absolute;
+ left: 50%;
+ margin-left: -300px;
+ margin-top: 2em;
+ padding: 1em;
+ border: 1px solid #000;
+ box-shadow: 0 0 3em #fff;
+ -moz-box-shadow: 0 0 3em #fff;
+ -webkit-box-shadow: 0 0 3em #fff;
+ border-radius: 1em;
+ -moz-border-radius: 1em;
+ -webkit-border-radius: 1em;
+ text-align: center;
+}
+
+#content h1 {
+ margin: 0;
+ color: #a00;
+ text-shadow: #444 1px 1px 3px;
+}
+
+ul.gemlist {
+ list-style: none;
+ margin: 2em 0;
+ padding: 0;
+}
+
+ul.gemlist li {
+ margin: 1em;
+ background: #eee;
+ border: 1px solid #444;
+ padding: .4em;
+ border-radius: .5em; -moz-border-radius: .5em; -webkit-border-radius: .5em;
+}
+
+ul.gemlist li strong {
+ display: block;
+ font-size: 1.2em;
+}
View
9 views/index.erb
@@ -1,7 +1,10 @@
-<ul>
+<ul class="gemlist">
<% @gems.each do |name, version| %>
- <li><a href="/gems/<%= name %>-<%= version %>.gem"><%= name %> (<%= version %>)</a></li>
+ <li>
+ <strong><%= name %> (<%= version %>)</strong>
+ <code>gem install <%= name %> -v "<%= version %>"</code>
+ </li>
<% end %>
</ul>
-<a href="upload">Upload More</a>
+<a href="upload">Upload Another Gem</a>
View
11 views/layout.erb
@@ -1,8 +1,15 @@
<html>
<head>
+ <title>GemBox</title>
+ <link rel="stylesheet" href="/master.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
- <h1>Gembox</h1>
- <%= yield %>
+ <div id="content">
+ <h1>Gembox</h1>
+ <p>
+ <code>gem sources -a <%= url_for "/" %></code>
+ </p>
+ <%= yield %>
+ </div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.