changeset 267:bbc0da7ef90e

*IMPL::Web::View refactoring
author cin
date Thu, 17 Jan 2013 02:39:44 +0400
parents 89179bb8c388
children 4abda21186cd dacfe7c0311a
files Lib/IMPL/Resources/Strings.pm Lib/IMPL/Web/View/TTControl.pm Lib/IMPL/Web/View/TTDocument.pm Lib/IMPL/Web/View/TTFactory.pm
diffstat 4 files changed, 46 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Resources/Strings.pm	Mon Jan 14 03:10:06 2013 +0400
+++ b/Lib/IMPL/Resources/Strings.pm	Thu Jan 17 02:39:44 2013 +0400
@@ -122,7 +122,7 @@
 use IMPL::Resources::Strings {
     msg_say_hello => "Hello, %name%!",
     msg_module_name => "Simple Foo class"
-}, auto => 1, locale => 'en-US';
+};
 
 sub InviteUser {
     my ($this,$uname) = @_;
--- a/Lib/IMPL/Web/View/TTControl.pm	Mon Jan 14 03:10:06 2013 +0400
+++ b/Lib/IMPL/Web/View/TTControl.pm	Thu Jan 17 02:39:44 2013 +0400
@@ -96,7 +96,7 @@
     }
 }
 
-sub GetRenderBlock {
+sub GetMainBlock {
     $_[0]->template->blocks->{RENDER} || $_[0]->template;
 }
 
@@ -105,13 +105,21 @@
     
     $args = {} unless ref $args eq 'HASH';
     
-    if(my $body = $this->GetRenderBlock ) {
+    if(my $body = $this->GetMainBlock ) {
         return $this->context->include( $body, { %$args, this => $this, template => $this->template } );
     } else {
         return "";
     }    
 }
 
+sub RenderBlock {
+    my ($this,$block, $args) = @_;
+    
+    $args = {} unless ref $args eq 'HASH';
+    
+    return $this->context->include( $block, { %$args, this => $this, template => $this->template } );
+}
+
 sub AUTOLOAD {
     our $AUTOLOAD;
     
--- a/Lib/IMPL/Web/View/TTDocument.pm	Mon Jan 14 03:10:06 2013 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Thu Jan 17 02:39:44 2013 +0400
@@ -75,16 +75,14 @@
 }
 
 sub RequireControl {
-    my ($this, $control, $nodeProps) = @_;
-    
-    $nodeProps ||= {};
-    $nodeProps->{document} = $this;
+    my ($this, $control) = @_;
     
     if (my $factory = $this->controls->{$control}) {
         return $factory;
     } else {
     
         my $path = $control;
+        
         if ( my $template = $this->loader->template($path) ) {
             my $opts = { %{$this->opts} };
 
@@ -97,7 +95,8 @@
                 $template->class || TTControl,
                 $template,
                 $ctx,
-                $opts
+                $opts,
+                join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) )
             );
             
             if ($template->class) {
--- a/Lib/IMPL/Web/View/TTFactory.pm	Mon Jan 14 03:10:06 2013 +0400
+++ b/Lib/IMPL/Web/View/TTFactory.pm	Thu Jan 17 02:39:44 2013 +0400
@@ -3,25 +3,27 @@
 
 use Template::Context();
 
-use IMPL::lang qw(:hash :declare );
+use IMPL::lang qw(:hash);
 use IMPL::Exception();
 use Scalar::Util qw(weaken);
 
 
-use parent qw(IMPL::Object::Factory);
-
-BEGIN {
-    public property template => PROP_ALL;
-    public property context => PROP_ALL;
-    public property opts => PROP_ALL;
-    public property nodeProperties => PROP_ALL;
-    public property instances => PROP_GET | PROP_OWNERSET;
-}
-
-__PACKAGE__->PassThroughArgs;
+use IMPL::Const qw(:prop);
+use IMPL::declare {
+    base => [
+        'IMPL::Object::Factory' => '@_'
+    ],
+    props => [
+        template => PROP_RW,
+        context => PROP_RW,
+        opts => PROP_RW,
+        instances => PROP_RW,
+        base => PROP_RW 
+    ]
+};
 
 sub CTOR {
-    my ($this,$factory,$template,$context,$options,$nodeProps) = @_;
+    my ($this,$factory,$template,$context,$options,$base) = @_;
     
     die IMPL::ArgumentException("A template is required") unless $template;
     
@@ -31,7 +33,7 @@
     $this->template($template);
     $this->context($context);
     $this->opts($options);
-    $this->nodeProperties($nodeProps || {});
+    $this->base($base);
     $this->instances(0);
 }
 
@@ -47,9 +49,23 @@
     my $opts = { %{ $this->opts } };
     $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH};
     
+    my $base = $this->base;
+    
     my $ctx = new Template::Context($opts);
     
-    return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps));
+    my $stash = $ctx->stash;
+    weaken($stash);
+    
+    $stash->update({
+        require => sub {
+            my ($module) = @_;
+            
+            $module =~ s/^\.\//$base\//;
+            return $stash->get('document')->RequireControl($module);
+        }        
+    });
+    
+    return ($name, $this->template, $ctx, hashApply({ factory => $this },$refProps));
 }
 
 sub CreateObject {