Move the Commit code to URIStructure, add templates for tree.
Tomas Doran [Sun, 17 Jan 2010 21:33:14 +0000 (21:33 +0000)]
None of the actual functionality is implemented yet

lib/Gitalist/Controller/Commit.pm
lib/Gitalist/Controller/Fragment/Commit.pm [new file with mode: 0644]
lib/Gitalist/URIStructure/Commit.pm [new file with mode: 0644]
root/commit/tree.tt2 [new file with mode: 0644]
root/fragment/commit/tree.tt2 [new file with mode: 0644]

index 8eb7790..0290a51 100644 (file)
@@ -1,24 +1,11 @@
 package Gitalist::Controller::Commit;
 
 use Moose;
-use Moose::Autobox;
-use Try::Tiny qw/try catch/;
 use namespace::autoclean;
 
 BEGIN { extends 'Catalyst::Controller' }
+with 'Gitalist::URIStructure::Commit';
 
 sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
 
-sub find : Chained('base') PathPart('') CaptureArgs(1) {
-    my ($self, $c, $sha1part) = @_;
-    $c->stash->{Commit} = $c->stash->{Repository}->get_object($sha1part)
-        or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
-}
-
-sub diff : Chained('find') Args(0) {}
-
-sub tree : Chained('find') Args(0) {}
-
-sub commit : Chained('find') Args(0) {}
-
 __PACKAGE__->meta->make_immutable;
diff --git a/lib/Gitalist/Controller/Fragment/Commit.pm b/lib/Gitalist/Controller/Fragment/Commit.pm
new file mode 100644 (file)
index 0000000..37398f7
--- /dev/null
@@ -0,0 +1,10 @@
+package Gitalist::Controller::Fragment::Commit;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+with 'Gitalist::URIStructure::Commit';
+
+sub base : Chained('/fragment/repository/find') PathPart('') CaptureArgs(0) {}
+
+__PACKAGE__->meta->make_immutable;
diff --git a/lib/Gitalist/URIStructure/Commit.pm b/lib/Gitalist/URIStructure/Commit.pm
new file mode 100644 (file)
index 0000000..91d1405
--- /dev/null
@@ -0,0 +1,26 @@
+package Gitalist::URIStructure::Commit;
+use MooseX::MethodAttributes::Role;
+use namespace::autoclean;
+
+requires 'base';
+
+after 'base' => sub {
+    my ($self, $c) = @_;
+    confess("No repository in the stash")
+        unless $c->stash->{Repository};
+};
+
+sub find : Chained('base') PathPart('') CaptureArgs(1) {
+    my ($self, $c, $sha1part) = @_;
+    # FIXME - Should not be here!
+    $c->stash->{Commit} = $c->stash->{Repository}->get_object($sha1part)
+        or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
+}
+
+sub diff : Chained('find') Args(0) {}
+
+sub tree : Chained('find') Args(0) {}
+
+sub commit : Chained('find') Args(0) {}
+
+1;
diff --git a/root/commit/tree.tt2 b/root/commit/tree.tt2
new file mode 100644 (file)
index 0000000..be27877
--- /dev/null
@@ -0,0 +1,15 @@
+[% INCLUDE 'nav/actions.tt2' object = commit %]
+
+<div class='content'>
+  <div class='commit-message'>
+  [% short_cmt(commit.comment) | html %] ...
+  </div>
+
+  [%
+    IF path;
+      INCLUDE 'nav/path.tt2' filename = path, head = commit;
+    END;
+
+    subinclude('/fragment/commit/tree', c.req.captures);
+  %]
+</div>
diff --git a/root/fragment/commit/tree.tt2 b/root/fragment/commit/tree.tt2
new file mode 100644 (file)
index 0000000..6a96cda
--- /dev/null
@@ -0,0 +1,39 @@
+<table class='tree listing'>
+ <thead>
+  <tr>
+   <th>mode</th>
+   <th>file</th>
+   <th>actions</th>
+  </tr>
+ </thead>
+ <tfoot>
+  <tr>
+   <td>mode</td>
+   <td>file</td>
+   <td>actions</td>
+  </tr>
+ </tfoot>
+
+ <tbody>
+  [% FOREACH item IN tree_list %]
+  <tr>
+   <td class='file-mode'>[% item.modestr %]</td>
+   [% theact = item.type == 'tree' ? 'tree' : 'blob' -%]
+   [% fullpath = path ? path _ '/' _ item.file : item.file %]
+   <td class='file-name'>
+    <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% item.file %]</a>
+   </td>
+   <td class='action-list'>
+     <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% theact %]</a>
+         [% IF item.type == 'blob' %]
+         <a href="[% c.uri_for('blame', {h=commit.sha1, hb=commit.sha1, f=fullpath}) %]">blame</a>
+         [% END %]
+     <a href="[% c.uri_for('history', {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">history</a>
+     [% IF item.type == 'blob' %]
+     <a href="[% c.uri_for('raw', {hb=commit.sha1, f=fullpath}) %]">raw</a>
+     [% END %]
+   </td>
+  </tr>
+  [% END %]
+ </tbody>
+</table>