Add age to commit info.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Fragment / Ref.pm
index 2917616..a2e02e3 100644 (file)
@@ -9,6 +9,7 @@ with qw/
 /;
 
 use File::Type::WebImages ();
+use JSON::XS qw(encode_json);
 
 sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
 
@@ -27,7 +28,6 @@ sub _diff {
       diff      => $patch,
       # XXX Hack hack hack, see View::SyntaxHighlight
       blobs     => [map $_->{diff}, @$patch],
-      language  => 'Diff',
       %filename,
     );
 }
@@ -35,7 +35,7 @@ sub _diff {
 after diff_fancy => sub {
     my ($self, $c) = @_;
     $self->_diff($c);
-    $c->forward('View::SyntaxHighlight');
+    $c->forward('Model::ContentMangler');
 };
 
 after diff_plain => sub {
@@ -65,13 +65,10 @@ after blame => sub {
     my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
     $c->stash(
         blame    => $blame,
-        # XXX Hack hack hack, see View::SyntaxHighlight
-        language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
         blob     => join("\n", map $_->{line}, @$blame),
     );
 
-    $c->forward('View::SyntaxHighlight')
-        unless $c->stash->{no_wrapper};
+    $c->forward('Model::ContentMangler');
 };
 
 =head2 blob
@@ -83,14 +80,10 @@ The blob action i.e the contents of a file.
 after blob => sub {
     my ( $self, $c ) = @_;
     $c->stash(
-        # XXX Hack hack hack, see View::SyntaxHighlight
-        language  => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
         is_image  => File::Type::WebImages::mime_type($c->stash->{blob}),
-        is_binary => -B $c->stash->{blob},
+        is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
     );
-
-    $c->forward('View::SyntaxHighlight')
-        unless $c->stash->{no_wrapper};
+    $c->forward('Model::ContentMangler');
 };
 
 after history => sub {
@@ -123,4 +116,28 @@ after history => sub {
     );
 };
 
+after file_commit_info => sub {
+    my ($self, $c) = @_;
+
+    my $repository  = $c->stash->{Repository};
+
+    my($commit) = $repository->list_revs(
+       sha1   => $c->stash->{Commit}->sha1,
+       count  => 1,
+       file   => $c->stash->{filename},
+    );
+
+    my $json_obj = !$commit
+                 ? { }
+                 : {
+                    sha1    => $commit->sha1,
+                    comment => $c->stash->{short_cmt}->($commit->comment),
+                    age     => $c->stash->{time_since}->($commit->authored_time),
+                };
+
+    $c->response->content_type('application/json');
+    # XXX Make use of the json branch
+    $c->response->body( encode_json $json_obj );
+};
+
 __PACKAGE__->meta->make_immutable;