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 ) = @_;
77 my $git = $c->model('Git');
79 my $filename = $req->param('f') || $req->param('filename');
80 my $hash = $req->param('hb') || $req->param('hashbase')
81 || $git->get_head_hash($req->param('p') || $req->param('project'));
82 my $filehash = $git->get_hash_by_path($hash, $filename, 'blob');
84 my $blob = $git->run_cmd('cat-file' => blob => $filehash);
87 blob => encode_entities($blob),
95 # Yes, this is hideous.
100 use Gitalist::Util qw(to_utf8);
101 use HTML::Entities qw(encode_entities);
102 use URI::Escape qw(uri_escape);
103 # Formally git_header_html
107 my $title = $c->config->{sitename};
109 my $project = $c->req->param('project') || $c->req->param('p');
110 my $action = $c->req->param('action') || $c->req->param('a');
111 my $file_name = $c->req->param('filename') || $c->req->param('f');
112 if(defined $project) {
113 $title .= " - " . to_utf8($project);
114 if (defined $action) {
115 $title .= "/$action";
116 if (defined $file_name) {
117 $title .= " - " . encode_entities($file_name);
118 if ($action eq "tree" && $file_name !~ m|/$|) {
125 $c->stash->{version} = $c->config->{version};
126 $c->stash->{git_version} = $c->model('Git')->run_cmd('--version');
127 $c->stash->{title} = $title;
129 #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url);
130 $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css';
132 $c->stash->{project} = $project;
135 my %href_params = $self->feed_info($c);
136 $href_params{'-title'} ||= 'log';
138 foreach my $format qw(RSS Atom) {
139 my $type = lc($format);
142 title => "$project - $href_params{'-title'} - $format feed",
143 # XXX A bit hacky and could do with using gitweb::href() features
144 href => "?a=$type;p=$project",
145 type => "application/$type+xml"
148 # XXX This duplication also feels a bit awkward
149 title => "$project - $href_params{'-title'} - $format feed (no merges)",
150 href => "?a=$type;p=$project;opt=--no-merges",
151 type => "application/$type+xml"
157 title => $c->config->{sitename}." projects list",
158 href => '?a=project_index',
159 type => "text/plain; charset=utf-8"
162 title => $c->config->{sitename}." projects feeds",
164 type => "text/plain; charset=utf-8"
168 $c->stash->{favicon} = $c->config->{favicon};
173 logo_url => uri_escape($c->config->{logo_url}),
174 logo_label => encode_entities($c->config->{logo_label}),
175 logo_img => $c->config->{logo},
176 home_link => uri_escape($c->config->{home_link}),
177 home_link_str => $c->config->{home_link_str},
180 if(defined $project) {
182 search_text => ( $c->req->param('s') || $c->req->param('searchtext') ),
183 search_hash => ( $c->req->param('hb') || $c->req->param('hashbase')
184 || $c->req->param('h') || $c->req->param('hash')
190 # Formally git_footer_html
194 my $feed_class = 'rss_logo';
197 my $project = $c->req->param('project') || $c->req->param('p');
198 if(defined $project) {
199 (my $pstr = $project) =~ s[/?\.git$][];
200 my $descr = $c->model('Git')->project_info($project)->{description};
201 $c->stash->{project_description} = defined $descr
202 ? encode_entities($descr)
205 my %href_params = $self->feed_info($c);
207 $feed_class .= ' generic';
209 $href_params{'-title'} ||= 'log';
213 class => $feed_class,
214 title => "$href_params{'-title'} $_ feed",
215 href => "/?p=$project;a=\L$_",
222 class => $feed_class,
224 href => "/?a=$_->[0]",
226 }, [opml=>'OPML'],[project_index=>'TXT'],
231 # XXX This feels wrong here, should probably be refactored.
232 # returns hash to be passed to href to generate gitweb URL
233 # in -title key it returns description of link
237 my $format = shift || 'Atom';
238 my %res = (action => lc($format));
240 # feed links are possible only for project views
241 return unless $c->req->param('project');
242 # some views should link to OPML, or to generic project feed,
243 # or don't have specific feed yet (so they should use generic)
244 return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x;
247 my $hash = $c->req->param('h') || $c->req->param('hash');
248 my $hash_base = $c->req->param('hb') || $c->req->param('hashbase');
249 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
250 # from tag links; this also makes possible to detect branch links
251 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
252 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
255 # find log type for feed description (title)
257 my $file_name = $c->req->param('f') || $c->req->param('filename');
258 if (defined $file_name) {
259 $type = "history of $file_name";
260 $type .= "/" if $c->req->param('action') eq 'tree';
261 $type .= " on '$branch'" if (defined $branch);
263 $type = "log of $branch" if (defined $branch);
266 $res{-title} = $type;
267 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
268 $res{'file_name'} = $file_name;
274 Attempt to render a view, if needed.
278 sub end : ActionClass('RenderView') {}
286 This library is free software. You can redistribute it and/or modify
287 it under the same terms as Perl itself.
291 __PACKAGE__->meta->make_immutable;