Merge remote branch 'github/foxtons_design' into foxtons-frontend
[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);
c113db92 6use Gitalist::Utils qw/ age_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
5bb401c6 21sub base : Chained('/root') PathPart('') CaptureArgs(0) {
4621ecf0 22 my($self, $c) = @_;
04d1d917 23
066e9aa4 24 my $git_version = `git --version`;
25 chomp($git_version);
4621ecf0 26 $c->stash(
066e9aa4 27 git_version => $git_version,
da8f4f82 28 version => $Gitalist::VERSION,
29
4621ecf0 30 time_since => sub {
ef11b09e 31 return 'never' unless $_[0];
4621ecf0 32 return age_string(time - $_[0]->epoch);
33 },
34 short_cmt => sub {
35 my $cmt = shift;
36 my($line) = split /\n/, $cmt;
6dac2638 37 $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/ if defined $line;
4621ecf0 38 return $line;
39 },
5cd9b9f9 40 abridged_description => sub {
41 join(' ', grep { defined } (split / /, shift)[0..10]);
42 },
b0265bca 43 uri_for_gravatar => sub { # FIXME - Cache these?
44 my $email = shift;
45 my $size = shift;
46 my $uri = 'http://www.gravatar.com/avatar/' . md5_hex($email);
47 $uri .= "?s=$size" if $size;
48 return $uri;
49 },
4621ecf0 50 );
04d1d917 51}
d9a9b56b 52
872e6812 53sub search : Chained('base') Args(0) {}
54
12a0f9d3 55=head2 search_help
56
57Provides some help for the search form.
58
59=cut
60
61sub search_help : Chained('base') Args(0) {}
62
63sub end : ActionClass('RenderView') {}
d9a9b56b 64
c113db92 65sub error_404 : Action {
4111e151 66 my ($self, $c) = @_;
67 $c->response->status(404);
5232dbdd 68 $c->response->body('Page not found');
4111e151 69}
70
775e96e0 71__PACKAGE__->meta->make_immutable;
72
73__END__
74
d137f7d5 75=head1 NAME
76
77Gitalist::Controller::Root - Root controller for the application
78
79=head1 DESCRIPTION
80
81This controller handles all of the root level paths for the application
82
83=head1 METHODS
84
5bb401c6 85=head2 root
86
87Root of chained actions
88
89=head2 base
90
91Populate the header and footer. Perhaps not the best location.
92
93=head2 index
94
82bc0f05 95Provides the repository listing.
5bb401c6 96
97=head2 end
98
99Attempt to render a view, if needed.
d137f7d5 100
d137f7d5 101=head2 error_404
102
775e96e0 103=head1 AUTHORS
89de6a33 104
775e96e0 105See L<Gitalist> for authors.
89de6a33 106
107=head1 LICENSE
108
775e96e0 109See L<Gitalist> for the license.
89de6a33 110
111=cut