diff Lib/IMPL/Web/View/TTContext.pm @ 352:675cd1829255

working on TTView: added control classes support
author cin
date Thu, 10 Oct 2013 19:51:19 +0400
parents cfd7570c2af2
children feeb3bc4a818
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTContext.pm	Tue Oct 08 17:40:35 2013 +0400
+++ b/Lib/IMPL/Web/View/TTContext.pm	Thu Oct 10 19:51:19 2013 +0400
@@ -13,7 +13,8 @@
 	   Document => '-Template::Document',
 	   TypeKeyedCollection => 'IMPL::TypeKeyedCollection',
 	   ArgException => '-IMPL::InvalidArgumentException',
-	   Resources => 'IMPL::Resources'
+	   Resources => 'IMPL::Resources',
+	   Loader => 'IMPL::Code::Loader'
 	},
 	base => [
 		'Template::Context' => '@_'
@@ -32,6 +33,7 @@
 	   cache
 	   includes
 	   modules
+	   aliases
 	)) {
 		my $t = $prop;
 		
@@ -93,11 +95,17 @@
                 if $info;
 		} else {
             if( my $tt = eval { $this->template($file) } ) {
+            	my $class;
+            	if ($class = $tt->class) {
+            		$class = $this->aliases->{$class} || $class;
+            		Loader->safe->Require($class);
+            	}
                 my $info = {
 		            base => $base,
 		            labels => $this->load_labels($file),
 		            template => $tt,
-		            initialized => 0
+		            initialized => 0,
+		            class => $class
 		        };
 		        $this->modules->{$file} = $info;
 		        return $cache->{$name} = $info;
@@ -188,6 +196,7 @@
 		$this->localise(
             hashApply(
 	            {
+	            	aliases => $this->aliases || {},
 					root => $this->root || $this,
 					modules => $this->modules || {},
 					cache => TypeKeyedCollection->new(),
@@ -236,7 +245,7 @@
     return $this->invoke_environment(
         sub {
        	    my $ctx = shift;
-       	   
+       	    
        	    unless($info->{initialized}) {
        	        if(my $init = $info->{template}->blocks->{INIT}) {
        	        	$info->{initialized} = 1;
@@ -247,8 +256,12 @@
        	            $ctx->leave();
        	        }
        	    }
-       	   
-            return $ctx->include($info->{template},$args);
+       	    
+       	    if (my $class = $info->{class}) {
+       	    	$class->new($this,$info->{template})->Render($args);
+       	    } else {
+            	return $ctx->include($info->{template},$args);
+       	    }
 	   },
 	   hashMerge(
 	       $info->{labels} || {},