This moves most of the logic round, and adds a role which I called ::URIStructure::XX
as that is what it was conceptually for. However as it seems to have the repos lookup (and as we need to lookup the repos to work out if it exists in the top level for 404) - it's no longer so clean at all..
I think that I'm going to add a ->has_project method to the model which I can
call for the 404 in the wrapped page, then the actual 'get project' logic can
just be in the /fragment code and the conceptual purity of 'URIStructure' is restored somewhat..
requires 'Catalyst::Component::InstancePerContext';
requires 'Catalyst::View::Component::SubInclude' => '0.07';
requires 'Catalyst::View::TT';
-
+requires 'Try::Tiny';
requires 'Template';
requires 'Template::Provider::Encoding';
requires 'Template::Plugin::Cycle';
--- /dev/null
+package Gitalist::Controller::Fragment;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+sub base : Chained('/root') PathPart('fragment') CaptureArgs(0) {}
+
+__PACKAGE__->meta->make_immutable;
--- /dev/null
+package Gitalist::Controller::Fragment::Repository;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+with 'Gitalist::URIStructure::Repository';
+
+sub base : Chained('/fragment/base') PathPart('') CaptureArgs(0) {
+ my ($self, $c) = @_;
+ $c->stash(no_wrapper => 1);
+}
+
+after shortlog => sub {
+ my ($self, $c) = @_;
+ $c->forward('/shortlog');
+};
+
+after heads => sub {
+ my ($self, $c) = @_;
+ $c->stash(
+ heads => $c->stash->{Repository}->heads,
+ );
+};
+
+after log => sub {
+ my ($self, $c) = @_;
+ $c->stash(
+ template => 'log.tt2',
+ );
+ $c->forward('/log');
+};
+
+__PACKAGE__->meta->make_immutable;
package Gitalist::Controller::Repository;
-
use Moose;
-use Moose::Autobox;
-use Try::Tiny qw/try catch/;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
+with 'Gitalist::URIStructure::Repository';
-sub base : Chained('/root') PathPart('') CaptureArgs(0) {
- my ($self, $c) = @_;
- $c->stash(_do_not_mangle_uri_for => 1);
-}
-
-sub find : Chained('base') PathPart('') CaptureArgs(1) {
- my ($self, $c, $repository) = @_;
- try {
- $c->stash(Repository => $c->model()->get_repository($repository));
- }
- catch {
- $c->detach('/error_404');
- };
-}
-
-sub summary : Chained('find') PathPart('') Args(0) {}
-
-sub shortlog : Chained('find') Args(0) {
- my ($self, $c) = @_;
- $c->stash(no_wrapper => 1);
- $c->forward('/shortlog');
-}
-
-sub heads : Chained('find') Args(0) {
- my ($self, $c) = @_;
- $c->stash(
- no_wrapper => 1,
- heads => $c->stash->{Repository}->heads,
- );
-}
-
-sub log : Chained('find') Args(0) {
- my ($self, $c) = @_;
- $c->stash(template => 'log.tt2');
- $c->forward('/log');
-}
+sub base : Chained('/root') PathPart('') CaptureArgs(0) {}
__PACKAGE__->meta->make_immutable;
--- /dev/null
+package Gitalist::URIStructure::Repository;
+use MooseX::MethodAttributes::Role;
+use Try::Tiny qw/try catch/;
+use namespace::autoclean;
+
+requires 'base';
+
+after 'base' => sub {
+ my ($self, $c) = @_;
+ $c->stash(_do_not_mangle_uri_for => 1);
+};
+
+sub find : Chained('base') PathPart('') CaptureArgs(1) {
+ my ($self, $c, $repository) = @_;
+ try {
+ $c->stash(Repository => $c->model()->get_repository($repository));
+ }
+ catch {
+ $c->detach('/error_404');
+ };
+}
+
+sub summary : Chained('find') PathPart('') Args(0) {}
+
+sub shortlog : Chained('find') Args(0) {}
+
+sub heads : Chained('find') Args(0) {}
+
+sub log : Chained('find') Args(0) {}
+
+1;
--- /dev/null
+<table class='[% action %] listing'>
+ <thead>
+ <tr>
+ <th>HEAD</th>
+ <th>age</th>
+ <th>branch</th>
+ <th>actions</th>
+ </tr>
+ </thead>
+ <tfoot>
+ <tr>
+ <td>HEAD</td>
+ <td>age</td>
+ <td>branch</td>
+ <td>actions</td>
+ </tr>
+ </tfoot>
+
+ <tbody>
+ [% FOREACH head IN heads %]
+ <tr>
+ <td class='sha1' title='[% head.sha1 %]'>[% INCLUDE '_chroma_hash.tt2' sha1 = head.sha1.substr(0,7) %]</td>
+ <td class='time-since' title='[% head.last_change %]'>[% time_since(head.last_change) %]</td>
+ <td class='head[% head.sha1 == HEAD ? ' current' : '' %]'>[% head.name %]</td>
+ <td class='action-list'>
+ <a href="[% c.uri_for("shortlog", {h='refs/heads/' _ head.name}) %]">shortlog</a>
+ <a href="[% c.uri_for("log", {h='refs/heads/' _ head.name}) %]">log</a>
+ <a href="[% c.uri_for("tree", {h='refs/heads/' _ head.name, hb=head.name}) %]">tree</a>
+ </td>
+ </tr>
+ [% END %]
+ </tbody>
+</table>
--- /dev/null
+<div class='content'>
+[%
+ INCLUDE '_log_pager.tt2';
+ INCLUDE '_shortlog.tt2';
+ INCLUDE '_log_pager.tt2';
+%]
+</div>
--- /dev/null
+<dl>
+ <dt>description</dt><dd>[% Repository.description %]</dd>
+ <dt>owner</dt><dd>[% Repository.owner %]</dd>
+ <dt>last change</dt><dd>[% Repository.last_change %]</dd>
+</dl>
-<table class='[% action %] listing'>
- <thead>
- <tr>
- <th>HEAD</th>
- <th>age</th>
- <th>branch</th>
- <th>actions</th>
- </tr>
- </thead>
- <tfoot>
- <tr>
- <td>HEAD</td>
- <td>age</td>
- <td>branch</td>
- <td>actions</td>
- </tr>
- </tfoot>
-
- <tbody>
- [% FOREACH head IN heads %]
- <tr>
- <td class='sha1' title='[% head.sha1 %]'>[% INCLUDE '_chroma_hash.tt2' sha1 = head.sha1.substr(0,7) %]</td>
- <td class='time-since' title='[% head.last_change %]'>[% time_since(head.last_change) %]</td>
- <td class='head[% head.sha1 == HEAD ? ' current' : '' %]'>[% head.name %]</td>
- <td class='action-list'>
- <a href="[% c.uri_for("shortlog", {h='refs/heads/' _ head.name}) %]">shortlog</a>
- <a href="[% c.uri_for("log", {h='refs/heads/' _ head.name}) %]">log</a>
- <a href="[% c.uri_for("tree", {h='refs/heads/' _ head.name, hb=head.name}) %]">tree</a>
- </td>
- </tr>
- [% END %]
- </tbody>
-</table>
+[% INCLUDE 'nav/actions.tt2' object = commit %]
+[% subinclude('/fragment/repository/heads', c.req.captures) %]
\ No newline at end of file
-<div class='content'>
-[%
- INCLUDE '_log_pager.tt2';
- INCLUDE '_shortlog.tt2';
- INCLUDE '_log_pager.tt2';
-%]
-</div>
+[% INCLUDE 'nav/actions.tt2' object = commit %]
+[% subinclude('/fragment/repository/shortlog', c.req.captures) %]
[% PROCESS 'nav/actions.tt2' object = commit %]
<div class='summary content'>
- <dl>
- <dt>description</dt><dd>[% Repository.description %]</dd>
- <dt>owner</dt><dd>[% Repository.owner %]</dd>
- <dt>last change</dt><dd>[% Repository.last_change %]</dd>
- </dl>
+ [% subinclude('/fragment/repository/summary', c.req.captures) %]
<h2><a href='[% c.uri_for(c.controller.action_for('shortlog'), c.req.captures) %]'>shortlog</a></h2>
- [% subinclude('/repository/shortlog', c.req.captures) %]
+ [% subinclude('/fragment/repository/shortlog', c.req.captures) %]
<h2><a href='[% c.uri_for(c.controller.action_for('heads'), c.req.captures) %]'>branches</a></h2>
- [% subinclude('/repository/heads', c.req.captures) %]
+ [% subinclude('/fragment/repository/heads', c.req.captures) %]
</div>