# HG changeset patch # User cin # Date 1381930120 -14400 # Node ID 9330835535b9f0aebc1d5bb85bf9a9fb86b9855a # Parent feeb3bc4a818b9a57d134fc5ed90c3c233ec0cd6 fixed view double rendering diff -r feeb3bc4a818 -r 9330835535b9 Lib/IMPL/Web/Handler/View.pm --- a/Lib/IMPL/Web/Handler/View.pm Fri Oct 11 15:49:04 2013 +0400 +++ b/Lib/IMPL/Web/Handler/View.pm Wed Oct 16 17:28:40 2013 +0400 @@ -60,12 +60,6 @@ layout => $this->layout }; - $this->view->display( - $model, - $template || $this->SelectView( $action, ref $model ), - $vars - ); - my %responseParams = ( type => $this->contentType, charset => $this->contentCharset, diff -r feeb3bc4a818 -r 9330835535b9 Lib/IMPL/Web/View/TTContext.pm --- 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 { diff -r feeb3bc4a818 -r 9330835535b9 Lib/IMPL/Web/View/TTView.pm --- a/Lib/IMPL/Web/View/TTView.pm Fri Oct 11 15:49:04 2013 +0400 +++ b/Lib/IMPL/Web/View/TTView.pm Wed Oct 16 17:28:40 2013 +0400 @@ -41,26 +41,33 @@ if ($layout) { return $ctx->invoke_environment( sub { - return $ctx->render($layout,$args); + return shift->render( + $layout, + hashMerge( + $args, + { + content => sub { + $ctx->invoke_environment( + sub { + return shift->display_model($model,$template,$args); + }, + { + base => $this->viewBase + } + ) + } + } + ) + ); # render }, { base => $this->layoutBase, - content => sub { - $ctx->invoke_environment( - sub { - return shift->display_model($model,$template,$args); - }, - { - base => $this->viewBase - } - ) - } } ); } else { return $ctx->invoke_environment( sub { - return $ctx->display_model($model,$template,$args); + return shift->display_model($model,$template,$args); }, { base => $this->viewBase