Move OPML code out of the root controller
Tomas Doran [Mon, 18 Jan 2010 20:22:34 +0000 (20:22 +0000)]
lib/Gitalist/Controller/OPML.pm [new file with mode: 0644]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/URIStructure/Repository.pm
root/_header_feeds.tt2

diff --git a/lib/Gitalist/Controller/OPML.pm b/lib/Gitalist/Controller/OPML.pm
new file mode 100644 (file)
index 0000000..62dcc81
--- /dev/null
@@ -0,0 +1,31 @@
+package Gitalist::Controller::OPML;
+
+use Moose;
+use Moose::Autobox;
+
+use Sys::Hostname qw/hostname/;
+use XML::OPML::SimpleGen;
+
+use namespace::autoclean;
+
+BEGIN { extends 'Gitalist::Controller' }
+
+sub opml : Chained('base') Args(0) {
+    my ($self, $c) = @_;
+
+    my $opml = XML::OPML::SimpleGen->new();
+
+    $opml->head(title => lc(hostname()) . ' - ' . blessed($c)->config->{name});
+
+    for my $repos ( $c->model()->repositories->flatten ) {
+        $opml->insert_outline(
+            text   => $repos->name. ' - '. $repos->description,
+            xmlUrl => $c->uri_for_action('/repository/rss', [$repos->name]),
+        );
+    }
+
+    $c->response->body($opml->as_string);
+    $c->response->content_type('application/rss');
+}
+
+__PACKAGE__->meta->make_immutable;
index 25e5667..d4190c0 100644 (file)
@@ -2,8 +2,6 @@ package Gitalist::Controller::Root;
 
 use Moose;
 use Moose::Autobox;
-use Sys::Hostname qw/hostname/;
-use XML::OPML::SimpleGen;
 
 use Gitalist::Utils qw/ age_string /;
 
@@ -11,49 +9,13 @@ use namespace::autoclean;
 
 BEGIN { extends 'Gitalist::Controller' }
 
-__PACKAGE__->config->{namespace} = '';
+__PACKAGE__->config(namespace => '');
 
 sub root : Chained('/') PathPart('') CaptureArgs(0) {}
 
 sub index : Chained('base') PathPart('') Args(0) {
-  my ( $self, $c ) = @_;
-
-  my $search = $c->req->param('s') || '';
-
-  $c->stash(
-    search_text => $search,
-  );
-}
-
-=head2 search_help
-
-Provides some help for the search form.
-
-=cut
-
-sub search_help : Chained('base') Args(0) {}
-
-sub opml : Chained('base') Args(0) {
-  my($self, $c) = @_;
-
-  my $opml = XML::OPML::SimpleGen->new();
-
-  $opml->head(title => lc(hostname()) . ' - ' . Gitalist->config->{name});
-
-  my @list = @{ $c->model()->repositories };
-  die 'No repositories 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);
+    my ( $self, $c ) = @_;
+    $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
 }
 
 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
@@ -65,7 +27,6 @@ sub base : Chained('/root') PathPart('') CaptureArgs(0) {
     git_version => $git_version,
     version     => $Gitalist::VERSION,
 
-    # XXX Move these to a plugin!
     time_since => sub {
       return 'never' unless $_[0];
       return age_string(time - $_[0]->epoch);
@@ -82,13 +43,15 @@ sub base : Chained('/root') PathPart('') CaptureArgs(0) {
   );
 }
 
-sub end : ActionClass('RenderView') {
-    my ($self, $c) = @_;
-    # Give repository views the current HEAD.
-    if ($c->stash->{Repository}) {
-        $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
-    }
-}
+=head2 search_help
+
+Provides some help for the search form.
+
+=cut
+
+sub search_help : Chained('base') Args(0) {}
+
+sub end : ActionClass('RenderView') {}
 
 sub error_404 : Action {
     my ($self, $c) = @_;
@@ -126,16 +89,8 @@ Provides the repository listing.
 
 Attempt to render a view, if needed.
 
-=head2 blame
-
 =head2 error_404
 
-=head2 history
-
-=head2 opml
-
-=head2 repository_index
-
 =head1 AUTHORS
 
 See L<Gitalist> for authors.
index 8673560..9d7a0e3 100644 (file)
@@ -11,11 +11,15 @@ after 'base' => sub {
 };
 
 sub find : Chained('base') PathPart('') CaptureArgs(1) {
-    my ($self, $c, $repository) = @_;
+    my ($self, $c, $repos_name) = @_;
     # XXX FIXME - This should be in the repository fragment controller, and the repository
     #             controller should just check has_repository
     try {
-        $c->stash(Repository => $c->model()->get_repository($repository));
+        my $repos = $c->model()->get_repository($repos_name);
+        $c->stash(
+            Repository => $repos,
+            HEAD => $repos->head_hash,
+        );
     }
     catch {
         $c->detach('/error_404');
index e0b83ec..1fbcfaa 100644 (file)
@@ -3,13 +3,13 @@
   <link
     rel="alternate"
     title="[% Repository.name %] - [% title %] Atom feed"
-    href="[% c.uri_for('atom') %]"
+    href="[% c.uri_for_action('/repository/atom', [Repository.name]) %]"
     type="application/atom+xml"
   >
   <link
     rel="alternate"
     title="[% Repository.name %] - [% title %] RSS feed"
-    href="[% c.uri_for('rss') %]"
+    href="[% c.uri_for_action('/repository/rss', [Repository.name]) %]"
     type="application/rss+xml"
   >
   [% ELSE %]
@@ -22,7 +22,7 @@
   <link
     rel="alternate"
     title="[% c.config.sitename %] Git repositories feeds"
-    href="[% c.uri_for('opml') %]"
+    href="[% c.uri_for_action('/opml/opml') %]"
     type="text/x-opml"
   >
   [% END %]