]> Frank Brehm's Git Trees - books.git/commitdiff
Kleine Umgestaltung mit den Pfaden
authorFrank Brehm <frank@brehm-online.com>
Thu, 27 Mar 2008 16:04:33 +0000 (16:04 +0000)
committerFrank Brehm <frank@brehm-online.com>
Thu, 27 Mar 2008 16:04:33 +0000 (16:04 +0000)
lib/FrBr/Books.pm
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Controller/Login.pm
lib/FrBr/Books/Plugin/WebPath.pm [new file with mode: 0644]
root/lib/config/main.tt2
root/lib/site/html.tt2
root/lib/site/statusbar.tt2
root/src/books/book_form.tt2
root/src/books/index.tt2
root/src/books/new.tt2
root/src/index.tt2

index 44d89b9fe0d89528e41c1a2fb2a81d644078e27e..01f3184729e30b541a26ff53051d0f672daf0f8d 100644 (file)
@@ -23,6 +23,7 @@ use FrBr::Common;
 use Catalyst qw/
 
     +FrBr::Books::Plugin::ConfigLoader
+    +FrBr::Books::Plugin::WebPath
 
     Static::Simple
 
@@ -76,6 +77,10 @@ sub auto : Private {
     my ( $self, $c ) = @_;
     my $K = __PACKAGE__ . "::auto(): ";
 
+    my $self_url = $c->request->base . $c->request->path;
+    $self_url =~ s#^https?://[^/]+/#/#;
+    $c->stash->{'self_url'} = $self_url;
+
     my $storage = $c->model('Schema')->storage;
     $c->stash->{'storage'} = $storage;
 
@@ -83,7 +88,7 @@ sub auto : Private {
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/"),
+        'path' => $c->web_path("/"),
         'name' => "Startseite"
     };
 
@@ -144,6 +149,8 @@ sub auto : Private {
 
     $c->stash->{'login_action'} = 'login';
 
+    $c->log->debug( $K . "Aktuelle Script-URL: '" . $c->stash->{'self_url'} . "'." ) if $c->stash->{'debug_level'} >= 2;
+
     1;
 
 } ## end sub auto :
index d07e5c91da934521627a1787c93c3fe61008ecf1..4107d85b5faf9138dc5d47bda59e451655129e4e 100644 (file)
@@ -39,7 +39,7 @@ sub auto : Private {
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/books"),
+        'path' => $c->web_path("/books"),
         'name' => "Bücher"
     };
 
@@ -78,7 +78,7 @@ sub default : Private {
     $c->stash->{'template'}   = 'not_implemented.tt2';
 
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/books/default"),
+        'path' => $c->web_path("/books/default"),
         'name' => "Nicht Implementiert"
     };
 
@@ -100,7 +100,7 @@ sub list : Local {
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/books/list"),
+        'path' => $c->web_path("/books/list"),
         'name' => "Liste"
     };
 
@@ -129,7 +129,7 @@ sub form_new : Path('new') {
 
     $c->stash->{'menu_path'} = [] unless $c->stash->{'menu_path'};
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/books/new"),
+        'path' => $c->web_path("/books/new"),
         'name' => "Neu"
     };
 
index eaa72aaf4c829a546493d01d10720c7ff2b092bc..723cdb90735a2f298b0930a4f9b750e962167550 100644 (file)
@@ -31,7 +31,7 @@ sub index : Private {
     $c->stash->{'template'}   = 'not_implemented.tt2';
 
     push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->uri_for("/login"),
+        'path' => $c->web_path("/login"),
         'name' => "Anmeldung"
     };
 
diff --git a/lib/FrBr/Books/Plugin/WebPath.pm b/lib/FrBr/Books/Plugin/WebPath.pm
new file mode 100644 (file)
index 0000000..935e660
--- /dev/null
@@ -0,0 +1,38 @@
+package FrBr::Books::Plugin::WebPath;
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use Carp qw/croak/;
+
+our $VERSION = '0.02';
+
+=head2 web_path
+
+Wrapper fuer $Catalyst->uri_for(), um C<< $c->request->base >> aus der URI zu entfernen.
+
+=cut
+
+sub web_path {
+
+    my $c = shift;
+    my $K = __PACKAGE__ . "::web_path(): ";
+
+    my $base = $c->req->base;
+    $base =~ s#^(https?://[^/]+/).*#$1#;
+
+    my $uri = $c->uri_for(@_);
+    return '/' if $uri eq $base;
+
+    my $uri_rel = $uri->rel($base);
+    $uri_rel = '/' . $uri_rel unless $uri_rel =~ m#^/#;
+
+    return $uri_rel;
+
+}
+
+1;
+
index 18322dcdfa3e50994faf509efe35e2f9f8246942..167fca13640ac2b64f3a86efcd70ed367a034832 100644 (file)
@@ -8,9 +8,24 @@
    template.  This is the place to define any extra template variables,
    macros, load plugins, and perform any other template setup.
 
+-%]
+[%# -
+
+    MACRO l(text, args) BLOCK;
+       Catalyst.localize(text, args);
+    END;
+
 -%]
 [%-
 
+    MACRO uri( path ) BLOCK;
+        Catalyst.uri_for( path );
+    END;
+
+    MACRO path( path ) BLOCK;
+        Catalyst.web_path( path );
+    END;
+
     # define a data structure to hold sitewide data
     site = {
         title     => 'Inhalt',
index 6d91b9447114a3aa7b0d7343ee5b010e61d45f4f..c94e96e11521da9d8e8efb53b24896e13a91ea94 100644 (file)
@@ -14,7 +14,7 @@
   <meta name="copyright" content="copyright 2008 Frank Brehm, Berlin" />
   <meta name="robots" content="noindex" />
 [% PROCESS site/jsfiles.tt2 -%]
-  <link rel="shortcut icon" href="[% Catalyst.uri_for('/static/pic/fbr.ico') %]" />
+  <link rel="shortcut icon" href="[% path('/static/pic/fbr.ico') %]" />
   <title>[% site_title or template.title or site.title %]</title>
   <style type="text/css">
 [% PROCESS site/styles.css %]
index 50fcf30ec396942467a9c78c1552ea5a9f0972d0..eac6ec669c89a3a5b63a7ff9218296d2022c3502 100644 (file)
     &nbsp;
 [%- ELSE -%]
     [%- IF login_action == 'login' -%]
-    <span class="login"><a href="[% Catalyst.uri_for("/login") %]">Anmelden</a></span>
+    <span class="login"><a href="[% path("/login") %]">Anmelden</a></span>
     [%- ELSE -%]
     Angemeldet als: <span class="login">[% current_user %] -
-    <a href="[% Catalyst.uri_for("/logout") %]">Abmelden</a></span>
+    <a href="[% path("/logout") %]">Abmelden</a></span>
     [%- END -%]
 [%- END -%]
     </td>
index c366a296e16b6de3c9e87df8f40c333c7e181ac6..7b5b6bb9010eda3c9a403f907dc2dd63260724c2 100644 (file)
@@ -6,7 +6,7 @@
 
 -%]
 <!-- Book form -->
-<form method="post" name="book_form" action="[% Catalyst.request.base %][% Catalyst.request.path %]">
+<form method="post" name="book_form" action="[% self_url %]">
 <input type="hidden" name="book_form_sent" value="sent" />
 [%- IF book_edit.id %]<input type="hidden" name="book_id" value="[% book_edit.id | html %]" />[% END %]
   <table class="ftable" cellspacing="0">
index 0d58760b6d4f16af35c1a75f85c69a58383ead1d..2bed461706bb51d7991f800271df39e284f28d61 100644 (file)
@@ -19,7 +19,7 @@
     <td class="button">
       &nbsp;</td>
     <td class="item">
-      <a href="[% Catalyst.uri_for('/books/search') %]">Suchmaske</a></td>
+      <a href="[% path('/books/search') %]">Suchmaske</a></td>
   </tr>
   <tr>
     <td colspan="2" class="empty">
@@ -29,7 +29,7 @@
     <td class="button">
       &nbsp;</td>
     <td class="item">
-      <a href="[% Catalyst.uri_for('/books/list') %]">Bücherliste</a></td>
+      <a href="[% path('/books/list') %]">Bücherliste</a></td>
   </tr>
   <tr>
     <td colspan="2" class="empty">
@@ -39,7 +39,7 @@
     <td class="button">
       &nbsp;</td>
     <td class="item">
-      <a href="[% Catalyst.uri_for('/') %]">Zurück zum Hauptmenü</a></td>
+      <a href="[% path('/') %]">Zurück zum Hauptmenü</a></td>
   </tr>
 </table>
 </div>
index cb8f10db7df7811460ea1fc2b550647f85307432..59abf93dd7df92a6c3a499d3042e6e5f293a7985 100644 (file)
@@ -9,5 +9,5 @@
 [% PROCESS books/book_form.tt2 %]
 
 <div class="back">
-<h2><a href="[% Catalyst.uri_for('/books') %]">[% 'Zurück' %]</a></h2>
+<h2><a href="[% path('/books') %]">[% 'Zurück' %]</a></h2>
 </div>
index dea2373e047a2e75bd1829f8d57ffec324ca985a..d8f32b40b1687c688cddb73c11a4776fa00c9525 100644 (file)
@@ -21,7 +21,7 @@
     <td class="button">
       &nbsp;</td>
     <td class="item">
-      <a href="[% Catalyst.uri_for('/books') %]">Bücher suchen</a></td>
+      <a href="[% path('/books') %]">Bücher suchen</a></td>
   </tr>
 </table>
 </div>