Massive tree action speedup
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
CommitLineData
89de6a33 1package Gitalist::Controller::Root;
89de6a33 2
c113db92 3use Moose;
cce8c9b6 4use Moose::Autobox;
b0265bca 5use Digest::MD5 qw(md5_hex);
eb8ee28a 6use Gitalist::Utils qw/ age_string mode_string /;
89de6a33 7
c113db92 8use namespace::autoclean;
89de6a33 9
b6ec181b 10BEGIN { extends 'Gitalist::Controller' }
89de6a33 11
12a0f9d3 12__PACKAGE__->config(namespace => '');
89de6a33 13
c113db92 14sub root : Chained('/') PathPart('') CaptureArgs(0) {}
89de6a33 15
5bb401c6 16sub index : Chained('base') PathPart('') Args(0) {
12a0f9d3 17 my ( $self, $c ) = @_;
18 $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
286cea09 19}
20
2b686219 21# XXX Fragile much?
22sub css : Chained('/root') PathPart('core.css') Args(0) {
23 my ( $self, $c ) = @_;
24
e1a23af1 25 $c->stash( template => 'static/css/core.css', content_type => 'text/css' );
2b686219 26}
27
5bb401c6 28sub base : Chained('/root') PathPart('') CaptureArgs(0) {
4621ecf0 29 my($self, $c) = @_;
04d1d917 30
066e9aa4 31 my $git_version = `git --version`;
32 chomp($git_version);
4621ecf0 33 $c->stash(
066e9aa4 34 git_version => $git_version,
da8f4f82 35 version => $Gitalist::VERSION,
36
4621ecf0 37 time_since => sub {
ef11b09e 38 return 'never' unless $_[0];
4621ecf0 39 return age_string(time - $_[0]->epoch);
40 },
41 short_cmt => sub {
42 my $cmt = shift;
43 my($line) = split /\n/, $cmt;
6dac2638 44 $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/ if defined $line;
4621ecf0 45 return $line;
46 },
5cd9b9f9 47 abridged_description => sub {
48 join(' ', grep { defined } (split / /, shift)[0..10]);
49 },
5111a8ab 50 uri_for_gravatar => sub {
b0265bca 51 my $email = shift;
52 my $size = shift;
53 my $uri = 'http://www.gravatar.com/avatar/' . md5_hex($email);
54 $uri .= "?s=$size" if $size;
55 return $uri;
56 },
eb8ee28a 57 mode_string => sub {
58 return mode_string(oct shift);
59 }
4621ecf0 60 );
04d1d917 61}
d9a9b56b 62
872e6812 63sub search : Chained('base') Args(0) {}
64
12a0f9d3 65=head2 search_help
66
67Provides some help for the search form.
68
69=cut
70
71sub search_help : Chained('base') Args(0) {}
72
f41fc741 73sub end : ActionClass('Serialize') {
74 my ($self, $c) = @_;
75 # Give repository views the current HEAD.
76 if ($c->stash->{Repository}) {
77 $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
78 }
79 if ($c->stash->{data} && blessed $c->stash->{data}) {
80 $c->stash->{rest} = $c->stash->{data}->pack;
81 }
82}
d9a9b56b 83
c113db92 84sub error_404 : Action {
4111e151 85 my ($self, $c) = @_;
86 $c->response->status(404);
5232dbdd 87 $c->response->body('Page not found');
4111e151 88}
89
f41fc741 90__PACKAGE__->config(
91 default => 'text/html',
92 map => {
93 'application/json' => [qw/ JSON /],
94 map { $_ => [qw/ View Default /] }
95 qw( text/css text/html text/plain
96 application/atom+xml application/rss+xml application/rss )
e1a23af1 97 },
98 content_type_stash_key => 'content_type',
f41fc741 99);
100
775e96e0 101__PACKAGE__->meta->make_immutable;
102
103__END__
104
d137f7d5 105=head1 NAME
106
107Gitalist::Controller::Root - Root controller for the application
108
109=head1 DESCRIPTION
110
111This controller handles all of the root level paths for the application
112
113=head1 METHODS
114
5bb401c6 115=head2 root
116
117Root of chained actions
118
119=head2 base
120
121Populate the header and footer. Perhaps not the best location.
122
123=head2 index
124
82bc0f05 125Provides the repository listing.
5bb401c6 126
127=head2 end
128
129Attempt to render a view, if needed.
d137f7d5 130
d137f7d5 131=head2 error_404
132
775e96e0 133=head1 AUTHORS
89de6a33 134
775e96e0 135See L<Gitalist> for authors.
89de6a33 136
137=head1 LICENSE
138
775e96e0 139See L<Gitalist> for the license.
89de6a33 140
141=cut