# HG changeset patch # User wizard # Date 1278282162 -14400 # Node ID fb896377389f8fb9984a0f4779ebafd2f6e54c62 # Parent 5a9f64890c31f190014f9627170cd010eb42de50 to_json and escape_string functions for the templates minor changes diff -r 5a9f64890c31 -r fb896377389f Lib/IMPL/Serialization.pm --- a/Lib/IMPL/Serialization.pm Thu Jul 01 17:32:29 2010 +0400 +++ b/Lib/IMPL/Serialization.pm Mon Jul 05 02:22:42 2010 +0400 @@ -368,7 +368,7 @@ return $refSurogate; } } else { - eval "require $Type" unless _is_class($Type); + eval "require $Type; 1;" or warn $@ unless _is_class($Type); if ( $Type->UNIVERSAL::can('restore') ) { return $Type->restore($Data,$refSurogate); } else { diff -r 5a9f64890c31 -r fb896377389f Lib/IMPL/Web/QueryHandler/JsonFormat.pm --- a/Lib/IMPL/Web/QueryHandler/JsonFormat.pm Thu Jul 01 17:32:29 2010 +0400 +++ b/Lib/IMPL/Web/QueryHandler/JsonFormat.pm Mon Jul 05 02:22:42 2010 +0400 @@ -99,6 +99,8 @@ sub Transform { my ($this,$object) = @_; + # small hack to prevent cycling + return $this->SUPER::Transform($object) unless ref $object; if (exists $this->{$_visited}{refaddr $object}) { diff -r 5a9f64890c31 -r fb896377389f Lib/IMPL/Web/QueryHandler/PageFormat.pm --- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm Thu Jul 01 17:32:29 2010 +0400 +++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm Mon Jul 05 02:22:42 2010 +0400 @@ -4,6 +4,7 @@ __PACKAGE__->PassThroughArgs; +use JSON; use IMPL::Class::Property; use IMPL::Web::TT::Document; use Template::Plugin::URL; @@ -69,17 +70,20 @@ pop @pathContainer; $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 { 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 ); - $doc->AddVar( session => IMPL::Security::Context->current ); - warn $@ if $@; - } + + $doc->AddVar( user => IMPL::Security::Context->current->principal ); + $doc->AddVar( session => IMPL::Security::Context->current ); + + $doc->AddVar( to_json => \&to_json ); + $doc->AddVar( escape_string => sub { $_[0] =~ s/"/"/g; $_[0] } ); + $action->response->contentType('text/html'); my $hOut = $action->response->streamBody; diff -r 5a9f64890c31 -r fb896377389f Lib/IMPL/Web/TT/Control.pm --- a/Lib/IMPL/Web/TT/Control.pm Thu Jul 01 17:32:29 2010 +0400 +++ b/Lib/IMPL/Web/TT/Control.pm Mon Jul 05 02:22:42 2010 +0400 @@ -20,12 +20,12 @@ if ($this->document) { # load a template - $args{template} = $this->document->context->template($args{template}) if ($args{template} and not ref $args{template}); + $this->template( $this->document->context->template($args{template})) if ($args{template} and not ref $args{template}); } #$this->template($args{template}) if $args{template}; $this->id($this->nodeName . '-' . $nextId++); - $this->controlClass($args{controlClass} || 'Control'); + $this->controlClass('Control') unless $this->controlClass; } sub Render {