# HG changeset patch # User sergey # Date 1366375141 -14400 # Node ID 0a9d51cf6dfd14138054efbf52a2687acafc39a1 # Parent 5e4e7c8fbca19fa55f41da8292d34b54a177da6a *TTView: refactoring, document supports custom classes, layouts are become controls diff -r 5e4e7c8fbca1 -r 0a9d51cf6dfd Lib/IMPL/Web/View/TTDocument.pm --- a/Lib/IMPL/Web/View/TTDocument.pm Fri Apr 19 00:27:51 2013 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Fri Apr 19 16:39:01 2013 +0400 @@ -42,10 +42,8 @@ my ($this,$args) = @_; $args ||= {}; + $args->{document} = $this; - $this->context->localise(); # localise stash - my $documentContext = _clone_context( $this->context ); # create a new context - $this->context->stash->update({ document => sub { $this } }); @@ -53,37 +51,20 @@ my $text = eval { if ($this->layout) { - my $tlayout = $this->registry->loader->layout($this->layout) - or die OpException->new('The specified layout isn\'t found', $this->layout); - if(my $init = $tlayout->blocks->{INIT}) { - $this->context->process( - $init, - hashMerge( - $args, - { - template => $this->template - } - ) - ); - } + my $layout = $this->registry->Require(join('/',$this->layoutBase, $this->layout))->new(); + my $content = $this->next::method($args); - return $this->context->include( - $tlayout, - { - %{$args}, - content => $content, - this => $this, - template => $this->template - } - ); + return $layout->Render({ + content => $content, + template => $this->template, + document => $this + }); } else { return $this->next::method($args); } }; my $e = $@; - - $this->context->delocalise(); undef $this; diff -r 5e4e7c8fbca1 -r 0a9d51cf6dfd Lib/IMPL/Web/View/TTLoader.pm --- a/Lib/IMPL/Web/View/TTLoader.pm Fri Apr 19 00:27:51 2013 +0400 +++ b/Lib/IMPL/Web/View/TTLoader.pm Fri Apr 19 16:39:01 2013 +0400 @@ -90,6 +90,7 @@ my $factory = TTFactory->new($tt->class || TTDocument, $tt, $ctx, $name, $registry); $vars->{registry} = $registry; + $vars->{layoutBase} = $this->layoutBase; return $factory->new( $vars ); } @@ -115,19 +116,6 @@ return $tt; } -sub layout { - my ($this,$name) = @_; - - my $layout; - - if ($this->layoutBase) { - $layout = $this->layoutBase . "/"; - } - - $layout .= $name; - return $this->template($layout); -} - sub _appendExt { my ($this,$name) = @_;