WIP of moving the project list to an action.
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
CommitLineData
89de6a33 1package Gitalist::Controller::Root;
42fe5d11 2use Moose;
3use namespace::autoclean;
89de6a33 4
42fe5d11 5BEGIN { extends 'Catalyst::Controller' }
89de6a33 6
7#
8# Sets the actions in this controller to be registered with no prefix
9# so they function identically to actions created in MyApp.pm
10#
11__PACKAGE__->config->{namespace} = '';
12
13=head1 NAME
14
15Gitalist::Controller::Root - Root Controller for Gitalist
16
17=head1 DESCRIPTION
18
19[enter your description here]
20
21=head1 METHODS
22
23=cut
24
25=head2 index
26
27=cut
28
89de6a33 29use IO::Capture::Stdout;
86382b95 30use File::Slurp qw(slurp);
d3feefcf 31
89de6a33 32sub default :Path {
86382b95 33 my ( $self, $c ) = @_;
34
35 my $capture = IO::Capture::Stdout->new();
36 $capture->start();
37 eval {
38 my $action = gitweb::main($c);
39 $action->();
40 };
41 $capture->stop();
42
43 gitweb::git_header_html();
44 gitweb::git_footer_html();
45 my $output = join '', $capture->read;
46 $c->stash->{content} = $output
47 unless $c->stash->{content};
48 $c->stash->{template} = 'default.tt2';
49}
50
51sub index :Path :Args(0) {
89de6a33 52 my ( $self, $c ) = @_;
53
86382b95 54 my $order = $c->req->param('order');
55 if($order && $order !~ m/none|project|descr|owner|age/) {
56 die "Unknown order parameter";
57 }
58
59 my @list = $c->model('Git')->projects;
60 if (!@list) {
61 die "No projects found";
62 }
63
64 if (-f $c->config->{home_text}) {
65 print "<div class=\"index_include\">\n";
66 print slurp($c->config->{home_text});
67 print "</div>\n";
68 }
69
70 my $cgi;
71 print $cgi->startform(-method => "get") .
72 "<p class=\"projsearch\">Search:\n" .
73 $cgi->textfield(-name => "s", -value => $c->req->param('searchtext')) . "\n" .
74 "</p>" .
75 $cgi->end_form() . "\n";
76
77 git_project_list_body(\@list, $order);
89de6a33 78}
79
80=head2 end
81
82Attempt to render a view, if needed.
83
84=cut
85
86sub end : ActionClass('RenderView') {}
87
88=head1 AUTHOR
89
90Dan Brook,,,
91
92=head1 LICENSE
93
94This library is free software. You can redistribute it and/or modify
95it under the same terms as Perl itself.
96
97=cut
98
42fe5d11 99__PACKAGE__->meta->make_immutable;