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;
33 The main shim around C<gitweb.pm>.
38 my ( $self, $c ) = @_;
40 # XXX A slippery slope to be sure.
41 if($c->req->param('a')) {
42 my $capture = IO::Capture::Stdout->new();
45 my $action = gitweb::main($c);
54 my $output = join '', $capture->read;
55 $c->stash->{gitweb_output} = $output;
56 $c->stash->{template} = 'gitweb.tt2';
62 Provides the project listing.
66 sub index :Path :Args(0) {
67 my ( $self, $c ) = @_;
69 # Leave actions up to gitweb at this point.
70 return $self->run_gitweb($c)
71 if $c->req->param('a');
73 my $list = $c->model('Git')->list_projects;
75 die "No projects found";
79 searchtext => $c->req->param('searchtext') || '',
87 The blob action i.e the contents of a file.
92 my ( $self, $c ) = @_;
95 blob => $c->model('Git')->get_object($c->req->param('h'))->content,
99 $c->forward('View::Syntax')
100 if $c->req->param('f') and $c->req->param('f') =~ /\.p[lm]$/;
105 Expose the local reflog. This may go away.
110 my ( $self, $c ) = @_;
112 my @log = $c->model('Git')->reflog(
124 Exposes a given commit. Probably too simple currently.
129 my ( $self, $c ) = @_;
132 commit => $c->model('Git')->get_object($c->req->param('h')),
139 Populate the header and footer. Perhaps not the best location.
146 # XXX Temp hack until a decent solution is invented.
147 $c->model('Git')->project($c->req->param('p'))
148 if $c->req->param('p');
150 # Yes, this is hideous.
155 # XXX This could probably be dropped altogether.
156 use Gitalist::Util qw(to_utf8);
157 # Formally git_header_html
161 my $title = $c->config->{sitename};
163 my $project = $c->req->param('project') || $c->req->param('p');
164 my $action = $c->req->param('action') || $c->req->param('a');
165 my $file_name = $c->req->param('filename') || $c->req->param('f');
166 if(defined $project) {
167 $title .= " - " . to_utf8($project);
168 if (defined $action) {
169 $title .= "/$action";
170 if (defined $file_name) {
171 $title .= " - " . $file_name;
172 if ($action eq "tree" && $file_name !~ m|/$|) {
179 $c->stash->{version} = $c->config->{version};
180 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
181 $c->stash->{title} = $title;
183 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
184 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
186 $c->stash->{project} = $project;
189 my %href_params = $self->feed_info($c);
190 $href_params{'-title'} ||= 'log';
192 foreach my $format qw(RSS Atom) {
193 my $type = lc($format);
196 title => "$project - $href_params{'-title'} - $format feed",
198 # XXX A bit hacky and could do with using gitweb::href() features
199 href => "?a=$type;p=$project",
200 type => "application/$type+xml"
204 # XXX This duplication also feels a bit awkward
205 title => "$project - $href_params{'-title'} - $format feed (no merges)",
206 href => "?a=$type;p=$project;opt=--no-merges",
207 type => "application/$type+xml"
213 title => $c->config->{sitename}." projects list",
214 href => '?a=project_index',
215 type => "text/plain; charset=utf-8"
218 title => $c->config->{sitename}." projects feeds",
220 type => "text/plain; charset=utf-8"
224 $c->stash->{favicon} = $c->config->{favicon};
229 logo_url => $c->config->{logo_url},
230 logo_label => $c->config->{logo_label},
231 logo_img => $c->config->{logo},
232 home_link => $c->config->{home_link},
233 home_link_str => $c->config->{home_link_str},
236 if(defined $project) {
238 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
239 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
240 || $c->req->param('h') || $c->req->param('hash')
246 # Formally git_footer_html
250 my $feed_class = 'rss_logo';
253 my $project = $c->req->param('project') || $c->req->param('p');
254 if(defined $project) {
255 (my $pstr = $project) =~ s[/?\.git$][];
256 my $descr = $c->model('Git')->project_info($project)->{description};
257 $c->stash->{project_description} = defined $descr
261 my %href_params = $self->feed_info($c);
263 $feed_class .= ' generic';
265 $href_params{'-title'} ||= 'log';
269 class => $feed_class,
270 title => "$href_params{'-title'} $_ feed",
271 href => "/?p=$project;a=\L$_",
278 class => $feed_class,
280 href => "/?a=$_->[0]",
282 }, [opml=>'OPML'],[project_index=>'TXT'],
287 # XXX This feels wrong here, should probably be refactored.
288 # returns hash to be passed to href to generate gitweb URL
289 # in -title key it returns description of link
293 my $format = shift || 'Atom';
294 my %res = (action => lc($format));
296 # feed links are possible only for project views
297 return unless $c->req->param('project');
299 # some views should link to OPML, or to generic project feed,
300 # or don't have specific feed yet (so they should use generic)
301 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
304 my $hash = $c->req->param('h') || $c->req->param('hash');
305 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
307 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
308 # from tag links; this also makes possible to detect branch links
309 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
310 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
314 # find log type for feed description (title)
316 my $file_name = $c->req->param('f') || $c->req->param('filename');
317 if (defined $file_name) {
318 $type = "history of $file_name";
319 $type .= "/" if $c->req->param('action') eq 'tree';
320 $type .= " on '$branch'" if (defined $branch);
322 $type = "log of $branch" if (defined $branch);
325 $res{-title} = $type;
326 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
327 $res{'file_name'} = $file_name;
333 Attempt to render a view, if needed.
337 sub end : ActionClass('RenderView') {}
345 This library is free software. You can redistribute it and/or modify
346 it under the same terms as Perl itself.
350 __PACKAGE__->meta->make_immutable;