Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Clean up and simplify the gem index #75

Merged
merged 2 commits into from

2 participants

Joshua Ballanco Tom Lea
Joshua Ballanco

These two commits resolve an issue with the leading content
and introduce the concept of limiting the full gem listing
on the index page.

jballanc added some commits
Joshua Ballanco jballanc Move header content out of layout
The content about adding gem sources doesn't make much sense
on the upload page, especially considering that it gives an
incorrect gem source URL.
da55251
Joshua Ballanco jballanc Limit gem index listing to most recent 5 versions
Listing every version of a gem can get cumbersome if you
have very many gem versions. This commit introduces a
page for specific gems and limits the full index listing
to the most recent 5 versions.
30fb4d0
Tom Lea cwninja merged commit 80f9fd9 into from
Tom Lea
Owner

This is lovely.

Merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2012
  1. Joshua Ballanco

    Move header content out of layout

    jballanc authored
    The content about adding gem sources doesn't make much sense
    on the upload page, especially considering that it gives an
    incorrect gem source URL.
  2. Joshua Ballanco

    Limit gem index listing to most recent 5 versions

    jballanc authored
    Listing every version of a gem can get cumbersome if you
    have very many gem versions. This commit introduces a
    page for specific gems and limits the full index listing
    to the most recent 5 versions.
This page is out of date. Refresh to see the latest.
7 lib/geminabox.rb
View
@@ -75,6 +75,13 @@ def fixup_bundler_rubygems!
redirect url("/")
end
+ get '/gems/:gemname' do
+ gems = Hash[load_gems.by_name]
+ @gem = gems[params[:gemname]]
+ halt 404 unless @gem
+ erb :gem
+ end
+
delete '/gems/*.gem' do
File.delete file_path if File.exists? file_path
reindex(:force_rebuild)
8 public/master.css
View
@@ -24,6 +24,12 @@ a:hover {
color: #00f;
}
+a#more_link {
+ font-size: 0.7em;
+ line-height: 1.2;
+ vertical-align: bottom;
+}
+
form {
margin: 0;
}
@@ -146,4 +152,4 @@ ul.gemlist li:hover a.download {
.gem-version small.platform {
padding: 0 0 0 15px;
-}
+}
37 views/gem.erb
View
@@ -0,0 +1,37 @@
+<p>
+<a href="/">Back to Gem Index</a>
+</p>
+
+<ul class="gemlist">
+ <% @gem.by_name do |name, versions| %>
+ <li class="gem-version">
+ <h2><%= name %> (<%= versions.count == 1 ? versions.first.number : "#{versions.oldest.number} - #{versions.newest.number}" %>)</h2>
+ <% versions.each.reverse_each do |version| %>
+ <p>
+ <code>gem install <%= version.name %> <%= "--prerelease" if version.number.to_s.match(/[a-z]/i) %> -v "<%= version.number %>"</code>
+ <% unless version.platform =~ /^ruby/i %>
+ <small class="platform"><%= version.platform %></small>
+ <% end %>
+ </p>
+ <form class="delete-form" method="post" action="<%= url("/gems/#{version.gemfile_name}.gem") %>">
+ <a class="download" href="<%= url("/gems/#{version.gemfile_name}.gem") %>">download</a>
+ <input type="hidden" name="_method" value="DELETE" />
+ <button type="submit">delete</button>
+ </form>
+ <% end %>
+
+ <div class="details">
+ <p>
+ <% if spec = spec_for(name, versions.newest.number) %>
+ <%= spec.description %>
+ <br/>
+ <span class="author">– <%= spec.authors.map do |author|
+ "<a href='#{spec.homepage}'>#{author}</a>"
+ end.join(', ') %></span>
+ <% end %>
+ </p>
+ </div>
+
+ </li>
+ <% end %>
+</ul>
15 views/index.erb
View
@@ -1,3 +1,12 @@
+<p>
+<small>If you did not need any credentials to get to this page</small>
+ <pre><code>gem sources -a <%= url "/" %></code></pre>
+<small>If you needed some credentials to get to this page</small>
+ <pre><code>gem sources -a <%= url.to_s.gsub('://','://username:password@') %></code></pre>
+<small>and then ...</small>
+ <pre><code>gem install geminabox<br />gem inabox [gemfile]</code></pre>
+</p>
+
<% if @gems.any? %>
<a href="<%= url("/upload") %>">Upload Another Gem</a>
@@ -8,7 +17,7 @@
<% @gems.by_name do |name, versions| %>
<li <%= %{id="jump_#{name[0..0].downcase}"} if @index_gems.delete(name[0..0].downcase) %> class="gem-version">
<h2><%= name %> (<%= versions.count == 1 ? versions.first.number : "#{versions.oldest.number} - #{versions.newest.number}" %>)</h2>
- <% versions.each do |version| %>
+ <% versions.each.reverse_each.first(5).each do |version| %>
<p>
<code>gem install <%= version.name %> <%= "--prerelease" if version.number.to_s.match(/[a-z]/i) %> -v "<%= version.number %>"</code>
<% unless version.platform =~ /^ruby/i %>
@@ -22,6 +31,10 @@
</form>
<% end %>
+ <% if versions.count > 5 %>
+ <a href="<%= url("/gems/#{name}") %>" id="more_link">Older versions...</a>
+ <% end %>
+
<div class="details">
<p>
<% if spec = spec_for(name, versions.newest.number) %>
8 views/layout.erb
View
@@ -8,14 +8,6 @@
<body>
<div id="content">
<h1>Gem in a Box</h1>
- <p>
- <small>If you did not need any credentials to get to this page</small>
- <pre><code>gem sources -a <%= url "/" %></code></pre>
- <small>If you needed some credentials to get to this page</small>
- <pre><code>gem sources -a <%= url.to_s.gsub('://','://username:password@') %></code></pre>
- <small>and then ...</small>
- <pre><code>gem install geminabox<br />gem inabox [gemfile]</code></pre>
- </p>
<%= yield %>
</div>
<script type="text/javascript" src="<%= url "/jquery.js" %>"></script>
3  views/upload.erb
View
@@ -1,3 +1,6 @@
+<p>
+<small>Choose a gem file to upload ...</small>
+</p>
<%= @error %>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file">
Something went wrong with that request. Please try again.