annotate Lib/IMPL/Web/View/TTFactory.pm @ 338:c78dfbe658bd

improved string maps loading for TT documents
author cin
date Sat, 15 Jun 2013 02:32:11 +0400
parents f4e14f32cf54
children 97628101b765
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
1 package IMPL::Web::View::TTFactory;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
2 use strict;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
3
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
4 use Template::Context();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
5
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
6 use Carp qw(carp);
312
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
7 use IMPL::lang qw(:hash is);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
8 use IMPL::Exception();
192
a9faf883cdce IMPL::Web::View refactoring
cin
parents: 191
diff changeset
9 use Scalar::Util qw(weaken);
336
cin
parents: 312
diff changeset
10 use IMPL::Resources::Format qw(FormatMessage);
cin
parents: 312
diff changeset
11 use IMPL::Resources::Strings();
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
12
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
13
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
14 use IMPL::Const qw(:prop);
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
15 use IMPL::declare {
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
16 require => {
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
17 Loader => 'IMPL::Code::Loader',
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
18 Resources => 'IMPL::Resources',
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
19 OpException => '-IMPL::InvalidOperationException',
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
20 ArgException => '-IMPL::InvalidArgumentException'
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
21 },
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
22 base => [
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
23 'IMPL::Object::Factory' => sub {
309
cin
parents: 305
diff changeset
24 shift;
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
25 }
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
26 ],
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
27 props => [
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
28 template => PROP_RW,
312
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
29 activation => PROP_RW,
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
30 context => PROP_RW,
300
cin
parents: 298
diff changeset
31 baseLocation => PROP_RW,
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
32 base => PROP_RW,
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 301
diff changeset
33 registry => PROP_RO,
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
34 blocks => PROP_RO,
336
cin
parents: 312
diff changeset
35 path => PROP_RO,
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
36 _instance => PROP_RW,
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
37 _labels => PROP_RW
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
38 ]
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 232
diff changeset
39 };
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
40
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
41 sub CTOR {
309
cin
parents: 305
diff changeset
42 my ($this,$class,$template,$context,$path,$registry) = @_;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
43
309
cin
parents: 305
diff changeset
44 die ArgException->new("A control class must be specified")
cin
parents: 305
diff changeset
45 unless $class;
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
46 die ArgException->new("A template is required") unless $template;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
47
309
cin
parents: 305
diff changeset
48 Loader->safe->Require($class)
cin
parents: 305
diff changeset
49 unless ref $class ;
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
50
287
2d253e6e4a88 *TTView refactoring
cin
parents: 280
diff changeset
51 $context ||= new Template::Context();
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 301
diff changeset
52 my $baseLocation = join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) );
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
53
312
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
54 $this->activation($template->activation || 'new');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
55 $this->template($template);
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
56 $this->context($context);
300
cin
parents: 298
diff changeset
57 $this->baseLocation($baseLocation);
336
cin
parents: 312
diff changeset
58 $this->path($path);
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 301
diff changeset
59 $this->registry($registry);
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
60
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
61 if (my $baseTplName = $template->extends) {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
62 $baseTplName =~ s{^\./}{$baseLocation/};
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
63
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 301
diff changeset
64 my $base = $registry->Require($baseTplName)
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
65 or die OpException->new("The specified base template isn't found");
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
66
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
67 $this->base($base);
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
68
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
69 $this->blocks(hashMerge($base->blocks, $template->blocks));
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
70
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
71 # блок BASE должен меняться в процессе выполнения, в зависимости от
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
72 # шаблона, который рендерится, по мере перехода в BASE
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
73
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
74 my @baseStack;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
75
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
76 $this->blocks->{BASE} = sub {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
77 my $ctx = shift;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
78
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
79 die OpException->new("This tamplate doesn't have a base template")
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
80 unless $base;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
81
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
82 push @baseStack, $base;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
83 my $block = $base->template->block;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
84
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
85 $base = $base->base;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
86
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
87 my $result = eval {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
88 $ctx->process($block);
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
89 };
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
90 my $e = $@;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
91
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
92 $base = pop @baseStack;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
93
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
94 die $e if $e;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
95 return $result;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
96 };
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
97 } else {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
98 $this->blocks( $template->blocks );
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
99 }
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
100
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
101 if(my $blocks = $this->blocks) {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
102 while (my ($name,$block) = each %$blocks) {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
103 $context->define_block($name,$block);
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
104 }
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
105 }
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
106
336
cin
parents: 312
diff changeset
107 $context->stash->update({
cin
parents: 312
diff changeset
108 require => sub {
cin
parents: 312
diff changeset
109 my ($module) = @_;
cin
parents: 312
diff changeset
110
cin
parents: 312
diff changeset
111 $module =~ s/^\.\//$baseLocation\//;
cin
parents: 312
diff changeset
112 return $registry->Require($module);
cin
parents: 312
diff changeset
113 }
cin
parents: 312
diff changeset
114 });
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
115 $this->LoadLabelsToContext($context);
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
116 }
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
117
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
118 #TODO optimize labels loading for extended classes
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
119 sub LoadLabelsToContext {
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
120 my ($this,$context) = @_;
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
121
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
122 my %vars;
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
123
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
124 %vars = %{$this->base->_labels || {}}
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
125 if $this->base;
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
126 $this->_labels(\%vars);
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
127
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
128 if(my $fname = $this->registry->loader->ResolveFileName($this->path)) {
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
129 my $flabels = "$fname.labels";
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
130
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
131 if (-f $flabels) {
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
132
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
133 my %labels;
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
134 $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels");
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
135
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
136 while(my($label,$text) = each %{$labels{default}}) {
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
137 warn "LABEL: $label";
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
138 $vars{$label} = sub {
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
139 my ($params) = @_;
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
140 my $locale = Resources->currentLocale;
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
141
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
142 unless ($labels{$locale}) {
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
143 $labels{$locale} = -f "$fname.$locale" ?
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
144 IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") :
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
145 {};
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
146 }
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
147
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
148 return FormatMessage(($labels{$locale}{$label} || $text),$params);
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
149 }
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
150 }
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
151
337
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
152 }
f4e14f32cf54 fixed bugs with string and local $_
cin
parents: 336
diff changeset
153 }
338
c78dfbe658bd improved string maps loading for TT documents
cin
parents: 337
diff changeset
154 $context->stash->update(\%vars);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157 sub MergeParameters {
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
158 my $this = shift;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
159 my $refProps = shift || {};
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
160
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
161 unless (ref($refProps) eq 'HASH') {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
162 carp "Passing control name through the first parameter is deprecated";
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
163 my $name = $refProps;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
164 $refProps = shift;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
165 $refProps->{name} ||= $name;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
166 }
291
5d14baa35790 *TTView: fixed template selectors mechanism
cin
parents: 290
diff changeset
167
298
78f767765706 TT view refactoring
cin
parents: 296
diff changeset
168 $refProps->{factory} = $this;
300
cin
parents: 298
diff changeset
169 my $ctx = $this->CloneContext();
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
170
300
cin
parents: 298
diff changeset
171 return ($this->template, $ctx, $refProps);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
172 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
173
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
174 sub CreateObject {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
175 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
176
312
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
177 $this->activation eq 'singleton' ?
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
178 $this->_instance || $this->_instance($this->next::method(@_)) :
75a78cbf7dcf View refactoring: INIT blocks are deprecated
cin
parents: 309
diff changeset
179 $this->next::method(@_);
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
180 }
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
181
300
cin
parents: 298
diff changeset
182 sub CloneContext {
cin
parents: 298
diff changeset
183 my ($this) = @_;
cin
parents: 298
diff changeset
184
cin
parents: 298
diff changeset
185 $this->context->localise();
cin
parents: 298
diff changeset
186
cin
parents: 298
diff changeset
187 my $args = { %{$this->context} };
289
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
188 delete $args->{CONFIG};
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
189
300
cin
parents: 298
diff changeset
190 $this->context->delocalise();
cin
parents: 298
diff changeset
191
289
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
192 return Template::Context->new($args);
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
193 }
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
194
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
195 sub Render {
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
196 my ($this, $args) = @_;
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
197
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
198 return $this->new()->Render($args);
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
199 }
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
200
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
201 sub save {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
202 die new IMPL::NotImplementedException("This class doesn't support serialization");
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
203 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
204
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
205 sub restore {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
206 die new IMPL::NotImplementedException("This class doesn't support serialization");
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
207 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
208
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
209 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
210
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
211 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
212
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
213 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
214
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
215 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
216
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
217 C<IMPL::Web::View::TTFactory> - фабрика элементов управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
218
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
219 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
220
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
221 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
222
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
223 my $factory = new IMPL::Web::View::TTFactory(
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 267
diff changeset
224 'IMPL::Web::View::TTControl',
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
225 $doc,
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
226 $context,
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
227 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
228 TRIM => 1
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
229 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
230 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
231 myprop => 'my value'
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
232 },
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
233 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
234
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
235 my $input1 = $factory->new('login', { class => "required" } );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
236
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
237 my $propval = $input->nodeProperty('myprop'); # 'my value'
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
238
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
239 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
240
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
241 =begin text
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
242
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
243 [%
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
244 this.appendChild(
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
245 my.org.input.new('login', class = this.errors('login') ? "invalid" : "" )
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
246 );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
247 %]
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
248
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
249 =end text
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
250
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
251 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
252
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
253 C< Inherits L<IMPL::Object::Factory> >
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
254
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
255 =head1 MEMBERS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
256
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
257 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
258
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
259 =item C<[get,set]template>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
260
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
261 Документ C<Template::Document> который описывает элемент управления. См. C<IMPL::Web::View::TTControl>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
262
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
263 =item C<[get,set]context>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
264
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
265 Контекст фабрики элементов управления, в этом контексте выполняет шаблон элемента управления при загрузке.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
266 Далее в этом контексте будет выполнен блок инициализации при создании первого элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
267
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
268 =item C<[get,set]opts>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
269
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
270 Параметры контекста элемента управления (ссылка на хеш). Каждый элемент управления при создании получает свой контекст,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
271 который создает с данными параметрами и хранилищем переменных, дочерним к контексту фабрики.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
272
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
273 =item C<[get,set]nodeProperties>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
274
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
275 Ссылка на хеш со значениями свойств по умолчанию для создаваемого элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
276
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
277 =item C<[get]instances>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
278
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
279 Количество созданных элементов управления данной фабрикой
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
280
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
281 =item C<[override]MergeParameters($name,$nodeProps)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
282
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
283 Превращает значения переданные методу C<new> фабрики в параметры для создания элемента управления.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
284
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
285 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
286
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
287 =item C<$name>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
288
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
289 Имя создаваемого узла (C<nodeName>).
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
290
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
291 =item C<$nodeProps>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
292
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
293 Ссылка на шех со значениями свойств узла. Данные значения будут совмещены со значениями из свойства C<nodeProperties>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
294
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
295 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
296
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
297 =item C<[override]CreateObject(@params)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
298
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
299 Создает экземпляр элемента управления стандартным образом. Учитывает количество экземпляров и если это первый,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
300 то производит дополнительную инициализацию контекста выполнив блок шаблона C<INIT>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
301
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 186
diff changeset
302 =item C<[inherited]new($name,$nodeProps)>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
303
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
304 Создает элемент управления с указанным именем и набором свойств.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
305
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
306 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
307
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
308 =cut