sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
+sub blob_plain : Chained('find_blob') Does('FilenameArgs') Args() {
+ my ($self, $c) = @_;
+
+ $c->response->content_type('text/plain; charset=utf-8');
+ $c->response->body(delete $c->stash->{blob});
+}
+
+=head2 snapshot
+
+Provides a snapshot of a given commit.
+
+=cut
+
+sub snapshot : Chained('base') Args() {
+ my ($self, $c, $format) = @_;
+ $format ||= 'tgz';
+ my @snap = $c->stash->{Repository}->snapshot(
+ sha1 => $c->stash->{Commit}->sha1,
+ format => $format
+ );
+ $c->response->status(200);
+ $c->response->headers->header( 'Content-Disposition' =>
+ "attachment; filename=$snap[0]");
+ $c->response->body($snap[1]);
+}
+
__PACKAGE__->meta->make_immutable;
after blob => sub {
my ( $self, $c ) = @_;
-
- my $repository = $c->stash->{Repository};
- my $h =
- $repository->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename})
- || die "No file or sha1 provided.";
- my $blob = $repository->get_object($h);
$c->stash(
- blob => $blob->content,
# XXX Hack hack hack, see View::SyntaxHighlight
language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
);
package Gitalist::Controller::Repository;
use Moose;
+use XML::Atom::Feed;
+use XML::Atom::Entry;
+use XML::RSS;
+use Sys::Hostname qw/hostname/;
use namespace::autoclean;
BEGIN { extends 'Gitalist::Controller' }
sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
+=head2 atom
+
+Provides an atom feed for a given repository.
+
+=cut
+
+sub atom : Chained('find') Args(0) {
+ my($self, $c) = @_;
+
+ my $feed = XML::Atom::Feed->new;
+
+ my $host = lc hostname();
+ $feed->title($host . ' - ' . Gitalist->config->{name});
+ $feed->updated(~~DateTime->now);
+
+ my $repository = $c->stash->{Repository};
+ my %logargs = (
+ sha1 => $repository->head_hash,
+ count => Gitalist->config->{paging}{log} || 25,
+ );
+
+ my $mk_title = $c->stash->{short_cmt};
+ for my $commit ($repository->list_revs(%logargs)) {
+ my $entry = XML::Atom::Entry->new;
+ $entry->title( $mk_title->($commit->comment) );
+ $entry->id($c->uri_for_action('/commit/commit', [$repository->name, $commit->sha1]));
+ # XXX FIXME Needs work ...
+ $entry->content($commit->comment);
+ $feed->add_entry($entry);
+ }
+
+ $c->response->body($feed->as_xml);
+ $c->response->content_type('application/atom+xml');
+}
+
+=head2 rss
+
+Provides an RSS feed for a given repository.
+
+=cut
+
+sub rss : Chained('find') Args(0) {
+ my ($self, $c) = @_;
+
+ my $repository = $c->stash->{Repository};
+
+ my $rss = XML::RSS->new(version => '2.0');
+ $rss->channel(
+ title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
+ link => $c->uri_for('summary', {p=>$repository->name}),
+ language => 'en',
+ description => $repository->description,
+ pubDate => DateTime->now,
+ lastBuildDate => DateTime->now,
+ );
+
+ my %logargs = (
+ sha1 => $repository->head_hash,
+ count => Gitalist->config->{paging}{log} || 25,
+# ($c->req->param('f') ? (file => $c->req->param('f')) : ())
+ );
+ my $mk_title = $c->stash->{short_cmt};
+ for my $commit ($repository->list_revs(%logargs)) {
+ # XXX FIXME Needs work ....
+ $rss->add_item(
+ title => $mk_title->($commit->comment),
+ permaLink => $c->uri_for_action('/commit/commit', [$repository->name, $commit->sha1]),
+ description => $commit->comment,
+ );
+ }
+
+ $c->response->body($rss->as_string);
+ $c->response->content_type('application/rss+xml');
+}
+
__PACKAGE__->meta->make_immutable;
use Moose;
use Moose::Autobox;
-use Sys::Hostname ();
-use XML::Atom::Feed;
-use XML::Atom::Entry;
-use XML::RSS;
+use Sys::Hostname qw/hostname/;
use XML::OPML::SimpleGen;
use Gitalist::Utils qw/ age_string /;
return $blob, $repository->get_object($hb), $filename;
}
-
-
-=head2 blob_plain
-
-The plain text version of blob, where file is rendered as is.
-
-=cut
-
-sub blob_plain : Chained('base') Args(0) {
- my($self, $c) = @_;
-
- my($blob) = $self->_blob_objs($c);
- $c->response->content_type('text/plain; charset=utf-8');
- $c->response->body($blob->content);
- $c->response->status(200);
-}
-
=head2 blobdiff_plain
The plain text version of blobdiff.
=cut
-sub search_help : Chained('base') Args(0) {
- my ($self, $c) = @_;
- $c->stash(template => 'search_help.tt2');
-}
-
-=head2 atom
-
-Provides an atom feed for a given repository.
-
-=cut
-
-sub atom : Chained('base') Args(0) {
- my($self, $c) = @_;
-
- my $feed = XML::Atom::Feed->new;
-
- my $host = lc Sys::Hostname::hostname();
- $feed->title($host . ' - ' . Gitalist->config->{name});
- $feed->updated(~~DateTime->now);
-
- my $repository = $c->stash->{Repository};
- my %logargs = (
- sha1 => $repository->head_hash,
- count => Gitalist->config->{paging}{log} || 25,
- ($c->req->param('f') ? (file => $c->req->param('f')) : ())
- );
-
- my $mk_title = $c->stash->{short_cmt};
- for my $commit ($repository->list_revs(%logargs)) {
- my $entry = XML::Atom::Entry->new;
- $entry->title( $mk_title->($commit->comment) );
- $entry->id($c->uri_for('commit', {h=>$commit->sha1}));
- # XXX Needs work ...
- $entry->content($commit->comment);
- $feed->add_entry($entry);
- }
-
- $c->response->body($feed->as_xml);
- $c->response->content_type('application/atom+xml');
- $c->response->status(200);
-}
-
-=head2 rss
-
-Provides an RSS feed for a given repository.
-
-=cut
-
-sub rss : Chained('base') Args(0) {
- my ($self, $c) = @_;
-
- my $repository = $c->stash->{Repository};
-
- my $rss = XML::RSS->new(version => '2.0');
- $rss->channel(
- title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name},
- link => $c->uri_for('summary', {p=>$repository->name}),
- language => 'en',
- description => $repository->description,
- pubDate => DateTime->now,
- lastBuildDate => DateTime->now,
- );
-
- my %logargs = (
- sha1 => $repository->head_hash,
- count => Gitalist->config->{paging}{log} || 25,
- ($c->req->param('f') ? (file => $c->req->param('f')) : ())
- );
- my $mk_title = $c->stash->{short_cmt};
- for my $commit ($repository->list_revs(%logargs)) {
- # XXX Needs work ....
- $rss->add_item(
- title => $mk_title->($commit->comment),
- permaLink => $c->uri_for(commit => {h=>$commit->sha1}),
- description => $commit->comment,
- );
- }
-
- $c->response->body($rss->as_string);
- $c->response->content_type('application/rss+xml');
- $c->response->status(200);
-}
+sub search_help : Chained('base') Args(0) {}
sub opml : Chained('base') Args(0) {
my($self, $c) = @_;
my $opml = XML::OPML::SimpleGen->new();
- $opml->head(title => lc(Sys::Hostname::hostname()) . ' - ' . Gitalist->config->{name});
+ $opml->head(title => lc(hostname()) . ' - ' . Gitalist->config->{name});
my @list = @{ $c->model()->repositories };
die 'No repositories found in '. $c->model->repo_dir
$c->response->status(200);
}
-=head2 snapshot
-
-Provides a snapshot of a given commit.
-
-=cut
-
-sub snapshot : Chained('base') Args(0) {
- my ($self, $c) = @_;
- my $format = $c->req->param('sf') || 'tgz';
- die unless $format;
- my $sha1 = $c->req->param('h') || $self->_get_object($c)->sha1;
- my @snap = $c->stash->{Repository}->snapshot(
- sha1 => $sha1,
- format => $format
- );
- $c->response->status(200);
- $c->response->headers->header( 'Content-Disposition' =>
- "attachment; filename=$snap[0]");
- $c->response->body($snap[1]);
-}
-
-
sub base : Chained('/root') PathPart('') CaptureArgs(0) {
my($self, $c) = @_;
sub tree : Chained('find') Does('FilenameArgs') Args() {}
-sub blob_plain : Chained('find') Does('FilenameArgs') Args() {}
+sub find_blob : Chained('find') PathPart('') CaptureArgs(0) {
+ my ($self, $c) = @_;
+ # FIXME - Eugh!
+ my $h = $c->stash->{Repository}->hash_by_path($c->stash->{Commit}->sha1, $c->stash->{filename})
+ || die "No file or sha1 provided.";
+ $c->stash(blob => $c->stash->{Repository}->get_object($h)->content);
+}
-sub blob : Chained('find') Does('FilenameArgs') Args() {}
+sub blob : Chained('find_blob') Does('FilenameArgs') Args() {}
sub blame : Chained('find') Does('FilenameArgs') Args() {}