diff Lib/IMPL/Web/View/TTDocument.pm @ 287:2d253e6e4a88

*TTView refactoring
author cin
date Tue, 19 Feb 2013 03:05:10 +0400
parents d357b5d85d25
children 3a9cfea098dd
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm	Mon Feb 18 14:46:06 2013 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Tue Feb 19 03:05:10 2013 +0400
@@ -13,15 +13,14 @@
     },
     base => [
         'IMPL::Web::View::TTControl' => sub {
-            my ($template,$contextOpts) = @_;
+            my ($template,$ctx) = @_;
             'document',
             $template, # template
-            Template::Context->new($contextOpts)  # context
+            $ctx || Template::Context->new()  # context
         }
     ],
     props => [
         layout => PROP_RW,
-        opts => PROP_RO,
         loader => PROP_RW,
         controls => PROP_RO,
         creationArgs => PROP_RO,
@@ -37,14 +36,13 @@
 }
 
 sub CTOR {
-    my ($this,$template,$refOpts,$loader,$vars) = @_;
+    my ($this,$template,$ctx,$loader,$vars) = @_;
     
     $this->controls({});
     $this->loader($loader) if $loader;
     
     $this->layout( $template->layout ) unless $this->layout;
     
-    $this->opts($refOpts);
     $this->stash($this->context->stash);
     $this->creationArgs($vars);
     
@@ -82,18 +80,16 @@
         my $path = $control;
         
         if ( my $template = $this->loader->template($path) ) {
-            my $opts = { %{$this->opts} };
 
             # factory will create a clone of the stash 
             # $opts->{STASH} = $this->stash->clone();
  
-            my $ctx = new Template::Context($opts);
+            my $ctx = Template::Context->new({%{$this->context}, STASH => $this->stash });#new Template::Context($opts);
             
             $factory = new IMPL::Web::View::TTFactory(
                 $template->class || TTControl,
                 $template,
                 $ctx,
-                $opts,
                 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) )
             );
             
@@ -119,28 +115,40 @@
     my $newArgs = hashMerge($this->creationArgs, $args);
     
     if ($this->layout) {
-    	my $tlayout = $this->loader->layout($this->layout);
-    	if(my $init = $tlayout->blocks->{INIT}) {
-    		$this->context->process(
-                $init,
-                hashMerge(
-                    $newArgs,
-                    {
-                    	this => $this,
-                    	template => $this->template
-                    }
-                )
+        my $text = eval {
+            #$this->context->localise();
+        	my $tlayout = $this->loader->layout($this->layout);
+        	if(my $init = $tlayout->blocks->{INIT}) {
+        		$this->context->process(
+                    $init,
+                    hashMerge(
+                        $newArgs,
+                        {
+                        	template => $this->template
+                        }
+                    )
+                );
+        	}
+            return $this->context->include(
+                $tlayout,
+                {
+                	%{$newArgs},
+                    content => $this->RenderContent($newArgs),
+                    this => $this,
+                    template => $this->template
+                }
             );
-    	}
-        return $this->context->include(
-            $tlayout,
-            {
-            	%{$newArgs},
-                content => $this->RenderContent($newArgs),
-                this => $this,
-                template => $this->template
-            }
-        );
+        };
+        my $e = $@;
+        
+        #$this->context->delocalise();
+        
+        if ($e) {
+            die $e;
+        } else {
+            return $text;
+        }
+        
     } else {
         return $this->RenderContent($newArgs);
     }