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 ) = @_;
103 # XXX Probably not the best place for it but it will do for now.
104 if(my $proj = $c->req->param('p')) {
105 my $m = $c->model('Git');
109 # Yes, this is hideous.
114 # XXX This could probably be dropped altogether.
115 use Gitalist::Util qw(to_utf8);
116 # Formally git_header_html
120 my $title = $c->config->{sitename};
122 my $project = $c->req->param('project') || $c->req->param('p');
123 my $action = $c->req->param('action') || $c->req->param('a');
124 my $file_name = $c->req->param('filename') || $c->req->param('f');
125 if(defined $project) {
126 $title .= " - " . to_utf8($project);
127 if (defined $action) {
128 $title .= "/$action";
129 if (defined $file_name) {
130 $title .= " - " . $file_name;
131 if ($action eq "tree" && $file_name !~ m|/$|) {
138 $c->stash->{version} = $c->config->{version};
139 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
140 $c->stash->{title} = $title;
142 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
143 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
145 $c->stash->{project} = $project;
148 my %href_params = $self->feed_info($c);
149 $href_params{'-title'} ||= 'log';
151 foreach my $format qw(RSS Atom) {
152 my $type = lc($format);
155 title => "$project - $href_params{'-title'} - $format feed",
157 # XXX A bit hacky and could do with using gitweb::href() features
158 href => "?a=$type;p=$project",
159 type => "application/$type+xml"
163 # XXX This duplication also feels a bit awkward
164 title => "$project - $href_params{'-title'} - $format feed (no merges)",
165 href => "?a=$type;p=$project;opt=--no-merges",
166 type => "application/$type+xml"
172 title => $c->config->{sitename}." projects list",
173 href => '?a=project_index',
174 type => "text/plain; charset=utf-8"
177 title => $c->config->{sitename}." projects feeds",
179 type => "text/plain; charset=utf-8"
183 $c->stash->{favicon} = $c->config->{favicon};
188 logo_url => $c->config->{logo_url},
189 logo_label => $c->config->{logo_label},
190 logo_img => $c->config->{logo},
191 home_link => $c->config->{home_link},
192 home_link_str => $c->config->{home_link_str},
195 if(defined $project) {
197 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
198 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
199 || $c->req->param('h') || $c->req->param('hash')
205 # Formally git_footer_html
209 my $feed_class = 'rss_logo';
212 my $project = $c->req->param('project') || $c->req->param('p');
213 if(defined $project) {
214 (my $pstr = $project) =~ s[/?\.git$][];
215 my $descr = $c->model('Git')->project_info($project)->{description};
216 $c->stash->{project_description} = defined $descr
220 my %href_params = $self->feed_info($c);
222 $feed_class .= ' generic';
224 $href_params{'-title'} ||= 'log';
228 class => $feed_class,
229 title => "$href_params{'-title'} $_ feed",
230 href => "/?p=$project;a=\L$_",
237 class => $feed_class,
239 href => "/?a=$_->[0]",
241 }, [opml=>'OPML'],[project_index=>'TXT'],
246 # XXX This feels wrong here, should probably be refactored.
247 # returns hash to be passed to href to generate gitweb URL
248 # in -title key it returns description of link
252 my $format = shift || 'Atom';
253 my %res = (action => lc($format));
255 # feed links are possible only for project views
256 return unless $c->req->param('project');
258 # some views should link to OPML, or to generic project feed,
259 # or don't have specific feed yet (so they should use generic)
260 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
263 my $hash = $c->req->param('h') || $c->req->param('hash');
264 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
266 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
267 # from tag links; this also makes possible to detect branch links
268 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
269 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
273 # find log type for feed description (title)
275 my $file_name = $c->req->param('f') || $c->req->param('filename');
276 if (defined $file_name) {
277 $type = "history of $file_name";
278 $type .= "/" if $c->req->param('action') eq 'tree';
279 $type .= " on '$branch'" if (defined $branch);
281 $type = "log of $branch" if (defined $branch);
284 $res{-title} = $type;
285 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
286 $res{'file_name'} = $file_name;
292 Attempt to render a view, if needed.
296 sub end : ActionClass('RenderView') {}
304 This library is free software. You can redistribute it and/or modify
305 it under the same terms as Perl itself.
309 __PACKAGE__->meta->make_immutable;