1 package Gitalist::Controller::Root;
3 use namespace::autoclean;
5 BEGIN { extends 'Catalyst::Controller' }
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
11 __PACKAGE__->config->{namespace} = '';
15 Gitalist::Controller::Root - Root Controller for Gitalist
19 [enter your description here]
29 use IO::Capture::Stdout;
30 use File::Slurp qw(slurp);
34 my ( $self, $c ) = @_;
36 # XXX A slippery slope to be sure.
37 if($c->req->param('a')) {
38 my $capture = IO::Capture::Stdout->new();
41 my $action = gitweb::main($c);
50 my $output = join '', $capture->read;
51 $c->stash->{gitweb_output} = $output;
52 $c->stash->{template} = 'gitweb.tt2';
56 sub index :Path :Args(0) {
57 my ( $self, $c ) = @_;
59 # Leave actions up to gitweb at this point.
60 return $self->run_gitweb($c)
61 if $c->req->param('a');
63 my $list = $c->model('Git')->list_projects;
65 die "No projects found";
69 searchtext => $c->req->param('searchtext') || '',
78 # Yes, this is hideous.
83 use Gitalist::Util qw(to_utf8);
84 use HTML::Entities qw(encode_entities);
85 use URI::Escape qw(uri_escape);
86 # Formally git_header_html
90 my $title = $c->config->{sitename};
92 my $project = $c->req->param('project') || $c->req->param('p');
93 my $action = $c->req->param('action') || $c->req->param('a');
94 my $file_name = $c->req->param('filename') || $c->req->param('f');
95 if(defined $project) {
96 $title .= " - " . to_utf8($project);
97 if (defined $action) {
99 if (defined $file_name) {
100 $title .= " - " . encode_entities($file_name);
101 if ($action eq "tree" && $file_name !~ m|/$|) {
108 $c->stash->{version} = $c->config->{version};
109 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
110 $c->stash->{title} = $title;
112 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
113 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
115 $c->stash->{project} = $project;
118 my %href_params = $self->feed_info($c);
119 $href_params{'-title'} ||= 'log';
121 foreach my $format qw(RSS Atom) {
122 my $type = lc($format);
125 title => "$project - $href_params{'-title'} - $format feed",
126 # XXX A bit hacky and could do with using gitweb::href() features
127 href => "?a=$type;p=$project",
128 type => "application/$type+xml"
131 # XXX This duplication also feels a bit awkward
132 title => "$project - $href_params{'-title'} - $format feed (no merges)",
133 href => "?a=$type;p=$project;opt=--no-merges",
134 type => "application/$type+xml"
140 title => $c->config->{sitename}." projects list",
141 href => '?a=project_index',
142 type => "text/plain; charset=utf-8"
145 title => $c->config->{sitename}." projects feeds",
147 type => "text/plain; charset=utf-8"
151 $c->stash->{favicon} = $c->config->{favicon};
156 logo_url => uri_escape($c->config->{logo_url}),
157 logo_label => encode_entities($c->config->{logo_label}),
158 logo_img => $c->config->{logo},
159 home_link => uri_escape($c->config->{home_link}),
160 home_link_str => $c->config->{home_link_str},
163 if(defined $project) {
165 search_text => $c->req->param('s') || $c->req->param('searchtext'),
166 search_hash => $c->req->param('hb') || $c->req->param('hashbase')
167 || $c->req->param('h') || $c->req->param('hash')
173 # Formally git_footer_html
177 my $feed_class = 'rss_logo';
180 my $project = $c->req->param('project') || $c->req->param('p');
181 if(defined $project) {
182 (my $pstr = $project) =~ s[/?\.git$][];
183 my $descr = $c->model('Git')->project_info($project)->{description};
184 $c->stash->{project_description} = defined $descr
185 ? encode_entities($descr)
188 my %href_params = $self->feed_info($c);
190 $feed_class .= ' generic';
192 $href_params{'-title'} ||= 'log';
196 class => $feed_class,
197 title => "$href_params{'-title'} $_ feed",
198 href => "/?p=$project;a=\L$_",
205 class => $feed_class,
207 href => "/?a=$_->[0]",
209 }, [opml=>'OPML'],[project_index=>'TXT'],
214 # XXX This feels wrong here, should probably be refactored.
215 # returns hash to be passed to href to generate gitweb URL
216 # in -title key it returns description of link
220 my $format = shift || 'Atom';
221 my %res = (action => lc($format));
223 # feed links are possible only for project views
224 return unless $c->req->param('project');
225 # some views should link to OPML, or to generic project feed,
226 # or don't have specific feed yet (so they should use generic)
227 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
230 my $hash = $c->req->param('h') || $c->req->param('hash');
231 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
232 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
233 # from tag links; this also makes possible to detect branch links
234 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
235 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
238 # find log type for feed description (title)
240 my $file_name = $c->req->param('f') || $c->req->param('filename');
241 if (defined $file_name) {
242 $type = "history of $file_name";
243 $type .= "/" if $c->req->param('action') eq 'tree';
244 $type .= " on '$branch'" if (defined $branch);
246 $type = "log of $branch" if (defined $branch);
249 $res{-title} = $type;
250 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
251 $res{'file_name'} = $file_name;
257 Attempt to render a view, if needed.
261 sub end : ActionClass('RenderView') {}
269 This library is free software. You can redistribute it and/or modify
270 it under the same terms as Perl itself.
274 __PACKAGE__->meta->make_immutable;