diff Lib/IMPL/Web/View/TTContext.pm @ 354:9330835535b9

fixed view double rendering
author cin
date Wed, 16 Oct 2013 17:28:40 +0400
parents feeb3bc4a818
children 8dfb9df07d02
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTContext.pm	Fri Oct 11 15:49:04 2013 +0400
+++ b/Lib/IMPL/Web/View/TTContext.pm	Wed Oct 16 17:28:40 2013 +0400
@@ -34,6 +34,7 @@
 	   includes
 	   modules
 	   aliases
+	   resolver
 	)) {
 		my $t = $prop;
 		
@@ -137,22 +138,23 @@
 	
 	my $prefix = $this->prefix;
 	
+	my $info;
+	
     if (not(($args and delete $args->{_no_resolve}) or ref $model)) {
-		$prefix = $prefix ? "${prefix}.${model}" : $model;
-		$model = $this->resolve_model($model);
+		$info = $this->resolve_model($model,$args);
 	} else {
-		$prefix = "";
+		$info = {
+			model => $model,
+			prefix => ""
+		};
 	}
 	
-	$template = $template ? $this->find_template($template) : $this->find_template_for($model);
+	$template = $template ? $this->find_template($template) : $this->find_template_for($info->{model});
 	
 	return $this->render(
         $template,
         hashApply(
-            {
-                prefix => $prefix,
-                model => $model,
-	        },
+            $info,
             $args
         )
     );
@@ -197,22 +199,24 @@
 	
 	$env ||= {};
 	
+	my $ctx = ($this->root || $this)->clone();
+
 	my $out = eval {
-		$this->localise(
+		$ctx->localise(
             hashApply(
 	            {
 	            	aliases => $this->aliases || {},
-					root => $this->root || $this,
+					root => $this->root || $ctx,
 					modules => $this->modules || {},
 					cache => TypeKeyedCollection->new(),
 		            display => sub {
-		                $this->display(@_);
+		                $ctx->display(@_);
 		            },
 		            render => sub {
-		            	$this->render(@_);
+		            	$ctx->render(@_);
 		            },
 		            display_model => sub {
-		            	$this->display_model(@_);
+		            	$ctx->display_model(@_);
 		            },
 		            tt_cache => {}
 				},
@@ -220,11 +224,11 @@
             )
         );
 		
-		&$code($this);
+		&$code($ctx);
 	};
 	
 	my $e = $@;
-	$this->delocalise();
+	$ctx->delocalise();
 	
 	die $e if $e;
     
@@ -279,16 +283,23 @@
 }
 
 sub resolve_model {
-	my ($this,$prefix) = @_;
+	my ($this,$prefix,$args) = @_;
 	
 	die ArgException->new(prefix => "the prefix must be specified")
 	   unless defined $prefix;
 	
 	#TODO handle DOM models
 	
+	if (my $resolver = $this->resolver) {
+		return $this->$resolver($prefix,$args);
+	}
+	
 	my @comp = map { $_, 0 } grep length($_), split(/\.|\[(\d+)\]/, $prefix);
 	
-	return $this->stash->get(['model',0,@comp]);
+	return {
+		model => $this->stash->get(['model',0,@comp]),
+		prefix => $this->prefix ? $this->prefix . ".$prefix" : $prefix
+	};
 }
 
 sub find_template_for {