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