requires 'Catalyst::Plugin::SubRequest';
requires 'Catalyst::Action::RenderView';
requires 'Catalyst::Component::InstancePerContext';
+requires 'Catalyst::Controller::ActionRole';
requires 'Catalyst::View::Component::SubInclude' => '0.07';
requires 'Catalyst::View::TT';
requires 'Try::Tiny';
--- /dev/null
+package Gitalist::ActionRole::FilenameArgs;
+use Moose::Role;
+use namespace::autoclean;
+
+requires 'execute';
+
+before 'execute' => sub {
+ my ($self, $controller, $c, @args) = @_;
+ $c->stash->{filename} = join('/', @args) || '';
+};
+
+1;
+
--- /dev/null
+package Gitalist::Controller;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller::ActionRole' }
+
+__PACKAGE__->meta->make_immutable;
use Moose;
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
with 'Gitalist::URIStructure::Commit';
sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
use Moose;
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
sub base : Chained('/base') PathPart('fragment') CaptureArgs(0) {
my ($self, $c) = @_;
use Moose;
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
with 'Gitalist::URIStructure::Commit';
sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
};
after tree => sub {
- my ( $self, $c, @fn ) = @_;
+ my ( $self, $c ) = @_;
my $repository = $c->stash->{Repository};
my $commit = $c->stash->{Commit};
- my $filename = join('/', @fn);
- my $tree = $filename
- ? $repository->get_object($repository->hash_by_path($commit->sha1, $filename))
+ my $tree = $c->stash->{filename}
+ ? $repository->get_object($repository->hash_by_path($commit->sha1, $c->stash->{filename}))
: $repository->get_object($commit->tree_sha1)
;
$c->stash(
tree => $tree,
tree_list => [$repository->list_tree($tree->sha1)],
- path => $filename,
+ path => $c->stash->{filename}, # FIXME?
);
};
after blame => sub {
- my($self, $c, @fn) = @_;
+ my($self, $c) = @_;
my $repository = $c->stash->{Repository};
- my $filename = join('/', @fn);
# WTF?
- my $blame = $c->stash->{Commit}->blame($filename, $c->stash->{Commit}->sha1);
+ my $blame = $c->stash->{Commit}->blame($c->stash->{filename}, $c->stash->{Commit}->sha1);
$c->stash(
blame => $blame,
- filename => $filename,
-
# XXX Hack hack hack, see View::SyntaxHighlight
- language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
+ language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
blob => join("\n", map $_->{line}, @$blame),
);
=cut
after blob => sub {
- my ( $self, $c, @fn ) = @_;
+ my ( $self, $c ) = @_;
- my $filename = join('/', @fn);
my $repository = $c->stash->{Repository};
my $h =
- $repository->hash_by_path($c->stash->{Commit}->sha1, $filename)
+ $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,
- filename => $filename,
# XXX Hack hack hack, see View::SyntaxHighlight
- language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
+ language => ($c->stash->{filename} =~ /\.p[lm]$/i ? 'Perl' : ''),
);
$c->forward('View::SyntaxHighlight')
use Moose;
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
with 'Gitalist::URIStructure::Repository';
sub base : Chained('/fragment/base') PathPart('') CaptureArgs(0) {}
use Moose;
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
with 'Gitalist::URIStructure::Repository';
sub base : Chained('/base') PathPart('') CaptureArgs(0) {}
use namespace::autoclean;
-BEGIN { extends 'Catalyst::Controller' }
+BEGIN { extends 'Gitalist::Controller' }
__PACKAGE__->config->{namespace} = '';
package Gitalist::URIStructure::Commit;
use MooseX::MethodAttributes::Role;
+use Moose::Autobox;
use namespace::autoclean;
requires 'base';
sub diff_plain : Chained('diff') PathPart('plain') Args(0) {}
-sub tree : Chained('find') Args() {}
+sub commit : Chained('find') PathPart('') Args(0) {}
-sub commit : Chained('find') PathPart('') {}
+sub tree : Chained('find') Does('FilenameArgs') Args() {}
-sub blob : Chained('find') Args() {}
+sub blob_plain : Chained('find') Does('FilenameArgs') Args() {}
-sub blame : Chained('find') Args() {}
+sub blob : Chained('find') Does('FilenameArgs') Args() {}
-sub history : Chained('find') Args() {}
+sub blame : Chained('find') Does('FilenameArgs') Args() {}
-sub raw : Chained('find') Args() {}
+sub history : Chained('find') Does('FilenameArgs') Args() {}
+
+sub raw : Chained('find') Does('FilenameArgs') Args() {}
+
+sub shortlog : Chained('find') Does('FilenameArgs') Args() {}
1;
<!-- This should probably be a real LIst -->
<a href="[% c.uri_for_action('/repository/summary', [c.req.captures.0]) %]">summary</a> •
<a href="[% c.uri_for_action('/repository/shortlog', [c.req.captures.0]) %]">shortlog</a> •
- <a href="[% c.uri_for_action('/repository/log', [c.req.captures.0]) %]">log</a> •
+ <a href="[% c.uri_for_action('/repository/log', [c.req.captures.0]) %]">log</a>
[% IF Commit %]
+ §
<a href="[% c.uri_for_action('/commit/commit', [c.req.captures.0, Commit.sha1]) %]">commit</a> •
<a href="[% c.uri_for_action('/commit/diff_fancy', [c.req.captures.0, Commit.sha1]) %]">commitdiff</a> •
<a href="[% c.uri_for_action('/commit/tree', [c.req.captures.0, Commit.sha1]) %]">tree</a>
[% END %]
- [% IF filename && Commit %]•[% END %]
[% IF filename %]
§
- <a href="[% c.uri_for('blob', {h=object.sha1,f=filename}) %]">blob</a> •
- <a href="[% c.uri_for('blob_plain', {h=object.sha1,f=filename}) %]">raw</a> •
- <a href="[% c.uri_for('blame', {h=object.sha1,f=filename}) %]">blame</a> •
- <a href="[% c.uri_for('shortlog', {h=object.sha1,f=filename}) %]">history</a> •
+ <a href="[% c.uri_for_action('/commit/blob', [c.req.captures.0, Commit.sha1], filename) %]">blob</a> •
+ <a href="[% c.uri_for_action('/commit/blob_plain', [c.req.captures.0, Commit.sha1], filename) %]">raw</a> •
+ <a href="[% c.uri_for_action('/commit/blame', [c.req.captures.0, Commit.sha1], filename) %]">blame</a> •
+ <a href="[% c.uri_for_action('/commit/shortlog', [c.req.captures.0, Commit.sha1], filename) %]">history</a> •
<a href="[% c.uri_for(c.controller.action_for('commit'), [c.req.captures.0, Repository.head_hash]) %]">HEAD</a>
[% END %]
<div class='chroma-hash'>[% INCLUDE 'inc/chroma_hash.tt2' sha1 = object.sha1 %]</div>