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 my $capture = IO::Capture::Stdout->new();
38 my $action = gitweb::main($c);
43 my $output = join '', $capture->read;
44 $c->stash->{content} = $output
45 unless $c->stash->{content};
46 $c->stash->{template} = 'default.tt2';
49 sub index :Path :Args(0) {
50 my ( $self, $c ) = @_;
52 my $list = $c->model('Git')->list_projects;
54 die "No projects found";
58 searchtext => $c->req->param('searchtext') || '',
67 # Yes, this is hideous.
72 use Gitalist::Util qw(to_utf8);
73 use HTML::Entities qw(encode_entities);
74 use URI::Escape qw(uri_escape);
75 # Formally git_header_html
79 my $title = $c->config->{sitename};
81 my $project = $c->req->param('project') || $c->req->param('p');
82 my $action = $c->req->param('action') || $c->req->param('a');
83 my $file_name = $c->req->param('filename') || $c->req->param('f');
84 if(defined $project) {
85 $title .= " - " . to_utf8($project);
86 if (defined $action) {
88 if (defined $file_name) {
89 $title .= " - " . encode_entities($file_name);
90 if ($action eq "tree" && $file_name !~ m|/$|) {
97 $c->stash->{version} = $c->config->{version};
98 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
99 $c->stash->{title} = $title;
101 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
102 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
104 $c->stash->{project} = $project;
107 my %href_params = $self->feed_info($c);
108 $href_params{'-title'} ||= 'log';
110 foreach my $format qw(RSS Atom) {
111 my $type = lc($format);
114 title => "$project - $href_params{'-title'} - $format feed",
115 # XXX A bit hacky and could do with using gitweb::href() features
116 href => "?a=$type;p=$project",
117 type => "application/$type+xml"
120 # XXX This duplication also feels a bit awkward
121 title => "$project - $href_params{'-title'} - $format feed (no merges)",
122 href => "?a=$type;p=$project;opt=--no-merges",
123 type => "application/$type+xml"
129 title => $c->config->{sitename}." projects list",
130 href => '?a=project_index',
131 type => "text/plain; charset=utf-8"
134 title => $c->config->{sitename}." projects feeds",
136 type => "text/plain; charset=utf-8"
140 $c->stash->{favicon} = $c->config->{favicon};
145 logo_url => uri_escape($c->config->{logo_url}),
146 logo_label => encode_entities($c->config->{logo_label}),
147 logo_img => $c->config->{logo},
148 home_link => uri_escape($c->config->{home_link}),
149 home_link_str => $c->config->{home_link_str},
152 if(defined $project) {
154 search_text => $c->req->param('s') || $c->req->param('searchtext'),
155 search_hash => $c->req->param('hb') || $c->req->param('hashbase')
156 || $c->req->param('h') || $c->req->param('hash')
162 # Formally git_footer_html
166 my $feed_class = 'rss_logo';
169 my $project = $c->req->param('project') || $c->req->param('p');
170 if(defined $project) {
171 (my $pstr = $project) =~ s[/?\.git$][];
172 my $descr = $c->model('Git')->project_info($project)->{description};
173 $c->stash->{project_description} = defined $descr
174 ? encode_entities($descr)
177 my %href_params = $self->feed_info($c);
179 $feed_class .= ' generic';
181 $href_params{'-title'} ||= 'log';
185 class => $feed_class,
186 title => "$href_params{'-title'} $_ feed",
187 href => "/?p=$project;a=\L$_",
194 class => $feed_class,
196 href => "/?a=$_->[0]",
198 }, [opml=>'OPML'],[project_index=>'TXT'],
203 # XXX This feels wrong here, should probably be refactored.
204 # returns hash to be passed to href to generate gitweb URL
205 # in -title key it returns description of link
209 my $format = shift || 'Atom';
210 my %res = (action => lc($format));
212 # feed links are possible only for project views
213 return unless $c->req->param('project');
214 # some views should link to OPML, or to generic project feed,
215 # or don't have specific feed yet (so they should use generic)
216 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
219 my $hash = $c->req->param('h') || $c->req->param('hash');
220 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
221 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
222 # from tag links; this also makes possible to detect branch links
223 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
224 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
227 # find log type for feed description (title)
229 my $file_name = $c->req->param('f') || $c->req->param('filename');
230 if (defined $file_name) {
231 $type = "history of $file_name";
232 $type .= "/" if $c->req->param('action') eq 'tree';
233 $type .= " on '$branch'" if (defined $branch);
235 $type = "log of $branch" if (defined $branch);
238 $res{-title} = $type;
239 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
240 $res{'file_name'} = $file_name;
246 Attempt to render a view, if needed.
250 sub end : ActionClass('RenderView') {}
258 This library is free software. You can redistribute it and/or modify
259 it under the same terms as Perl itself.
263 __PACKAGE__->meta->make_immutable;