diff Lib/IMPL/Web/View/TTDocument.pm @ 241:f48a1a9f4fa2

+Added ViewResult to allow implementation of the view environment. *TTDocuments now storing creation parameters *TTControls automatically propagating layout and title meta to their attributes +Added UnauthorizaedException web exception *minor fixes
author sergey
date Thu, 18 Oct 2012 04:49:55 +0400
parents b8c724f6de36
children 7c517134c42f
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm	Wed Oct 17 17:41:29 2012 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Thu Oct 18 04:49:55 2012 +0400
@@ -3,6 +3,7 @@
 
 use Scalar::Util qw(weaken);
 use IMPL::Const qw(:prop);
+use IMPL::lang qw(:hash);
 
 use IMPL::declare {
     require => {
@@ -23,6 +24,7 @@
         opts => PROP_RO,
         loader => PROP_RW,
         controls => PROP_RO,
+        creationArgs => PROP_RO,
         
         # store the stash separately to make require() method to work correctly
         # even when a stash of the context is modified during the processing 
@@ -44,17 +46,20 @@
     
     $this->opts($refOpts);
     $this->stash($this->context->stash);
+    $this->creationArgs($vars);
     
     my $self = $this;
     weaken($self);
     
-    $this->templateVars('require', sub {
+    $this->templateVars(require => sub {
         my $doc = $self;
         die new IMPL::Exception("A document is destroyed or invalid") unless $doc;
         $doc->RequireControl(@_);
     });
     
-    $this->templateVars('document', sub { $self } );
+    $this->templateVars(context => $vars);
+    
+    $this->templateVars(document => sub { $self } );
     $this->InitInstance($vars);
 }
 
@@ -114,23 +119,23 @@
 sub Render {
     my ($this,$args) = @_;
     
-    my $output;
+    $args ||= {};
+    
+    my $newArgs = hashMerge($this->creationArgs, $args);
     
     if ($this->layout) {
-        $output = $this->context->include(
+        return $this->context->include(
             $this->loader->layout($this->layout),
             {
-            	%{$args || {}},
-                content => sub { $this->RenderContent($args); },
+            	%{$newArgs},
+                content => sub { $this->RenderContent($newArgs); },
                 this => $this,
                 template => $this->template
             }
         );
     } else {
-        return $this->RenderContent($args);
+        return $this->RenderContent($newArgs);
     }
-    
-    return $output;
 }
 
 sub RenderContent {