# HG changeset patch # User cin # Date 1379062395 -14400 # Node ID 9bdccdf1f50bb64289beb1ec8d03560dafeccfca # Parent 1090c1dd7429df4569577bfe5fd499b3ceb0df52 Added a templates context diff -r 1090c1dd7429 -r 9bdccdf1f50b Lib/IMPL/Web/View/TTContext.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/Web/View/TTContext.pm Fri Sep 13 12:53:15 2013 +0400 @@ -0,0 +1,27 @@ +package IMPL::Web::View::TTContext; +use strict; +use Template::Base; + +use IMPL::declare { + base => { + 'Template::Context' => '@_' + } +}; + +sub clone { + my $this = shift; + + $this->localise(); + + my $args = { %{$this} }; + + $this->delocalise(); + + my $class = typeof($this); + + delete $args->{CONFIG}; + + return $class->new($args); +} + +1; \ No newline at end of file diff -r 1090c1dd7429 -r 9bdccdf1f50b Lib/IMPL/Web/View/TTControl.pm --- a/Lib/IMPL/Web/View/TTControl.pm Wed Jul 03 03:53:12 2013 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Fri Sep 13 12:53:15 2013 +0400 @@ -7,7 +7,7 @@ use IMPL::declare { require => { TemplateDocument => 'Template::Document', - TTContext => 'Template::Context', + TTContext => 'IMPL::Web::View::TTContext', Exception => 'IMPL::Exception', ArgumentException => '-IMPL::InvalidArgumentException', OperationException => '-IMPL::InvalidOperationException' @@ -138,19 +138,6 @@ } } -sub CloneContext { - my ($this) = @_; - - $this->context->localise(); - - my $args = { %{$this->context} }; - delete $args->{CONFIG}; - - $this->context->delocalise(); - - return TTContext->new($args); -} - sub CreateControlFromTemplate { my ($this,$template,$args) = @_; @@ -163,7 +150,7 @@ } else { return $this->new( $template, - $this->CloneContext(), + $this->context->clone(), $args ); } diff -r 1090c1dd7429 -r 9bdccdf1f50b Lib/IMPL/Web/View/TTDocument.pm --- a/Lib/IMPL/Web/View/TTDocument.pm Wed Jul 03 03:53:12 2013 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Fri Sep 13 12:53:15 2013 +0400 @@ -76,13 +76,6 @@ $this->registry->Dispose() if $this->registry; } -sub _clone_context { - my $args = { %{shift || {}} }; - delete $args->{CONFIG}; - - return Template::Context->new($args); -} - 1; __END__ @@ -102,6 +95,31 @@ =head1 DESCRIPTION +Позволяет строить представления при помощи Template Toolkit, при этом расширяет +шаблоны до элементов управления, чтобы была возмлжность реализации функционала +средствами C. + +Структура представления. + +=begin text + + + view + |- document.tt + |-+items + | |- title.tt + | |- item.tt + | + |-+layouts + |- + +=end text + +=begin text + + + +=end text + =over diff -r 1090c1dd7429 -r 9bdccdf1f50b Lib/IMPL/Web/View/TTFactory.pm --- a/Lib/IMPL/Web/View/TTFactory.pm Wed Jul 03 03:53:12 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Fri Sep 13 12:53:15 2013 +0400 @@ -115,7 +115,6 @@ $this->LoadLabelsToContext($context); } -#TODO optimize labels loading for extended classes sub LoadLabelsToContext { my ($this,$context) = @_; @@ -131,7 +130,7 @@ if (-f $flabels) { my %labels; - $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels"); + $labels{default} = IMPL::Resources::Strings::ParseStringsMap($flabels); while(my($label,$text) = each %{$labels{default}}) { $vars{$label} = sub { @@ -165,7 +164,7 @@ } $refProps->{factory} = $this; - my $ctx = $this->CloneContext(); + my $ctx = $this->context->clone(); return ($this->template, $ctx, $refProps); } @@ -178,19 +177,6 @@ $this->next::method(@_); } -sub CloneContext { - my ($this) = @_; - - $this->context->localise(); - - my $args = { %{$this->context} }; - delete $args->{CONFIG}; - - $this->context->delocalise(); - - return Template::Context->new($args); -} - sub Render { my ($this, $args) = @_; @@ -251,6 +237,9 @@ C< Inherits L > +Соединяет в себе шаблон и заранее подготовленный контекст, который будет базой +для создаваемых элементов управления. + =head1 MEMBERS =over diff -r 1090c1dd7429 -r 9bdccdf1f50b Lib/IMPL/Web/View/TTLoader.pm --- a/Lib/IMPL/Web/View/TTLoader.pm Wed Jul 03 03:53:12 2013 +0400 +++ b/Lib/IMPL/Web/View/TTLoader.pm Fri Sep 13 12:53:15 2013 +0400 @@ -8,7 +8,7 @@ use IMPL::declare { require => { Provider => 'Template::Provider', - Context => 'Template::Context', + Context => 'IMPL::Web::View::TTContext', TTRegistry => 'IMPL::Web::View::TTRegistry', TTFactory => 'IMPL::Web::View::TTFactory', TTDocument => '-IMPL::Web::View::TTDocument', @@ -82,9 +82,7 @@ my $opts = { %{ $this->options } }; - $this->context->localise(); - my $ctx = _clone_context($this->context); - $this->context->delocalise(); + my $ctx = $this->context->clone(); $ctx->stash->update($vars); @@ -157,13 +155,6 @@ } } -sub _clone_context { - my $args = { %{shift || {}} }; - delete $args->{CONFIG}; - - return Template::Context->new($args); -} - 1; __END__