comparison Lib/IMPL/Web/View/TTFactory.pm @ 343:9bdccdf1f50b

Added a templates context
author cin
date Fri, 13 Sep 2013 12:53:15 +0400
parents 97628101b765
children
comparison
equal deleted inserted replaced
342:1090c1dd7429 343:9bdccdf1f50b
113 } 113 }
114 }); 114 });
115 $this->LoadLabelsToContext($context); 115 $this->LoadLabelsToContext($context);
116 } 116 }
117 117
118 #TODO optimize labels loading for extended classes
119 sub LoadLabelsToContext { 118 sub LoadLabelsToContext {
120 my ($this,$context) = @_; 119 my ($this,$context) = @_;
121 120
122 my %vars; 121 my %vars;
123 122
129 my $flabels = "$fname.labels"; 128 my $flabels = "$fname.labels";
130 129
131 if (-f $flabels) { 130 if (-f $flabels) {
132 131
133 my %labels; 132 my %labels;
134 $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels"); 133 $labels{default} = IMPL::Resources::Strings::ParseStringsMap($flabels);
135 134
136 while(my($label,$text) = each %{$labels{default}}) { 135 while(my($label,$text) = each %{$labels{default}}) {
137 $vars{$label} = sub { 136 $vars{$label} = sub {
138 my ($params) = @_; 137 my ($params) = @_;
139 my $locale = Resources->currentLocale; 138 my $locale = Resources->currentLocale;
163 $refProps = shift; 162 $refProps = shift;
164 $refProps->{name} ||= $name; 163 $refProps->{name} ||= $name;
165 } 164 }
166 165
167 $refProps->{factory} = $this; 166 $refProps->{factory} = $this;
168 my $ctx = $this->CloneContext(); 167 my $ctx = $this->context->clone();
169 168
170 return ($this->template, $ctx, $refProps); 169 return ($this->template, $ctx, $refProps);
171 } 170 }
172 171
173 sub CreateObject { 172 sub CreateObject {
174 my $this = shift; 173 my $this = shift;
175 174
176 $this->activation eq 'singleton' ? 175 $this->activation eq 'singleton' ?
177 $this->_instance || $this->_instance($this->next::method(@_)) : 176 $this->_instance || $this->_instance($this->next::method(@_)) :
178 $this->next::method(@_); 177 $this->next::method(@_);
179 }
180
181 sub CloneContext {
182 my ($this) = @_;
183
184 $this->context->localise();
185
186 my $args = { %{$this->context} };
187 delete $args->{CONFIG};
188
189 $this->context->delocalise();
190
191 return Template::Context->new($args);
192 } 178 }
193 179
194 sub Render { 180 sub Render {
195 my ($this, $args) = @_; 181 my ($this, $args) = @_;
196 182
249 235
250 =head1 DESCRIPTION 236 =head1 DESCRIPTION
251 237
252 C< Inherits L<IMPL::Object::Factory> > 238 C< Inherits L<IMPL::Object::Factory> >
253 239
240 Соединяет в себе шаблон и заранее подготовленный контекст, который будет базой
241 для создаваемых элементов управления.
242
254 =head1 MEMBERS 243 =head1 MEMBERS
255 244
256 =over 245 =over
257 246
258 =item C<[get,set]template> 247 =item C<[get,set]template>