fixing inline pod documentation for the debian package. (missing whatis entry)
[catagits/Gitalist.git] / lib / Gitalist / Controller / Ref.pm
index e43bd98..46def57 100644 (file)
@@ -6,24 +6,41 @@ use namespace::autoclean;
 BEGIN { extends 'Gitalist::Controller' }
 with 'Gitalist::URIStructure::Ref';
 
+use File::Type;
+use File::Type::WebImages ();
+
 sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
 
 after commit => sub {
   my($self, $c) = @_;
 
-  $c->stash->{diff_tree} = ($c->stash->{Repository}->diff(
-    commit => $c->stash->{Commit},
-  ))[0];
+  $c->stash->{diff_tree} = ( $c->stash->{Commit}->diff )[0];
 };
 
 sub raw : Chained('find') Does('FilenameArgs') Args() {
     my ($self, $c) = @_;
     $c->forward('find_blob');
 
-    $c->response->content_type('text/plain; charset=utf-8');
+    if(!Gitalist::Utils::is_binary($c->stash->{blob})) {
+        $c->response->content_type('text/plain; charset=utf-8');
+    } else {
+        my $ft = File::Type->new();
+        $c->response->content_type(
+            File::Type::WebImages::mime_type($c->stash->{blob})
+         || File::Type->new->mime_type($c->stash->{blob})
+        );
+    }
+
+    utf8::decode($c->stash->{blob});
     $c->response->body(delete $c->stash->{blob});
 }
 
+=encoding UTF-8
+
+=head1 NAME
+
+Gitalist::Controller::Ref - Controller::Ref module for Gitalist
+
 =head2 snapshot
 
 Provides a snapshot of a given commit.