Permalink
Browse files

Add an XML (RSS) representation of /torrents

Fairly straight forward, didn't want to require a module so just a hardcoded
template is good enough.

Also fix the route for '/' to be simpler and fix some whitespace issues.
  • Loading branch information...
1 parent 364434f commit 9ad65977055399c4a7df125748f599bbb3f240cb @afresh1 committed Dec 2, 2012
Showing with 46 additions and 3 deletions.
  1. +46 −3 OpenBSDtracker
View
@@ -19,6 +19,12 @@ app->config(
}
);
+app->defaults(
+ title => 'OpenBSD Torrents',
+ description => 'OpenBSD Torrents from openbsd.somedomain.net',
+ url => '/',
+);
+
helper title_case => sub {
my ($self, $block) = @_;
@@ -72,14 +78,15 @@ plugin 'PODRenderer' if app->mode eq 'development';
#my $torrents = plugin 'JSONConfig' => { file => 'torrents.json' };
-get '/' => sub { shift->render('index') };
-get '/torrents' => sub {
+get '/' => 'index';
+get '/torrents' => sub {
my $self = shift;
$self->respond_to(
json => { json => $self->torrents },
+ xml => { template => 'index' },
html => { template => 'index' },
- )
+ )
};
get '/detail/:hash' => sub {
@@ -215,6 +222,28 @@ $(document).ready(function() {
});
% end
+@@ index.xml.ep
+% my $torrents = torrents();
+% my $pubDate = 0;
+% foreach my $hash (
+% sort { $torrents->{$a}->{'creation date'}
+% <=> $torrents->{$b}->{'creation date'} } keys %{$torrents} )
+% {
+% my $detail = $torrents->{$hash};
+% next unless $detail->{torrent};
+% my $item_pub_date = $detail->{'creation date'};
+% $pubDate = $item_pub_date if $pubDate < $item_pub_date;
+ <item>
+ <title><%= $detail->{info}->{name} %></title>
+ <link><%= url_for( "torrent/$detail->{torrent}" )->to_abs %></link>
+ <description><%= $detail->{comment} %></description>
+ <guid><%= $detail->{torrent} %></guid>
+ <pubDate><%= human_date $item_pub_date %></pubDate>
+ </item>
+% }
+% layout 'default', pubDate => human_number $pubDate;
+
+
@@ detail.html.ep
% title 'OpenBSD Torrent Details';
% my $detail_line = begin
@@ -284,6 +313,20 @@ $(document).ready(function() {
</body>
</html>
+@@ layouts/default.xml.ep
+<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+<channel>
+ <title><%= $title %></title>
+ <description><%= $description %></description>
+ <link><%= url_for( $url )->to_abs %></link>
+ <lastBuildDate><%= human_date time %></lastBuildDate>
+ <pubDate><%= human_date $pubDate %></pubDate>
+ <ttl>1800</ttl>
+%= content
+</channel>
+</rss>
+
@@ inc/style.css.ep
body {
font: 12px tahoma, verdana, arial, sans-serif;

0 comments on commit 9ad6597

Please sign in to comment.