1 package Gitalist::Controller::Root;
5 use Digest::MD5 qw(md5_hex);
6 use Gitalist::Utils qw/ age_string /;
8 use namespace::autoclean;
10 BEGIN { extends 'Gitalist::Controller' }
12 __PACKAGE__->config(namespace => '');
14 sub root : Chained('/') PathPart('') CaptureArgs(0) {}
16 sub index : Chained('base') PathPart('') Args(0) {
17 my ( $self, $c ) = @_;
18 $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
22 sub css : Chained('/root') PathPart('core.css') Args(0) {
23 my ( $self, $c ) = @_;
25 $c->stash( template => 'static/css/core.css', content_type => 'text/css' );
28 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
31 my $git_version = `git --version`;
34 git_version => $git_version,
35 version => $Gitalist::VERSION,
38 return 'never' unless $_[0];
39 return age_string(time - $_[0]->epoch);
43 my($line) = split /\n/, $cmt;
44 $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/ if defined $line;
47 abridged_description => sub {
48 join(' ', grep { defined } (split / /, shift)[0..10]);
50 uri_for_gravatar => sub {
53 my $uri = 'http://www.gravatar.com/avatar/' . md5_hex($email);
54 $uri .= "?s=$size" if $size;
60 sub search : Chained('base') Args(0) {}
64 Provides some help for the search form.
68 sub search_help : Chained('base') Args(0) {}
70 sub end : ActionClass('Serialize') {
72 # Give repository views the current HEAD.
73 if ($c->stash->{Repository}) {
74 $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
76 if ($c->stash->{data} && blessed $c->stash->{data}) {
77 $c->stash->{rest} = $c->stash->{data}->pack;
81 sub error_404 : Action {
83 $c->response->status(404);
84 $c->response->body('Page not found');
88 default => 'text/html',
90 'application/json' => [qw/ JSON /],
91 map { $_ => [qw/ View Default /] }
92 qw( text/css text/html text/plain
93 application/atom+xml application/rss+xml application/rss )
95 content_type_stash_key => 'content_type',
98 __PACKAGE__->meta->make_immutable;
104 Gitalist::Controller::Root - Root controller for the application
108 This controller handles all of the root level paths for the application
114 Root of chained actions
118 Populate the header and footer. Perhaps not the best location.
122 Provides the repository listing.
126 Attempt to render a view, if needed.
132 See L<Gitalist> for authors.
136 See L<Gitalist> for the license.