Commit | Line | Data |
89de6a33 |
1 | package Gitalist::Controller::Root; |
89de6a33 |
2 | |
c113db92 |
3 | use Moose; |
cce8c9b6 |
4 | use Moose::Autobox; |
b0265bca |
5 | use Digest::MD5 qw(md5_hex); |
c113db92 |
6 | use Gitalist::Utils qw/ age_string /; |
89de6a33 |
7 | |
c113db92 |
8 | use namespace::autoclean; |
89de6a33 |
9 | |
b6ec181b |
10 | BEGIN { extends 'Gitalist::Controller' } |
89de6a33 |
11 | |
12a0f9d3 |
12 | __PACKAGE__->config(namespace => ''); |
89de6a33 |
13 | |
c113db92 |
14 | sub root : Chained('/') PathPart('') CaptureArgs(0) {} |
89de6a33 |
15 | |
5bb401c6 |
16 | sub 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 |
21 | sub 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 |
53 | sub search : Chained('base') Args(0) {} |
54 | |
12a0f9d3 |
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') {} |
d9a9b56b |
64 | |
c113db92 |
65 | sub 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 | |
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 | |
5bb401c6 |
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 | |
82bc0f05 |
95 | Provides the repository listing. |
5bb401c6 |
96 | |
97 | =head2 end |
98 | |
99 | Attempt to render a view, if needed. |
d137f7d5 |
100 | |
d137f7d5 |
101 | =head2 error_404 |
102 | |
775e96e0 |
103 | =head1 AUTHORS |
89de6a33 |
104 | |
775e96e0 |
105 | See L<Gitalist> for authors. |
89de6a33 |
106 | |
107 | =head1 LICENSE |
108 | |
775e96e0 |
109 | See L<Gitalist> for the license. |
89de6a33 |
110 | |
111 | =cut |