Mercurial > pub > Impl
changeset 136:f6af119ac741
url routines for templates
author | wizard |
---|---|
date | Fri, 25 Jun 2010 16:45:56 +0400 |
parents | 5b849974bed8 |
children | 6975cd4973d1 |
files | Lib/IMPL/Web/QueryHandler/PageFormat.pm Lib/IMPL/Web/TT/Document.pm |
diffstat | 2 files changed, 28 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm Thu Jun 24 02:39:00 2010 +0400 +++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm Fri Jun 25 16:45:56 2010 +0400 @@ -1,14 +1,18 @@ package IMPL::Web::QueryHandler::PageFormat; use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill); +use strict; __PACKAGE__->PassThroughArgs; use IMPL::Class::Property; use IMPL::Web::TT::Document; +use Template::Plugin::URL; use IMPL::Security::Context; use File::Spec; use Error qw(:try); +$Template::Plugin::URL::JOINT = '&'; + BEGIN { public property templatesCharset => prop_all; public property templatesBase => prop_all; @@ -34,12 +38,29 @@ $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; - my $pathInfo = $ENV{PATH_INFO}; - my $prefixRoot = ""; + my ($requestUri) = split /\?/, $ENV{REQUEST_URI}; + + my $pathInfo; + + if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) { + # CGI with path info + $pathInfo = $ENV{PATH_INFO}; + } else { + die "REQUEST_URI: $ENV{REQUEST_URI}\nPATH_INFO: $ENV{PATH_INFO}" unless $ENV{REQUEST_URI} eq $ENV{PATH_INFO}; + } + + my @root = (''); + my @base; + if (my $rx = $this->pathinfoPrefix) { - $pathInfo =~ s/($rx)//; - $prefixRoot = $1 if $1; + $requestUri =~ s/^($rx)//; + push @root, grep $_, split /\//, $1 if $1; } + + $pathInfo = $requestUri unless defined $pathInfo; + + @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri); + local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); @@ -50,8 +71,9 @@ $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase ); $doc->AddVar( result => $nextHandler->() ); $doc->AddVar( app => $action->application ); - $doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } ); - $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } ); + $doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } ); + $doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } ); + $doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } ); { local $@; $doc->AddVar( user => IMPL::Security::Context->current->principal );
--- a/Lib/IMPL/Web/TT/Document.pm Thu Jun 24 02:39:00 2010 +0400 +++ b/Lib/IMPL/Web/TT/Document.pm Fri Jun 25 16:45:56 2010 +0400 @@ -5,7 +5,6 @@ use base qw(IMPL::DOM::Document IMPL::Object::Disposable); use Template::Context; use Template::Provider; -use Template::Plugin::URL; use IMPL::Class::Property; use File::Spec; use Scalar::Util qw(blessed); @@ -13,8 +12,6 @@ use IMPL::Web::TT::Control; use Carp; -$Template::Plugin::URL::JOINT = '&'; - BEGIN { private property _provider => prop_all; private property _context => prop_all;