* Added deps for File::Type and File::Type::WebImages.
* Haven't been able to test binary non-image files as the presence of one (I
tried a .zip) breaks Git::PurePerl on win32 at least.
requires 'DateTime';
requires 'DateTime::Format::Mail';
requires 'File::Copy::Recursive';
+requires 'File::Type';
+requires 'File::Type::WebImages';
requires 'File::Which';
requires 'HTML::Entities';
requires 'IPC::Run';
Gitalist::URIStructure::Fragment::WithLog
/;
+use File::Type::WebImages ();
+
sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
sub _diff {
my ( $self, $c ) = @_;
$c->stash(
# XXX Hack hack hack, see View::SyntaxHighlight
- language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
+ language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
+ is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
+ is_binary => -B $c->stash->{blob},
);
$c->forward('View::SyntaxHighlight')
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->forward('find_blob');
- $c->response->content_type('text/plain; charset=utf-8');
+ if(-T $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})
+ );
+ }
+
$c->response->body(delete $c->stash->{blob});
}
-[% blob %]
+[%- IF is_image -%]
+<div class='blob'><img src="[% c.uri_for_action('/ref/raw', c.req.captures, filename) %]" title="[% filename %]"></div>
+[%- ELSIF is_binary -%]
+<div class='blob'>This is a binary file which won't render natively on the web, but you can get it here all the same: <a href="[% c.uri_for_action('/ref/raw', c.req.captures, filename) %]" title="[% filename %]">[% filename %]</a></div>
+[%- ELSE -%]
+<pre class='blob'>[% blob | html %]</pre>
+[%- END -%]
[% short_cmt(head.comment) %]
</div>
[% END %]
-
- <pre class='blob'>[% subinclude('/fragment/ref/blob', c.req.captures, c.req.args.to_path) | html %]</pre>
+
+[% subinclude('/fragment/ref/blob', c.req.captures, c.req.args.to_path) %]
\ No newline at end of file
overflow:auto;
font-size:12px;
}
+div.blob {
+ text-align: center;
+ margin: 30px;
+}
/* /blobdiff etc */