Started the switch from hand-written URLs to uri_for.
broquaint [Sun, 1 Nov 2009 17:02:00 +0000 (17:02 +0000)]
13 files changed:
lib/Gitalist.pm
lib/Gitalist/Controller/Root.pm
templates/blob.tt2
templates/blobdiff.tt2
templates/commit-nav.tt2 [deleted file]
templates/commit.tt2
templates/commitdiff.tt2
templates/heads.tt2
templates/log.tt2
templates/nav/actions.tt2 [new file with mode: 0644]
templates/shortlog.tt2
templates/summary.tt2
templates/tree.tt2

index 16e0990..5213ef7 100644 (file)
@@ -9,20 +9,35 @@ extends 'Catalyst';
 use Catalyst qw/-Debug
                 ConfigLoader
                 Static::Simple
-                               StackTrace/;
+                StackTrace/;
+
+use Class::C3::Adopt::NEXT -no_warn;
+
 our $VERSION = '0.01';
 
 # Bring in the libified gitweb.cgi.
 use gitweb;
 
 __PACKAGE__->config(
-       name => 'Gitalist',
-       default_view => 'Default',
+    name => 'Gitalist',
+    default_view => 'Default',
 );
 
 # Start the application
 __PACKAGE__->setup();
 
+sub uri_for {
+    my $p = ref $_[-1] eq 'HASH'
+          ? $_[-1]
+          : push(@_, {}) && $_[-1];
+    $p->{p} = $_[0]->model('Git')->project;
+
+    (my $uri = $_[0]->NEXT::uri_for(@_[1 .. $#_]))
+      # Ampersand! What is this, the 90s?
+      =~ s/&/;/g;
+    return $uri;
+}
+
 =head1 NAME
 
 Gitalist - Catalyst based application
index bcdc3d0..da1a9cd 100644 (file)
@@ -94,7 +94,7 @@ sub index :Path :Args(0) {
 
   my $list = $c->model('Git')->list_projects;
   unless(@$list) {
-    die "No projects found";
+    die "No projects found in ".Gitalist->config->{repodir};
   }
 
   $c->stash(
index 7b04661..df95156 100644 (file)
@@ -1,6 +1,6 @@
 <link rel="stylesheet" type="text/css" href="/static/css/syntax/[% language %].css"/>
 
-[% PROCESS 'commit-nav.tt2' object = head %]
+[% PROCESS 'nav/actions.tt2' object = head %]
 <div class='commit-message'>
 [% head.comment.substr(0, 85) %] ...
 </div>
index 8d6820b..d03aeb0 100644 (file)
@@ -1,4 +1,4 @@
-[% PROCESS 'commit-nav.tt2' object = commit %]
+[% PROCESS 'nav/actions.tt2' object = commit %]
 
 <div class='commit-message'>
 [% commit.comment.substr(0, 85) %] ...
diff --git a/templates/commit-nav.tt2 b/templates/commit-nav.tt2
deleted file mode 100644 (file)
index 24f38bb..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<div id='commit-nav'>
-    <a href="/summary?p=[% project %]">summary</a> |
-    <a href="/shortlog?p=[% project %];h=[% object.sha1 %]">shortlog</a> |
-    <a href="/log?p=[% project %];h=[% object.sha1 %]">log</a> |
-    <a href="/commit?p=[% project %];h=[% object.sha1 %]">commit</a> |
-    <a href="/commitdiff?p=[% project %];h=[% object.sha1 %]">commitdiff</a> |
-    <a href="/tree?p=[% project %];h=[% object.tree_sha1 %];hb=[% object.sha1 %]">tree</a>
-</div>
index c671f41..3d3d54b 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' object = commit %]
+[% INCLUDE 'nav/actions.tt2' object = commit %]
 
 <div class='commit-message'>
 [% commit.comment.substr(0, 85) %] ...
index a106b26..24723bc 100644 (file)
@@ -1,4 +1,4 @@
-[% PROCESS 'commit-nav.tt2' object = commit %]
+[% PROCESS 'nav/actions.tt2' object = commit %]
 
 <div class='commit-message'>
 [% commit.comment.substr(0, 85) %] ...
index 016b0d4..86c8cec 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' object = commit %]
+[% INCLUDE 'nav/actions.tt2' object = commit %]
 
 <div>
 [% project %]
index 2953d4e..29dbe96 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' object = commit %]
+[% INCLUDE 'nav/actions.tt2' object = commit %]
 
 [% INCLUDE '_log_pager.tt2' %]
 
diff --git a/templates/nav/actions.tt2 b/templates/nav/actions.tt2
new file mode 100644 (file)
index 0000000..8f2293b
--- /dev/null
@@ -0,0 +1,8 @@
+<div id='commit-nav'>
+    <a href="[% c.uri_for('summary') %]">summary</a> |
+    <a href="[% c.uri_for('shortlog', {h=object.sha1}) %]">shortlog</a> |
+    <a href="[% c.uri_for('log', {h=object.sha1}) %]">log</a> |
+    <a href="[% c.uri_for('commit', {h=object.sha1}) %]">commit</a> |
+    <a href="[% c.uri_for('commitdiff', {h=object.sha1}) %]">commitdiff</a> |
+    <a href="[% c.uri_for('tree', {h=object.tree_sha1, hb=object.sha1}) %]">tree</a>
+</div>
index c8e9ef2..2ad5505 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' object = commit %]
+[% INCLUDE 'nav/actions.tt2' object = commit %]
 
 <div>
 [% project %]
index f320ffc..7ccf7af 100644 (file)
@@ -1,4 +1,4 @@
-[% PROCESS 'commit-nav.tt2' object = head %]
+[% PROCESS 'nav/actions.tt2' object = head %]
 
 <div class='summary'>
 <dl>
@@ -9,11 +9,11 @@
 </div>
 
 <div class='shortlog'>
-<h2><a href='/shortlog?p=[% project %]'>shortlog</a></h2>
+<h2><a href='[% c.uri_for('shortlog') %]'>shortlog</a></h2>
 [% INCLUDE '_shortlog.tt2' %]
 </div>
 
 <div class='heads'>
-<h2><a href='/heads?p=[% project %]'>heads</a></h2>
+<h2><a href='[% c.uri_for('heads') %]'>heads</a></h2>
 [% INCLUDE '_heads.tt2' %]
 </div>
index 7b55830..4419028 100644 (file)
@@ -1,4 +1,4 @@
-[% INCLUDE 'commit-nav.tt2' object = commit %]
+[% INCLUDE 'nav/actions.tt2' object = commit %]
 
 <div class='commit-message'>
 [% commit.comment.substr(0, 85) %] ...