changeset 154:eb478083f72b

Url support
author wizard
date Thu, 30 Sep 2010 02:13:05 +0400
parents 3765adf1803f
children 05df123a2ff1
files Lib/IMPL/Web/QueryHandler/PageFormat.pm Lib/IMPL/Web/TT/Collection.pm Lib/IMPL/Web/TT/Document.pm
diffstat 3 files changed, 48 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Mon Sep 27 19:15:34 2010 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Thu Sep 30 02:13:05 2010 +0400
@@ -11,6 +11,7 @@
 use IMPL::Security::Context;
 use File::Spec;
 use HTML::TreeBuilder;
+use URI;
 use Error qw(:try);
 
 $Template::Plugin::URL::JOINT = '&';
@@ -72,22 +73,26 @@
 		my @pathContainer = @path;
 		pop @pathContainer;
 		
-		$doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase );
-		
-		$doc->AddVar( result => $nextHandler->() );
-		$doc->AddVar( action => $action );
-		$doc->AddVar( app => $action->application );
+		$doc->LoadFile (
+			File::Spec->catfile($this->templatesBase,@path),
+			$this->templatesCharset,
+			$this->templatesBase,
+			{
+				result => scalar($nextHandler->()),
+				action => $action,
+				app => $action->application,
 		
-		$doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } );
-		$doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } );
-		$doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } );
+				absoluteUrl => sub { new URI(join ('/', @root, $_[0]) ) },
+				baseUrl => sub { new URI (join ('/', @root, @base, $_[0]) ) },
+				relativeUrl => sub { new URI(join ('/', @root, @base, @pathContainer,$_[0]) ) },
 		
-		$doc->AddVar( user => IMPL::Security::Context->current->principal );
-		$doc->AddVar( session => IMPL::Security::Context->current );
+				user => IMPL::Security::Context->current->principal,
+				session => IMPL::Security::Context->current,
 		
-		$doc->AddVar( to_json => \&to_json );
-		$doc->AddVar( escape_string => sub { $_[0] =~ s/"/"/g; $_[0] } );
-		
+				to_json => \&to_json,
+				escape_string => sub { $_[0] =~ s/"/"/g; $_[0] },
+			}
+		);
 		
 		$action->response->contentType('text/html');
 		my $hOut = $action->response->streamBody;
@@ -110,6 +115,17 @@
 	};
 }
 
+sub URI::_query::new_params {
+	my ($this,$params) = @_;
+	
+	my $clone = $this->clone;
+	if (ref $params eq 'HASH' ) {
+		my %newParams = ($clone->query_form , %$params);
+		$clone->query_form(map { $_, $newParams{$_} } sort keys %newParams );
+	}
+	return $clone;
+}
+
 1;
 
 __END__
--- a/Lib/IMPL/Web/TT/Collection.pm	Mon Sep 27 19:15:34 2010 +0400
+++ b/Lib/IMPL/Web/TT/Collection.pm	Thu Sep 30 02:13:05 2010 +0400
@@ -38,8 +38,4 @@
 	return;
 }
 
-sub as_list {
-	$_[0]->childNodes;
-}
-
 1;
\ No newline at end of file
--- a/Lib/IMPL/Web/TT/Document.pm	Mon Sep 27 19:15:34 2010 +0400
+++ b/Lib/IMPL/Web/TT/Document.pm	Thu Sep 30 02:13:05 2010 +0400
@@ -20,6 +20,7 @@
     public property template => prop_get | owner_set;
     public property presenter => prop_all, { validate => \&_validatePresenter };
     public property preprocess => prop_all | prop_list,
+    public property title => prop_all;
     private property _controlClassMap => prop_all;
 }
 
@@ -163,7 +164,7 @@
 }
 
 sub LoadFile {
-    my ($this,$filePath,$encoding,@includes) = @_;
+    my ($this,$filePath,$encoding,$includes,$vars) = @_;
     
     die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath;
     
@@ -184,12 +185,26 @@
         TRIM => 0,
         COMPILE_EXT => $this->cache ? '.ttc' : undef,
         COMPILE_DIR => $this->cache,
-        INCLUDE_PATH => [$inc,@includes]
+        INCLUDE_PATH => [$inc,ref $includes ? @$includes : $includes ]
     );
     
+    if ($vars) {
+    	while ( my ($var,$val) = each %$vars ) {
+    		$this->AddVar($var,$val);
+    	}
+    }
+    
     $this->context->process($_) foreach $this->preprocess;
     
-    $this->template($this->context->template($fileName));
+    my $template = $this->context->template($fileName);
+    $this->title($template->title);
+    if ( $template->template ) {
+    	$this->context->process($template);
+    	$this->template($template->template);
+    } else {
+    	$this->template($template);
+    }
+    
 }
 
 sub AddVar {
@@ -198,14 +213,10 @@
 	$this->context->stash->set($name,$value);
 }
 
-sub title {
-    $_[0]->template->title;
-}
-
 sub Render {
     my ($this) = @_;
     
-    return $this->template->process($this->context);
+    return $this->context->process($this->template);
 }
 
 # Формирует представление для произвольных объектов 
@@ -248,10 +259,6 @@
 	return;
 }
 
-sub as_list {
-	$_[0]->childNodes;
-}
-
 sub Dispose {
     my ($this) = @_;