Split subincludes out into their own /fragment controllers.
Tomas Doran [Sun, 17 Jan 2010 19:59:37 +0000 (19:59 +0000)]
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..

Makefile.PL
lib/Gitalist/Controller/Fragment.pm [new file with mode: 0644]
lib/Gitalist/Controller/Fragment/Repository.pm [new file with mode: 0644]
lib/Gitalist/Controller/Repository.pm
lib/Gitalist/URIStructure/Repository.pm [new file with mode: 0644]
root/fragment/repository/heads.tt2 [new file with mode: 0644]
root/fragment/repository/shortlog.tt2 [new file with mode: 0644]
root/fragment/repository/summary.tt2 [new file with mode: 0644]
root/repository/heads.tt2
root/repository/shortlog.tt2
root/repository/summary.tt2

index baf71bb..71a80eb 100644 (file)
@@ -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';
diff --git a/lib/Gitalist/Controller/Fragment.pm b/lib/Gitalist/Controller/Fragment.pm
new file mode 100644 (file)
index 0000000..869c5b7
--- /dev/null
@@ -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;
diff --git a/lib/Gitalist/Controller/Fragment/Repository.pm b/lib/Gitalist/Controller/Fragment/Repository.pm
new file mode 100644 (file)
index 0000000..cee32d9
--- /dev/null
@@ -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;
index 2560a98..b79e51b 100644 (file)
@@ -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;
diff --git a/lib/Gitalist/URIStructure/Repository.pm b/lib/Gitalist/URIStructure/Repository.pm
new file mode 100644 (file)
index 0000000..120528e
--- /dev/null
@@ -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;
diff --git a/root/fragment/repository/heads.tt2 b/root/fragment/repository/heads.tt2
new file mode 100644 (file)
index 0000000..0eb77e7
--- /dev/null
@@ -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>
diff --git a/root/fragment/repository/shortlog.tt2 b/root/fragment/repository/shortlog.tt2
new file mode 100644 (file)
index 0000000..c1c7383
--- /dev/null
@@ -0,0 +1,7 @@
+<div class='content'>
+[%
+  INCLUDE '_log_pager.tt2';
+  INCLUDE '_shortlog.tt2';
+  INCLUDE '_log_pager.tt2';
+%]
+</div>
diff --git a/root/fragment/repository/summary.tt2 b/root/fragment/repository/summary.tt2
new file mode 100644 (file)
index 0000000..68fb0a8
--- /dev/null
@@ -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>
index 0eb77e7..36f5f87 100644 (file)
@@ -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) %]
\ No newline at end of file
index c1c7383..7bf52b4 100644 (file)
@@ -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) %]
index 26fe59d..45d08d4 100644 (file)
@@ -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>