Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix atom feed.

This should be done with an actual RSS/ATOM generator, but I'm not overly concerned right now. If anyone fancies doing it right, be my guest.

Resolves #56.
  • Loading branch information...
commit cdeda7173f34d00e0ce3f44d09f23647cc25cf7f 1 parent 35d4985
@cwninja cwninja authored
View
1  lib/geminabox.rb
@@ -6,6 +6,7 @@
require 'rubygems/indexer'
require 'hostess'
require 'geminabox/version'
+require 'rss/atom'
class Geminabox < Sinatra::Base
enable :static, :methodoverride
View
4 lib/geminabox/gem_version_collection.rb
@@ -3,6 +3,10 @@
class Geminabox::GemVersionCollection
include Enumerable
+ def size
+ @gems.size
+ end
+
attr_reader :gems
def initialize(initial_gems=[])
View
32 test/requests/atom_feed_test.rb
@@ -0,0 +1,32 @@
+require 'test_helper'
+require 'minitest/unit'
+require 'rack/test'
+
+class AtomFeedTest < MiniTest::Unit::TestCase
+ include Rack::Test::Methods
+
+ def setup
+ clean_data_dir
+ end
+
+ def app
+ Geminabox
+ end
+
+ test "atom feed returns when no gems are defined" do
+ get "/atom.xml"
+ assert last_response.ok?
+ refute_match %r{<entry>}, last_response.body
+ end
+
+ test "atom feed with a single gem" do
+ inject_gems do |builder|
+ builder.gem "foo"
+ end
+
+ get "/atom.xml"
+ assert last_response.ok?
+ feed_content = RSS::Parser.parse(last_response.body)
+ feed_content.items.size == 1
+ end
+end
View
20 views/atom.erb
@@ -4,13 +4,25 @@
<title>Gem in a Box</title>
<link href="<%= url '/atom.xml' %>" rel="self" />
<link href="<%= url '/' %>" />
-
- <% @gems.each do |name, versions| %>
+ <id><%= url '/atom.xml' %></id>
+ <% @gems.by_name do |name, versions| %>
+ <% spec = spec_for(name, versions.newest.number) %>
<entry>
- <title><%= name %> (<%= versions.size == 1 ? versions.first : "#{versions.first} - #{versions.last}" %>)</title>
+ <id><%= name %></id>
+ <updated><%= spec.date.w3cdtf %></updated>
+ <title><%= name %> (<%= versions.size == 1 ? versions.oldest.number : "#{versions.oldest.number} - #{versions.newest.number}" %>)</title>
+ <author><name><%= spec.authors.join(", ") %></name></author>
<% versions.each do |version| %>
- <link href="<%= url "/gems/#{name}-#{version}.gem" %>" />
+ <link href="<%= url "/gems/#{name}-#{version.number}.gem" %>" />
<% end %>
</entry>
<% end %>
+
+ <updated>
+ <% if newest_gem = @gems.newest %>
+ <%= spec_for(newest_gem.name, newest_gem.number).date.w3cdtf %>
+ <% else %>
+ <%= Date.today %>
+ <% end %>
+ </updated>
</feed>

0 comments on commit cdeda71

Please sign in to comment.
Something went wrong with that request. Please try again.