blobdiff just appears to be a reimplementation of the diff we already have. Need...
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
1 package Gitalist::Controller::Root;
2
3 use Moose;
4 use Moose::Autobox;
5 use Sys::Hostname qw/hostname/;
6 use XML::OPML::SimpleGen;
7
8 use Gitalist::Utils qw/ age_string /;
9
10 use namespace::autoclean;
11
12 BEGIN { extends 'Gitalist::Controller' }
13
14 __PACKAGE__->config->{namespace} = '';
15
16 sub root : Chained('/') PathPart('') CaptureArgs(0) {}
17
18 sub index : Chained('base') PathPart('') Args(0) {
19   my ( $self, $c ) = @_;
20
21   my $search = $c->req->param('s') || '';
22
23   $c->stash(
24     search_text => $search,
25   );
26 }
27
28 =head2 search_help
29
30 Provides some help for the search form.
31
32 =cut
33
34 sub search_help : Chained('base') Args(0) {}
35
36 sub opml : Chained('base') Args(0) {
37   my($self, $c) = @_;
38
39   my $opml = XML::OPML::SimpleGen->new();
40
41   $opml->head(title => lc(hostname()) . ' - ' . Gitalist->config->{name});
42
43   my @list = @{ $c->model()->repositories };
44   die 'No repositories found in '. $c->model->repo_dir
45     unless @list;
46
47   for my $proj ( @list ) {
48     $opml->insert_outline(
49       text   => $proj->name. ' - '. $proj->description,
50       xmlUrl => $c->uri_for(rss => {p => $proj->name}),
51     );
52   }
53
54   $c->response->body($opml->as_string);
55   $c->response->content_type('application/rss');
56   $c->response->status(200);
57 }
58
59 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
60   my($self, $c) = @_;
61
62   my $git_version = `git --version`;
63   chomp($git_version);
64   $c->stash(
65     git_version => $git_version,
66     version     => $Gitalist::VERSION,
67
68     # XXX Move these to a plugin!
69     time_since => sub {
70       return 'never' unless $_[0];
71       return age_string(time - $_[0]->epoch);
72     },
73     short_cmt => sub {
74       my $cmt = shift;
75       my($line) = split /\n/, $cmt;
76       $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/;
77       return $line;
78     },
79     abridged_description => sub {
80         join(' ', grep { defined } (split / /, shift)[0..10]);
81     },
82   );
83 }
84
85 sub end : ActionClass('RenderView') {
86     my ($self, $c) = @_;
87     # Give repository views the current HEAD.
88     if ($c->stash->{Repository}) {
89         $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
90     }
91 }
92
93 sub error_404 : Action {
94     my ($self, $c) = @_;
95     $c->response->status(404);
96     $c->response->body('Page not found');
97 }
98
99 __PACKAGE__->meta->make_immutable;
100
101 __END__
102
103 =head1 NAME
104
105 Gitalist::Controller::Root - Root controller for the application
106
107 =head1 DESCRIPTION
108
109 This controller handles all of the root level paths for the application
110
111 =head1 METHODS
112
113 =head2 root
114
115 Root of chained actions
116
117 =head2 base
118
119 Populate the header and footer. Perhaps not the best location.
120
121 =head2 index
122
123 Provides the repository listing.
124
125 =head2 end
126
127 Attempt to render a view, if needed.
128
129 =head2 blame
130
131 =head2 error_404
132
133 =head2 history
134
135 =head2 opml
136
137 =head2 repository_index
138
139 =head1 AUTHORS
140
141 See L<Gitalist> for authors.
142
143 =head1 LICENSE
144
145 See L<Gitalist> for the license.
146
147 =cut