From 1d9ffa541e9b2b166de347041facf5db81bc41c4 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 27 Mar 2008 16:04:33 +0000 Subject: [PATCH] Kleine Umgestaltung mit den Pfaden --- lib/FrBr/Books.pm | 9 ++++++- lib/FrBr/Books/Controller/Books.pm | 8 +++---- lib/FrBr/Books/Controller/Login.pm | 2 +- lib/FrBr/Books/Plugin/WebPath.pm | 38 ++++++++++++++++++++++++++++++ root/lib/config/main.tt2 | 15 ++++++++++++ root/lib/site/html.tt2 | 2 +- root/lib/site/statusbar.tt2 | 4 ++-- root/src/books/book_form.tt2 | 2 +- root/src/books/index.tt2 | 6 ++--- root/src/books/new.tt2 | 2 +- root/src/index.tt2 | 2 +- 11 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 lib/FrBr/Books/Plugin/WebPath.pm diff --git a/lib/FrBr/Books.pm b/lib/FrBr/Books.pm index 44d89b9..01f3184 100644 --- a/lib/FrBr/Books.pm +++ b/lib/FrBr/Books.pm @@ -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 : diff --git a/lib/FrBr/Books/Controller/Books.pm b/lib/FrBr/Books/Controller/Books.pm index d07e5c9..4107d85 100644 --- a/lib/FrBr/Books/Controller/Books.pm +++ b/lib/FrBr/Books/Controller/Books.pm @@ -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" }; diff --git a/lib/FrBr/Books/Controller/Login.pm b/lib/FrBr/Books/Controller/Login.pm index eaa72aa..723cdb9 100644 --- a/lib/FrBr/Books/Controller/Login.pm +++ b/lib/FrBr/Books/Controller/Login.pm @@ -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 index 0000000..935e660 --- /dev/null +++ b/lib/FrBr/Books/Plugin/WebPath.pm @@ -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; + diff --git a/root/lib/config/main.tt2 b/root/lib/config/main.tt2 index 18322dc..167fca1 100644 --- a/root/lib/config/main.tt2 +++ b/root/lib/config/main.tt2 @@ -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', diff --git a/root/lib/site/html.tt2 b/root/lib/site/html.tt2 index 6d91b94..c94e96e 100644 --- a/root/lib/site/html.tt2 +++ b/root/lib/site/html.tt2 @@ -14,7 +14,7 @@ [% PROCESS site/jsfiles.tt2 -%] - + [% site_title or template.title or site.title %]