Merge remote branch 't0m/json' into json
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index 963a286..a46fff0 100644 (file)
@@ -18,6 +18,14 @@ sub index : Chained('base') PathPart('') Args(0) {
     $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
 }
 
+# XXX Fragile much?
+sub css : Chained('/root') PathPart('core.css') Args(0) {
+    my ( $self, $c ) = @_;
+
+    $c->response->content_type('text/css');
+    $c->stash(template => 'static/css/core.css');
+}
+
 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
   my($self, $c) = @_;
 
@@ -27,6 +35,7 @@ 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);
@@ -50,17 +59,16 @@ sub base : Chained('/root') PathPart('') CaptureArgs(0) {
   );
 }
 
-sub search : Chained('base') Args(0) {}
-
-=head2 search_help
-
-Provides some help for the search form.
-
-=cut
-
-sub search_help : Chained('base') Args(0) {}
-
-sub end : ActionClass('RenderView') {}
+sub end : ActionClass('Serialize') {
+    my ($self, $c) = @_;
+    # Give repository views the current HEAD.
+    if ($c->stash->{Repository}) {
+        $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
+    }
+    if ($c->stash->{data} && blessed $c->stash->{data}) {
+        $c->stash->{rest} = $c->stash->{data}->pack;
+    }
+}
 
 sub error_404 : Action {
     my ($self, $c) = @_;
@@ -68,6 +76,14 @@ sub error_404 : Action {
     $c->response->body('Page not found');
 }
 
+__PACKAGE__->config(
+    default => 'text/html',
+    map => {
+        'text/html'        => [qw/ View Default /],
+        'application/json' => [qw/ JSON /],
+    }
+);
+
 __PACKAGE__->meta->make_immutable;
 
 __END__