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);
33 my ( $self, $c ) = @_;
35 # XXX A slippery slope to be sure.
36 if($c->req->param('a')) {
37 my $capture = IO::Capture::Stdout->new();
40 my $action = gitweb::main($c);
49 my $output = join '', $capture->read;
50 $c->stash->{gitweb_output} = $output;
51 $c->stash->{template} = 'gitweb.tt2';
55 sub index :Path :Args(0) {
56 my ( $self, $c ) = @_;
58 # Leave actions up to gitweb at this point.
59 return $self->run_gitweb($c)
60 if $c->req->param('a');
62 my $list = $c->model('Git')->list_projects;
64 die "No projects found";
68 searchtext => $c->req->param('searchtext') || '',
75 my ( $self, $c ) = @_;
78 blob => $c->model('GPP')->get_object($c->req->param('h'))->content,
84 my ( $self, $c ) = @_;
86 my @log = $c->model('Git')->reflog(
97 my ( $self, $c ) = @_;
100 commit => $c->model('GPP')->get_object($c->req->param('h')),
108 # Yes, this is hideous.
113 # XXX This could probably be dropped altogether.
114 use Gitalist::Util qw(to_utf8);
115 # Formally git_header_html
119 my $title = $c->config->{sitename};
121 my $project = $c->req->param('project') || $c->req->param('p');
122 my $action = $c->req->param('action') || $c->req->param('a');
123 my $file_name = $c->req->param('filename') || $c->req->param('f');
124 if(defined $project) {
125 $title .= " - " . to_utf8($project);
126 if (defined $action) {
127 $title .= "/$action";
128 if (defined $file_name) {
129 $title .= " - " . $file_name;
130 if ($action eq "tree" && $file_name !~ m|/$|) {
137 $c->stash->{version} = $c->config->{version};
138 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
139 $c->stash->{title} = $title;
141 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
142 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
144 $c->stash->{project} = $project;
147 my %href_params = $self->feed_info($c);
148 $href_params{'-title'} ||= 'log';
150 foreach my $format qw(RSS Atom) {
151 my $type = lc($format);
154 title => "$project - $href_params{'-title'} - $format feed",
156 # XXX A bit hacky and could do with using gitweb::href() features
157 href => "?a=$type;p=$project",
158 type => "application/$type+xml"
162 # XXX This duplication also feels a bit awkward
163 title => "$project - $href_params{'-title'} - $format feed (no merges)",
164 href => "?a=$type;p=$project;opt=--no-merges",
165 type => "application/$type+xml"
171 title => $c->config->{sitename}." projects list",
172 href => '?a=project_index',
173 type => "text/plain; charset=utf-8"
176 title => $c->config->{sitename}." projects feeds",
178 type => "text/plain; charset=utf-8"
182 $c->stash->{favicon} = $c->config->{favicon};
187 logo_url => $c->config->{logo_url},
188 logo_label => $c->config->{logo_label},
189 logo_img => $c->config->{logo},
190 home_link => $c->config->{home_link},
191 home_link_str => $c->config->{home_link_str},
194 if(defined $project) {
196 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
197 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
198 || $c->req->param('h') || $c->req->param('hash')
204 # Formally git_footer_html
208 my $feed_class = 'rss_logo';
211 my $project = $c->req->param('project') || $c->req->param('p');
212 if(defined $project) {
213 (my $pstr = $project) =~ s[/?\.git$][];
214 my $descr = $c->model('Git')->project_info($project)->{description};
215 $c->stash->{project_description} = defined $descr
219 my %href_params = $self->feed_info($c);
221 $feed_class .= ' generic';
223 $href_params{'-title'} ||= 'log';
227 class => $feed_class,
228 title => "$href_params{'-title'} $_ feed",
229 href => "/?p=$project;a=\L$_",
236 class => $feed_class,
238 href => "/?a=$_->[0]",
240 }, [opml=>'OPML'],[project_index=>'TXT'],
245 # XXX This feels wrong here, should probably be refactored.
246 # returns hash to be passed to href to generate gitweb URL
247 # in -title key it returns description of link
251 my $format = shift || 'Atom';
252 my %res = (action => lc($format));
254 # feed links are possible only for project views
255 return unless $c->req->param('project');
257 # some views should link to OPML, or to generic project feed,
258 # or don't have specific feed yet (so they should use generic)
259 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
262 my $hash = $c->req->param('h') || $c->req->param('hash');
263 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
265 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
266 # from tag links; this also makes possible to detect branch links
267 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
268 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
272 # find log type for feed description (title)
274 my $file_name = $c->req->param('f') || $c->req->param('filename');
275 if (defined $file_name) {
276 $type = "history of $file_name";
277 $type .= "/" if $c->req->param('action') eq 'tree';
278 $type .= " on '$branch'" if (defined $branch);
280 $type = "log of $branch" if (defined $branch);
283 $res{-title} = $type;
284 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
285 $res{'file_name'} = $file_name;
291 Attempt to render a view, if needed.
295 sub end : ActionClass('RenderView') {}
303 This library is free software. You can redistribute it and/or modify
304 it under the same terms as Perl itself.
308 __PACKAGE__->meta->make_immutable;