changeset 146:60fd224f3e3c

fixed cgi parameters processing Added parameters inflating feature Added preprocessed templates, reformatting output
author wizard
date Mon, 26 Jul 2010 03:19:06 +0400
parents bd10093bb122
children c2aa10fbb396
files Lib/IMPL/Web/Application/Action.pm Lib/IMPL/Web/Application/ControllerUnit.pm Lib/IMPL/Web/QueryHandler/PageFormat.pm Lib/IMPL/Web/TT/Document.pm
diffstat 4 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/Action.pm	Wed Jul 21 06:27:12 2010 +0400
+++ b/Lib/IMPL/Web/Application/Action.pm	Mon Jul 26 03:19:06 2010 +0400
@@ -90,7 +90,7 @@
 sub param {
 	my ($this,$name,$rx) = @_;
 	
-	$this->_launder( $this->query->param($name), $rx );
+	$this->_launder(scalar( $this->query->param($name) ), $rx );
 }
 
 sub _launder {
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm	Wed Jul 21 06:27:12 2010 +0400
+++ b/Lib/IMPL/Web/Application/ControllerUnit.pm	Mon Jul 26 03:19:06 2010 +0400
@@ -102,18 +102,28 @@
 	
 	my $params;
 	if ($params = $methodInfo->{parameters} and ref $params eq 'ARRAY') {
-		return map $this->ResolveParam($_), @$params; 
+		return map $this->ResolveParam($_,$methodInfo->{inflate}{$_}), @$params; 
 	}
 	return();
 }
 
 sub ResolveParam {
-	my ($this,$param) = @_;
+	my ($this,$param,$inflate) = @_;
 	
 	if ( $param =~ /^::(\w+)$/ and $publicProps{$1}) {
 		return $this->$1();
 	} else {
-		return scalar($this->query->param($param));
+		my $value;
+		if ( my $rx = $inflate->{rx} ) {
+			$value = $this->action->param($param,$rx);
+		} else {
+			$value = $this->query->param($param);
+		}
+		
+		if (my $method = $inflate->{method}) {
+			$value = $this->$method($value); 
+		}
+		return $value;
 	}
 }
 
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Wed Jul 21 06:27:12 2010 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Mon Jul 26 03:19:06 2010 +0400
@@ -10,6 +10,7 @@
 use Template::Plugin::URL;
 use IMPL::Security::Context;
 use File::Spec;
+use HTML::TreeBuilder;
 use Error qw(:try);
 
 $Template::Plugin::URL::JOINT = '&';
@@ -20,6 +21,8 @@
 	public property defaultTarget => prop_all;
 	public property pathinfoPrefix => prop_all;
 	public property cache => prop_all;
+	public property preprocess => prop_all;
+	public property formatOutput => prop_all;
 }
 
 sub CTOR {
@@ -33,7 +36,7 @@
 sub Process {
 	my ($this,$action,$nextHandler) = @_;
 	
-	my $doc = new IMPL::Web::TT::Document(cache => $this->cache);
+	my $doc = new IMPL::Web::TT::Document(cache => $this->cache, preprocess => $this->preprocess);
 	
 	try {
 
@@ -88,7 +91,20 @@
 		
 		$action->response->contentType('text/html');
 		my $hOut = $action->response->streamBody;
-		print $hOut $doc->Render();
+		if ($this->formatOutput == 1) {
+			my $tree = new HTML::TreeBuilder();
+			try {
+				$tree->parse_content($doc->Render());
+				print $hOut $tree->as_HTML('<>&',"    ",{});
+			} finally {
+				$tree->delete;
+			};
+		} elsif ($this->formatOutput() == 2 ) {
+			(my $data = $doc->Render()) =~ s/\s+/ /g;
+			print $hOut $data;
+		} else {
+			print $hOut $doc->Render();
+		}
 	} finally {
 		$doc->Dispose;
 	};
--- a/Lib/IMPL/Web/TT/Document.pm	Wed Jul 21 06:27:12 2010 +0400
+++ b/Lib/IMPL/Web/TT/Document.pm	Mon Jul 26 03:19:06 2010 +0400
@@ -18,6 +18,7 @@
     public property cache => prop_all;
     public property template => prop_get | owner_set;
     public property presenter => prop_all, { validate => \&_validatePresenter };
+    public property preprocess => prop_all | prop_list,
     private property _controlClassMap => prop_all;
 }
 
@@ -33,6 +34,7 @@
 	$this->appendChild( $this->Create(body => 'IMPL::Web::TT::Collection') );
 	$this->appendChild( $this->Create(head => 'IMPL::Web::TT::Collection') );
 	$this->cache($args{cache}) if $args{cache};
+	$this->preprocess($args{preprocess}) if $args{preprocess};
 }
 
 sub CreateControl {
@@ -77,8 +79,6 @@
                     	$this->_process(@_);
                     }
                 },
-                POST_CHOMP => 2,
-                PRE_CHOMP => 2,
                 RECURSION => 1,
                 LOAD_TEMPLATES => [$this->provider]
             )
@@ -103,6 +103,9 @@
 	
 	die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node');
 	
+	# resolve template name to a real template
+	$args->{template} = $this->context->template($args->{template}) if $args->{template};
+	
 	$this->_controlClassMap->{$controlClass} = {
 		controlClass => $controlClass,
 		type => $type,
@@ -127,7 +130,7 @@
 	if (not $this->isControlClass($controlClass)) {
 		if ($doc->template) {
 			$controlTemplate = $doc->blocks()->{$doc->template} || $this->context->template($doc->template);
-			$out = $this->context->process($doc);
+			$out = $this->context->include($doc);
 		} else {
 			$controlTemplate = $doc;
 		}
@@ -174,11 +177,14 @@
         INTERPOLATE => 1,
         PRE_CHOMP => 1,
         POST_CHOMP => 1,
+        TRIM => 0,
         COMPILE_EXT => $this->cache ? '.ttc' : undef,
         COMPILE_DIR => $this->cache,
         INCLUDE_PATH => [$inc,@includes]
     );
     
+    $this->context->process($_) foreach $this->preprocess;
+    
     $this->template($this->context->template($fileName));
 }