fixing inline pod documentation for the debian package. (missing whatis entry)
[catagits/Gitalist.git] / lib / Gitalist / Controller / Fragment / Ref.pm
CommitLineData
2980657b 1package Gitalist::Controller::Fragment::Ref;
0da7966e 2use Moose;
3use namespace::autoclean;
4
b6ec181b 5BEGIN { extends 'Gitalist::Controller' }
b9423b8e 6with qw/
7 Gitalist::URIStructure::Ref
8 Gitalist::URIStructure::Fragment::WithLog
9/;
0da7966e 10
e172b6b8 11use File::Type::WebImages ();
9912b062 12use JSON::XS qw(encode_json);
e172b6b8 13
0da7966e 14sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
15
7998de12 16sub _diff {
493327c8 17 my ($self, $c) = @_;
586572a7 18 my %diff_args = ( patch => 1 );
19 foreach my $arg qw/filename parent/ {
20 if (defined $c->stash->{$arg}) {
21 $diff_args{$arg} = $c->stash->{$arg};
22 };
23 };
24 my ($tree, $patch) = $c->stash->{Commit}->diff(
25 %diff_args,
493327c8 26 );
27 $c->stash(
28 diff_tree => $tree,
29 diff => $patch,
30 # XXX Hack hack hack, see View::SyntaxHighlight
31 blobs => [map $_->{diff}, @$patch],
5ac7ddcc 32 %diff_args,
493327c8 33 );
7998de12 34}
493327c8 35
d361d955 36after diff_fancy => sub {
37 my ($self, $c) = @_;
7998de12 38 $self->_diff($c);
0fb64eae 39 $c->forward('Model::ContentMangler');
d361d955 40};
41
42after diff_plain => sub {
43 my ($self, $c) = @_;
7998de12 44 $self->_diff($c);
493327c8 45};
46
1b33f63b 47after tree => sub {
b6ec181b 48 my ( $self, $c ) = @_;
1b33f63b 49 my $repository = $c->stash->{Repository};
50 my $commit = $c->stash->{Commit};
220ff256 51 my $tree_obj = $c->stash->{filename}
b9708061 52 ? $commit->sha_by_path($c->stash->{filename})
220ff256 53 : $commit->tree->[0]
1b33f63b 54 ;
55 $c->stash(
220ff256 56 tree => $tree_obj,
57 tree_list => $tree_obj->tree,
1b33f63b 58 );
59};
60
571348f6 61after blame => sub {
b6ec181b 62 my($self, $c) = @_;
571348f6 63
64 my $repository = $c->stash->{Repository};
5111a8ab 65
b6ec181b 66 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
571348f6 67 $c->stash(
68 blame => $blame,
571348f6 69 blob => join("\n", map $_->{line}, @$blame),
70 );
71
1064e5b8 72 $c->forward('Model::ContentMangler');
571348f6 73};
74
2298d93f 75=encoding UTF-8
76
77=head1 NAME
78
79Gitalist::Controller::Fragment::Ref - Fragment::Ref module for Gitalist::Controller
80
85aed493 81=head2 blob
82
83The blob action i.e the contents of a file.
84
85=cut
86
87after blob => sub {
b6ec181b 88 my ( $self, $c ) = @_;
85aed493 89 $c->stash(
e172b6b8 90 is_image => File::Type::WebImages::mime_type($c->stash->{blob}),
53a9d6de 91 is_binary => Gitalist::Utils::is_binary($c->stash->{blob}),
85aed493 92 );
1064e5b8 93 $c->forward('Model::ContentMangler');
85aed493 94};
95
18fdf3d0 96after history => sub {
97 my ($self, $c) = @_;
98 my $repository = $c->stash->{Repository};
99 my $filename = $c->stash->{filename};
100
101 my %logargs = (
102 sha1 => $c->stash->{Commit}->sha1,
5111a8ab 103 count => Gitalist->config->{paging}{log} || 25,
18fdf3d0 104 ($filename ? (file => $filename) : ())
105 );
106
9aed017f 107 my $commit = $repository->get_object('HEAD');
b9708061 108 my $file = $commit->sha_by_path($filename);
18fdf3d0 109
110 my $page = $c->req->param('pg') || 0;
111 $logargs{skip} = $c->req->param('pg') * $logargs{count}
112 if $c->req->param('pg');
113
114 $c->stash(
115 log_lines => [$repository->list_revs(%logargs)],
116 refs => $repository->references,
117 filename => $filename,
118 filetype => $file->type,
ff90329f 119 page => $page,
18fdf3d0 120 );
121};
122
9912b062 123after file_commit_info => sub {
124 my ($self, $c) = @_;
125
126 my $repository = $c->stash->{Repository};
127
128 my($commit) = $repository->list_revs(
129 sha1 => $c->stash->{Commit}->sha1,
130 count => 1,
131 file => $c->stash->{filename},
132 );
133
e404e9a6 134 my $json_obj = !$commit
135 ? { }
136 : {
faafb966 137 sha1 => $commit->sha1,
138 comment => $c->stash->{short_cmt}->($commit->comment),
139 age => $c->stash->{time_since}->($commit->authored_time),
140 };
9912b062 141
142 $c->response->content_type('application/json');
143 # XXX Make use of the json branch
144 $c->response->body( encode_json $json_obj );
145};
146
0da7966e 147__PACKAGE__->meta->make_immutable;