# HG changeset patch
# User sergey
# Date 1361184366 -14400
# Node ID d357b5d85d25cd15d1ddac971c94c8f5ec348848
# Parent 546957c50a3630160812f3375e8a4b82fd0f5332
*TTView refactoring
diff -r 546957c50a36 -r d357b5d85d25 Lib/IMPL/Web/View/TTDocument.pm
--- 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),
diff -r 546957c50a36 -r d357b5d85d25 _test/Resources/TTView/Layout/default.tt
--- 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;
+%]
$site.name - [% document.title || template.title %]
diff -r 546957c50a36 -r d357b5d85d25 _test/Test/Web/View.pm
--- 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) = @_;