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 # XXX Probably not the best place for it but it will do for now.
109 if(my $proj = $c->req->param('p')) {
110 my $m = $c->model('Git');
114 # Yes, this is hideous.
119 # XXX This could probably be dropped altogether.
120 use Gitalist::Util qw(to_utf8);
121 # Formally git_header_html
125 my $title = $c->config->{sitename};
127 my $project = $c->req->param('project') || $c->req->param('p');
128 my $action = $c->req->param('action') || $c->req->param('a');
129 my $file_name = $c->req->param('filename') || $c->req->param('f');
130 if(defined $project) {
131 $title .= " - " . to_utf8($project);
132 if (defined $action) {
133 $title .= "/$action";
134 if (defined $file_name) {
135 $title .= " - " . $file_name;
136 if ($action eq "tree" && $file_name !~ m|/$|) {
143 $c->stash->{version} = $c->config->{version};
144 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
145 $c->stash->{title} = $title;
147 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
148 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
150 $c->stash->{project} = $project;
153 my %href_params = $self->feed_info($c);
154 $href_params{'-title'} ||= 'log';
156 foreach my $format qw(RSS Atom) {
157 my $type = lc($format);
160 title => "$project - $href_params{'-title'} - $format feed",
162 # XXX A bit hacky and could do with using gitweb::href() features
163 href => "?a=$type;p=$project",
164 type => "application/$type+xml"
168 # XXX This duplication also feels a bit awkward
169 title => "$project - $href_params{'-title'} - $format feed (no merges)",
170 href => "?a=$type;p=$project;opt=--no-merges",
171 type => "application/$type+xml"
177 title => $c->config->{sitename}." projects list",
178 href => '?a=project_index',
179 type => "text/plain; charset=utf-8"
182 title => $c->config->{sitename}." projects feeds",
184 type => "text/plain; charset=utf-8"
188 $c->stash->{favicon} = $c->config->{favicon};
193 logo_url => $c->config->{logo_url},
194 logo_label => $c->config->{logo_label},
195 logo_img => $c->config->{logo},
196 home_link => $c->config->{home_link},
197 home_link_str => $c->config->{home_link_str},
200 if(defined $project) {
202 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
203 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
204 || $c->req->param('h') || $c->req->param('hash')
210 # Formally git_footer_html
214 my $feed_class = 'rss_logo';
217 my $project = $c->req->param('project') || $c->req->param('p');
218 if(defined $project) {
219 (my $pstr = $project) =~ s[/?\.git$][];
220 my $descr = $c->model('Git')->project_info($project)->{description};
221 $c->stash->{project_description} = defined $descr
225 my %href_params = $self->feed_info($c);
227 $feed_class .= ' generic';
229 $href_params{'-title'} ||= 'log';
233 class => $feed_class,
234 title => "$href_params{'-title'} $_ feed",
235 href => "/?p=$project;a=\L$_",
242 class => $feed_class,
244 href => "/?a=$_->[0]",
246 }, [opml=>'OPML'],[project_index=>'TXT'],
251 # XXX This feels wrong here, should probably be refactored.
252 # returns hash to be passed to href to generate gitweb URL
253 # in -title key it returns description of link
257 my $format = shift || 'Atom';
258 my %res = (action => lc($format));
260 # feed links are possible only for project views
261 return unless $c->req->param('project');
263 # some views should link to OPML, or to generic project feed,
264 # or don't have specific feed yet (so they should use generic)
265 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
268 my $hash = $c->req->param('h') || $c->req->param('hash');
269 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
271 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
272 # from tag links; this also makes possible to detect branch links
273 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
274 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
278 # find log type for feed description (title)
280 my $file_name = $c->req->param('f') || $c->req->param('filename');
281 if (defined $file_name) {
282 $type = "history of $file_name";
283 $type .= "/" if $c->req->param('action') eq 'tree';
284 $type .= " on '$branch'" if (defined $branch);
286 $type = "log of $branch" if (defined $branch);
289 $res{-title} = $type;
290 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
291 $res{'file_name'} = $file_name;
297 Attempt to render a view, if needed.
301 sub end : ActionClass('RenderView') {}
309 This library is free software. You can redistribute it and/or modify
310 it under the same terms as Perl itself.
314 __PACKAGE__->meta->make_immutable;