Merge remote branch 'seveas/seveas/tree_speedup'
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
index 14ef8ee..42896ea 100644 (file)
@@ -3,7 +3,7 @@ package Gitalist::Controller::Root;
 use Moose;
 use Moose::Autobox;
 use Digest::MD5 qw(md5_hex);
-use Gitalist::Utils qw/ age_string /;
+use Gitalist::Utils qw/ age_string mode_string /;
 
 use namespace::autoclean;
 
@@ -22,8 +22,7 @@ sub index : Chained('base') PathPart('') Args(0) {
 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');
+    $c->stash( template => 'static/css/core.css', content_type => 'text/css' );
 }
 
 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
@@ -48,13 +47,16 @@ sub base : Chained('/root') PathPart('') CaptureArgs(0) {
     abridged_description => sub {
         join(' ', grep { defined } (split / /, shift)[0..10]);
     },
-    uri_for_gravatar => sub { # FIXME - Cache these?
+    uri_for_gravatar => sub {
         my $email = shift;
         my $size = shift;
         my $uri = 'http://www.gravatar.com/avatar/' . md5_hex($email);
         $uri .= "?s=$size" if $size;
         return $uri;
     },
+    mode_string => sub {
+        return mode_string(oct shift);
+    }
   );
 }
 
@@ -68,7 +70,16 @@ Provides some help for the search form.
 
 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) = @_;
@@ -76,6 +87,17 @@ sub error_404 : Action {
     $c->response->body('Page not found');
 }
 
+__PACKAGE__->config(
+    default => 'text/html',
+    map => {
+        'application/json' => [qw/ JSON /],
+        map { $_ => [qw/ View Default /] }
+             qw( text/css text/html text/plain
+                 application/atom+xml application/rss+xml application/rss )
+    },
+    content_type_stash_key => 'content_type',
+);
+
 __PACKAGE__->meta->make_immutable;
 
 __END__