Mercurial > pub > Impl
changeset 286:d357b5d85d25
*TTView refactoring
author | sergey |
---|---|
date | Mon, 18 Feb 2013 14:46:06 +0400 |
parents | 546957c50a36 |
children | 2d253e6e4a88 |
files | Lib/IMPL/Web/View/TTDocument.pm _test/Resources/TTView/Layout/default.tt _test/Test/Web/View.pm |
diffstat | 3 files changed, 53 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm Mon Feb 18 02:55:59 2013 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Mon Feb 18 14:46:06 2013 +0400 @@ -101,8 +101,6 @@ Loader->safe->Require($template->class); } - my @parts = split(/\/+/,$control); - $this->controls->{$control} = $factory; return $factory; @@ -121,8 +119,21 @@ my $newArgs = hashMerge($this->creationArgs, $args); if ($this->layout) { + my $tlayout = $this->loader->layout($this->layout); + if(my $init = $tlayout->blocks->{INIT}) { + $this->context->process( + $init, + hashMerge( + $newArgs, + { + this => $this, + template => $this->template + } + ) + ); + } return $this->context->include( - $this->loader->layout($this->layout), + $tlayout, { %{$newArgs}, content => $this->RenderContent($newArgs),
--- a/_test/Resources/TTView/Layout/default.tt Mon Feb 18 02:55:59 2013 +0400 +++ b/_test/Resources/TTView/Layout/default.tt Mon Feb 18 14:46:06 2013 +0400 @@ -1,4 +1,9 @@ [% view.mode = 'default' %] +[% + BLOCK INIT; + dojo = { require => [] }; + END; +%] <html> <head> <title>$site.name - [% document.title || template.title %]</title>
--- a/_test/Test/Web/View.pm Mon Feb 18 02:55:59 2013 +0400 +++ b/_test/Test/Web/View.pm Mon Feb 18 14:46:06 2013 +0400 @@ -11,7 +11,7 @@ use Scalar::Util qw(weaken); use IMPL::lang; -use IMPL::Test qw(assert test GetCallerSourceLine); +use IMPL::Test qw(assert assertarray test GetCallerSourceLine); use IMPL::Web::View::TTLoader(); use constant { @@ -186,6 +186,39 @@ #assert($text eq $expected, '$doc->Render(): Bad output', "Got: $text", "Expected: $expected"); }; +test TestDocumentsIsolation => sub { + my $this = shift; + + my $loader = $this->CreateLoader(); + + my $doc = $loader->document('simple'); + + assert(ref $loader->context->stash->get([ 'dojo', 0, 'require', 0]) eq 'ARRAY'); + assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]); + assert($loader->context->stash != $doc->stash); + + assert(defined $doc); + + # only root stash variables can be localized, to avoid modifying dojo we + # need to replace it completely + $doc->context->process(\q{ + [% SET dojo = { require => [] } %] + [% dojo.require.push('dijit/form/TextBox') %] + [% SET user = 'dummy guy' %] + }); + + assert($doc->context->stash->get('user') eq 'dummy guy'); + assert($loader->context->stash->get('user') eq 'test_user'); + assertarray($doc->context->stash->get([ 'dojo', 0, 'require', 0]),['dijit/form/TextBox']); + assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]); + + my $text = $doc->Render(); + + my $doc2 = $loader->document('simple'); + + assertarray($doc2->context->stash->get([ 'dojo', 0, 'require', 0]),[]); +}; + test TestMemoryLeaks => sub { my ($this) = @_;