Skip to content

Commit

Permalink
Split subincludes out into their own /fragment controllers.
Browse files Browse the repository at this point in the history
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..
  • Loading branch information
bobtfish committed Jan 17, 2010
1 parent 103b1b9 commit ecb0ebe
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -58,7 +58,7 @@ requires 'Catalyst::Action::RenderView';
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';
Expand Down
10 changes: 10 additions & 0 deletions lib/Gitalist/Controller/Fragment.pm
@@ -0,0 +1,10 @@
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;
33 changes: 33 additions & 0 deletions lib/Gitalist/Controller/Fragment/Repository.pm
@@ -0,0 +1,33 @@
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;
41 changes: 2 additions & 39 deletions lib/Gitalist/Controller/Repository.pm
@@ -1,47 +1,10 @@
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;
31 changes: 31 additions & 0 deletions lib/Gitalist/URIStructure/Repository.pm
@@ -0,0 +1,31 @@
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;
33 changes: 33 additions & 0 deletions root/fragment/repository/heads.tt2
@@ -0,0 +1,33 @@
<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>
7 changes: 7 additions & 0 deletions root/fragment/repository/shortlog.tt2
@@ -0,0 +1,7 @@
<div class='content'>
[%
INCLUDE '_log_pager.tt2';
INCLUDE '_shortlog.tt2';
INCLUDE '_log_pager.tt2';
%]
</div>
5 changes: 5 additions & 0 deletions root/fragment/repository/summary.tt2
@@ -0,0 +1,5 @@
<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>
35 changes: 2 additions & 33 deletions root/repository/heads.tt2
@@ -1,33 +1,2 @@
<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) %]
9 changes: 2 additions & 7 deletions root/repository/shortlog.tt2
@@ -1,7 +1,2 @@
<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) %]
10 changes: 3 additions & 7 deletions root/repository/summary.tt2
@@ -1,15 +1,11 @@
[% 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>

0 comments on commit ecb0ebe

Please sign in to comment.