Added /opml action.
Dan Brook [Wed, 25 Nov 2009 09:10:59 +0000 (09:10 +0000)]
Makefile.PL
lib/Gitalist/Controller/Root.pm
t/03legacy_uri.t

index 9b8074e..fa87147 100644 (file)
@@ -58,6 +58,7 @@ requires 'Syntax::Highlight::Engine::Kate';
 requires 'Sys::Hostname';
 requires 'XML::Atom';
 requires 'XML::RSS';
+requires 'XML::OPML::SimpleGen';
 
 author_requires 'Test::NoTabs';
 author_requires 'Test::Pod' => '1.14';
index cd09a42..e8533d0 100644 (file)
@@ -10,6 +10,7 @@ use Sys::Hostname ();
 use XML::Atom::Feed;
 use XML::Atom::Entry;
 use XML::RSS;
+use XML::OPML::SimpleGen;
 
 =head1 NAME
 
@@ -536,6 +537,29 @@ sub rss : Local {
   $c->response->status(200);
 }
 
+sub opml : Local {
+  my($self, $c) = @_;
+
+  my $opml = XML::OPML::SimpleGen->new();
+
+  $opml->head(title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name});
+
+  my @list = @{ $c->model()->projects };
+  die 'No projects found in '. $c->model->repo_dir
+    unless @list;
+
+  for my $proj ( @list ) {
+    $opml->insert_outline(
+      text   => $proj->name. ' - '. $proj->description,
+      xmlUrl => $c->uri_for(rss => {p => $proj->name}),
+    );
+  }
+
+  $c->response->body($opml->as_string);
+  $c->response->content_type('application/rss');
+  $c->response->status(200);
+}
+
 =head2 patch
 
 A raw patch for a given commit.
@@ -626,11 +650,6 @@ sub auto : Private {
   );
 }
 
-sub opml : Local {
-    # FIXME - implement snapshot
-    Carp::croak "Not implemented.";
-}
-
 =head2 end
 
 Attempt to render a view, if needed.
index b638fde..6ff8e99 100644 (file)
@@ -232,10 +232,7 @@ test('/', 'a=rss;opt=--no-merges');
 
 test('/', 'a=project_index');
 
-TODO: {
-  local $TODO = 'The opml action is yet to be implemented';
-  test('/', 'a=opml');
-}
+test('/', 'a=opml');
 
 test('/', 'a=blame;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
 test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');