# HG changeset patch # User wizard # Date 1280099946 -14400 # Node ID 60fd224f3e3c9f6566141d9c4e924c23f04da222 # Parent bd10093bb12212784cd7771e1edcdb017fd2a81a fixed cgi parameters processing Added parameters inflating feature Added preprocessed templates, reformatting output diff -r bd10093bb122 -r 60fd224f3e3c Lib/IMPL/Web/Application/Action.pm --- 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 { diff -r bd10093bb122 -r 60fd224f3e3c Lib/IMPL/Web/Application/ControllerUnit.pm --- 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; } } diff -r bd10093bb122 -r 60fd224f3e3c Lib/IMPL/Web/QueryHandler/PageFormat.pm --- 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; }; diff -r bd10093bb122 -r 60fd224f3e3c Lib/IMPL/Web/TT/Document.pm --- 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)); }