# HG changeset patch # User sergey # Date 1333425265 -14400 # Node ID 927653d01f4f29fe811b6bf838d4037cc452024f # Parent 6c0fee769b0cdd6061bd32b80915ed8f9cf8e22d TTControl::AUTOLOAD now accesses nodeProperties Added TTControl::renderBlock property to access RENDER block of the template diff -r 6c0fee769b0c -r 927653d01f4f Lib/IMPL/Web/View/TTControl.pm --- a/Lib/IMPL/Web/View/TTControl.pm Fri Mar 30 16:40:34 2012 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Tue Apr 03 07:54:25 2012 +0400 @@ -10,7 +10,12 @@ IMPL::DOM::Node ); -my $nextId = 1; +{ + my $nextId = 1; + sub _GetNextId { + return $nextId++; + } +} BEGIN { @@ -24,6 +29,8 @@ sub CTOR { my ($this,$name,$template,$context,$refProps) = @_; + $name ||= "control"; + $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); @@ -31,6 +38,8 @@ $context->process($ctor, { this => $this } ); } + $this->id($name . "-" . _GetNextId()) unless $this->id; + } our %CTOR = ( @@ -40,11 +49,28 @@ } ); -sub Render { - my ($this) = @_; +sub templateVars { + my $this = shift; + my $name = shift; - if(my $body = $this->template->blocks->{RENDER} ) { - return $this->context->process( $body, { this => $this } ); + if (@_) { + return $this->context->stash->set($name, shift); + } else { + return $this->context->stash->get($name); + } +} + +sub renderBlock { + $_[0]->template->blocks->{RENDER}; +} + +sub Render { + my ($this,$args) = @_; + + $args = {} unless ref $args eq 'HASH'; + + if(my $body = $this->renderBlock ) { + return $this->context->include( $body, { %$args, this => $this, template => $this->template } ); } else { return ""; } @@ -57,10 +83,9 @@ return if $method eq 'DESTROY'; - my $res = $_[0]->template->$method(); + my $this = shift; - return defined($res) ? $res : $_[0]->context->stash->get($method); - + $this->nodeProperty(@_); } 1; @@ -92,7 +117,41 @@ =head3 RENDER - +Данный блок выполняется при вызове метода C, вывод данного блока и есть результат отображения элемента управления. + +=head2 TEMPLATE VARS + +Каждый шаблон имеет собственное пространство имен, унаследованное от пространства имен фабрики элементов (которая в свою очередь наследует контекст документа). +В шаблоне могут определяться новые переменные, которые разделяются между блоками. Также доступны стандартные переменные + +=over + +=item * C ссылка на объект элемента управления + +=item * C ссылка на текущий шаблон, устанавливается автоматически в методе C. + +=item * C