Change everything round to be /ref/ instead of /commit/ as this makes more sense
[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' }
2980657b 6with 'Gitalist::URIStructure::Ref';
0da7966e 7
8sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
9
493327c8 10after diff => sub {
11 my ($self, $c) = @_;
12 my $commit = $c->stash->{Commit};
13 my($tree, $patch) = $c->stash->{Repository}->diff(
14 commit => $commit,
15 parent => $c->req->param('hp') || undef,
16 patch => 1,
17 );
18 $c->stash(
19 diff_tree => $tree,
20 diff => $patch,
21 # XXX Hack hack hack, see View::SyntaxHighlight
22 blobs => [map $_->{diff}, @$patch],
23 language => 'Diff',
24 );
d361d955 25};
493327c8 26
d361d955 27after diff_fancy => sub {
28 my ($self, $c) = @_;
29 $c->forward('View::SyntaxHighlight');
30};
31
32after diff_plain => sub {
33 my ($self, $c) = @_;
34 $c->response->content_type('text/plain; charset=utf-8');
493327c8 35};
36
1b33f63b 37after tree => sub {
b6ec181b 38 my ( $self, $c ) = @_;
1b33f63b 39 my $repository = $c->stash->{Repository};
40 my $commit = $c->stash->{Commit};
b6ec181b 41 my $tree = $c->stash->{filename}
42 ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
1b33f63b 43 : $repository->get_object($commit->tree_sha1)
44 ;
45 $c->stash(
46 tree => $tree,
47 tree_list => [$repository->list_tree($tree->sha1)],
b6ec181b 48 path => $c->stash->{filename}, # FIXME?
1b33f63b 49 );
50};
51
571348f6 52after blame => sub {
b6ec181b 53 my($self, $c) = @_;
571348f6 54
55 my $repository = $c->stash->{Repository};
571348f6 56 # WTF?
b6ec181b 57 my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
571348f6 58 $c->stash(
59 blame => $blame,
571348f6 60 # XXX Hack hack hack, see View::SyntaxHighlight
b6ec181b 61 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
571348f6 62 blob => join("\n", map $_->{line}, @$blame),
63 );
64
65 $c->forward('View::SyntaxHighlight')
66 unless $c->stash->{no_wrapper};
67};
68
85aed493 69=head2 blob
70
71The blob action i.e the contents of a file.
72
73=cut
74
75after blob => sub {
b6ec181b 76 my ( $self, $c ) = @_;
85aed493 77 $c->stash(
85aed493 78 # XXX Hack hack hack, see View::SyntaxHighlight
b6ec181b 79 language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
85aed493 80 );
81
82 $c->forward('View::SyntaxHighlight')
83 unless $c->stash->{no_wrapper};
84};
85
0da7966e 86__PACKAGE__->meta->make_immutable;