changeset 140:fb896377389f

to_json and escape_string functions for the templates minor changes
author wizard
date Mon, 05 Jul 2010 02:22:42 +0400
parents 5a9f64890c31
children 7245c39e941e
files Lib/IMPL/Serialization.pm Lib/IMPL/Web/QueryHandler/JsonFormat.pm Lib/IMPL/Web/QueryHandler/PageFormat.pm Lib/IMPL/Web/TT/Control.pm
diffstat 4 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 {
--- 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}) {
--- 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;
--- 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 {