Add root search action, which does nothing right now. How did this used to be impleme...
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
1 package Gitalist::Controller::Root;
2
3 use Moose;
4 use Moose::Autobox;
5 use Digest::MD5 qw(md5_hex);
6 use Gitalist::Utils qw/ age_string /;
7
8 use namespace::autoclean;
9
10 BEGIN { extends 'Gitalist::Controller' }
11
12 __PACKAGE__->config(namespace => '');
13
14 sub root : Chained('/') PathPart('') CaptureArgs(0) {}
15
16 sub index : Chained('base') PathPart('') Args(0) {
17     my ( $self, $c ) = @_;
18     $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
19 }
20
21 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
22   my($self, $c) = @_;
23
24   my $git_version = `git --version`;
25   chomp($git_version);
26   $c->stash(
27     git_version => $git_version,
28     version     => $Gitalist::VERSION,
29
30     time_since => sub {
31       return 'never' unless $_[0];
32       return age_string(time - $_[0]->epoch);
33     },
34     short_cmt => sub {
35       my $cmt = shift;
36       my($line) = split /\n/, $cmt;
37       $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/ if defined $line;
38       return $line;
39     },
40     abridged_description => sub {
41         join(' ', grep { defined } (split / /, shift)[0..10]);
42     },
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     },
50   );
51 }
52
53 sub search : Chained('base') Args(0) {}
54
55 =head2 search_help
56
57 Provides some help for the search form.
58
59 =cut
60
61 sub search_help : Chained('base') Args(0) {}
62
63 sub end : ActionClass('RenderView') {}
64
65 sub error_404 : Action {
66     my ($self, $c) = @_;
67     $c->response->status(404);
68     $c->response->body('Page not found');
69 }
70
71 __PACKAGE__->meta->make_immutable;
72
73 __END__
74
75 =head1 NAME
76
77 Gitalist::Controller::Root - Root controller for the application
78
79 =head1 DESCRIPTION
80
81 This controller handles all of the root level paths for the application
82
83 =head1 METHODS
84
85 =head2 root
86
87 Root of chained actions
88
89 =head2 base
90
91 Populate the header and footer. Perhaps not the best location.
92
93 =head2 index
94
95 Provides the repository listing.
96
97 =head2 end
98
99 Attempt to render a view, if needed.
100
101 =head2 error_404
102
103 =head1 AUTHORS
104
105 See L<Gitalist> for authors.
106
107 =head1 LICENSE
108
109 See L<Gitalist> for the license.
110
111 =cut