Make the tree fragment work as expected so that you can browse trees again
Tomas Doran [Mon, 18 Jan 2010 00:13:33 +0000 (00:13 +0000)]
lib/Gitalist/URIStructure/Commit.pm
lib/Gitalist/View/Default.pm
root/fragment/commit/tree.tt2

index e59e64c..0140681 100644 (file)
@@ -27,4 +27,12 @@ sub tree : Chained('find') Args() {}
 
 sub commit : Chained('find') PathPart('') {}
 
+sub blob : Chained('find') Args() {}
+
+sub blame : Chained('find') Args() {}
+
+sub history : Chained('find') Args() {}
+
+sub raw : Chained('find') Args() {}
+
 1;
index 4bc7be6..443704b 100644 (file)
@@ -1,5 +1,6 @@
 package Gitalist::View::Default;
 use Moose;
+use Moose::Autobox;
 use namespace::autoclean;
 
 extends 'Catalyst::View::TT';
@@ -13,6 +14,13 @@ __PACKAGE__->config(
   subinclude_plugin => 'SubRequest',
 );
 
+use Template::Stash;
+
+# define list method to flatten arrayrefs
+$Template::Stash::LIST_OPS->{ to_path } = sub {
+    return join('%2F', shift->flatten, @_);
+};
+
 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
 
 __END__
index 6a96cda..4c52cd1 100644 (file)
@@ -1,36 +1,38 @@
-<table class='tree listing'>
- <thead>
+[% BLOCK tree_table_headfoot %]
   <tr>
    <th>mode</th>
    <th>file</th>
    <th>actions</th>
   </tr>
+[% END %]
+<table class='tree listing'>
+ <thead>
+    [% PROCESS tree_table_headfoot %]
  </thead>
  <tfoot>
-  <tr>
-   <td>mode</td>
-   <td>file</td>
-   <td>actions</td>
-  </tr>
+    [% PROCESS tree_table_headfoot %]
  </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 %]
+   [%-
+        action_type = item.type == 'tree' ? 'tree' : 'blob';
+        action_for_link = item.type == 'tree' ? c.action : c.controller.action_for('blob');
+        blob_or_tree_link = c.uri_for(action_for_link, c.req.captures, c.req.args.to_path(item.file))
+   -%]
    <td class='file-name'>
-    <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% item.file %]</a>
+    <a href="[% blob_or_tree_link %]">[% item.file %]</a>
    </td>
    <td class='action-list'>
-     <a href="[% c.uri_for(theact, {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">[% theact %]</a>
+     <a href="[% blob_or_tree_link %]">[% theact %]</a>
          [% IF item.type == 'blob' %]
-         <a href="[% c.uri_for('blame', {h=commit.sha1, hb=commit.sha1, f=fullpath}) %]">blame</a>
+         <a href="[% c.uri_for(c.controller.action_for('blame'), c.req.captures, c.req.args.to_path(item.file)) %]">blame</a>
          [% END %]
-     <a href="[% c.uri_for('history', {h=item.sha1, hb=commit.sha1, f=fullpath}) %]">history</a>
+     <a href="[% c.uri_for(c.controller.action_for('history'), c.req.captures, c.req.args.to_path(item.file)) %]">history</a>
      [% IF item.type == 'blob' %]
-     <a href="[% c.uri_for('raw', {hb=commit.sha1, f=fullpath}) %]">raw</a>
+     <a href="[% c.uri_for(c.controller.action_for('raw'), c.req.captures, c.req.args.to_path(item.file)) %]">raw</a>
      [% END %]
    </td>
   </tr>