annotate Lib/IMPL/Web/View/TTContext.pm @ 373:3ca44e23fd1f

implemented new web resource
author cin
date Wed, 25 Dec 2013 17:29:38 +0400
parents d5c8b955bf8d
children 1eca08048ba9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
1 package IMPL::Web::View::TTContext;
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
2 use strict;
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
3 use Template::Base;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
4 use Carp qw(carp);
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
5 use File::Spec();
86b470004d47 added lables loading
cin
parents: 348
diff changeset
6 use IMPL::Resources::Format qw(FormatMessage);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
7 use IMPL::Resources::Strings();
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
8
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
9 use IMPL::Exception();
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
10 use IMPL::lang qw(is typeof hashApply hashMerge);
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
11 use IMPL::declare {
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
12 require => {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
13 Document => '-Template::Document',
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
14 TypeKeyedCollection => 'IMPL::TypeKeyedCollection',
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
15 ArgException => '-IMPL::InvalidArgumentException',
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
16 Resources => 'IMPL::Resources',
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
17 Loader => 'IMPL::Code::Loader',
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
18 MetadataBase => '-IMPL::Web::View::Metadata::BaseMeta',
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
19 Metadata => 'IMPL::Web::View::Metadata::ObjectMeta'
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
20 },
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
21 base => [
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
22 'Template::Context' => '@_'
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
23 ]
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
24 };
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
25
347
cin
parents: 346
diff changeset
26 BEGIN {
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
27 no strict 'refs';
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
28 # modules is a global (for the whole document) templates cache
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
29 # tt_cache is a local (for the current context only) templtes cache
347
cin
parents: 346
diff changeset
30 foreach my $prop (qw(
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
31 root
347
cin
parents: 346
diff changeset
32 base
cin
parents: 346
diff changeset
33 tt_ext
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
34 tt_cache
347
cin
parents: 346
diff changeset
35 parent
cin
parents: 346
diff changeset
36 prefix
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
37 cache
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
38 includes
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
39 modules
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
40 aliases
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
41
356
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
42 id
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
43 metadata
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
44 model
347
cin
parents: 346
diff changeset
45 )) {
cin
parents: 346
diff changeset
46 my $t = $prop;
cin
parents: 346
diff changeset
47
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
48 *{__PACKAGE__ . '::' . $prop} = sub {
347
cin
parents: 346
diff changeset
49 my $this = shift;
cin
parents: 346
diff changeset
50 return @_ ? $this->stash->set($t, @_) : $this->stash->get($t);
cin
parents: 346
diff changeset
51 }
cin
parents: 346
diff changeset
52 }
cin
parents: 346
diff changeset
53 }
cin
parents: 346
diff changeset
54
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
55 sub clone {
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
56 my $this = shift;
347
cin
parents: 346
diff changeset
57 my $params = shift;
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
58
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
59 $this->localise();
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
60
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
61 my $args = { %{$this} };
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
62
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
63 $this->delocalise();
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
64
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
65 my $class = ref($this);
343
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
66
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
67 delete $args->{CONFIG};
9bdccdf1f50b Added a templates context
cin
parents:
diff changeset
68
347
cin
parents: 346
diff changeset
69 my $clone = $class->new($args);
cin
parents: 346
diff changeset
70
cin
parents: 346
diff changeset
71 $clone->stash->update($params) if $params;
cin
parents: 346
diff changeset
72
cin
parents: 346
diff changeset
73 return $clone;
345
cin
parents: 343
diff changeset
74 }
cin
parents: 343
diff changeset
75
356
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
76 sub get_next_id {
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
77 my ($this) = @_;
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
78
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
79 my $id = $this->stash->get('document.nextId') || 0;
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
80 $this->stash->set('document.nextId', $id + 1);
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
81 return "w-$id";
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
82 }
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
83
345
cin
parents: 343
diff changeset
84 sub find_template {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
85 my ($this,$name, $nothrow) = @_;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
86
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
87 my $cache = $this->tt_cache;
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
88
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
89 $this->tt_cache($cache = {}) unless $cache;
345
cin
parents: 343
diff changeset
90
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
91 if(my $tpl = $cache->{$name}) {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
92 return $tpl;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
93 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
94
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
95 my @inc = ($this->base, @{$this->includes || []});
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
96
345
cin
parents: 343
diff changeset
97 my $ext = $this->tt_ext || "";
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
98
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
99 my $file;
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
100
345
cin
parents: 343
diff changeset
101 foreach my $dir (@inc) {
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
102 $file = $dir ? "$dir/$name" : $name;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
103
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
104 my $base = join('/',splice([split(/\/+/,$file)],0,-1));
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
105
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
106 $file = $ext ? "$file.$ext" : $file;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
107
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
108 if (exists($this->modules->{$file})) {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
109 my $info = $this->modules->{$file};
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
110 return $cache->{$name} = $info
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
111 if $info;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
112 } else {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
113 if( my $tt = eval { $this->template($file) } ) {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
114 my $class;
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
115 if ($class = $tt->class) {
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
116 $class = $this->aliases->{$class} || $class;
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
117 Loader->safe->Require($class);
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
118 }
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
119 my $info = {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
120 base => $base,
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
121 labels => $this->load_labels($file),
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
122 template => $tt,
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
123 initialized => 0,
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
124 class => $class
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
125 };
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
126 $this->modules->{$file} = $info;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
127 return $cache->{$name} = $info;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
128 } else {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
129 my $err = $@;
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
130
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
131 for(my $t = $err; is($t,'Template::Exception'); $t = $t->info ) {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
132 die $err unless $t->type eq Template::Constants::ERROR_FILE;
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
133 }
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
134 $this->modules->{$file} = undef;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
135 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
136 }
345
cin
parents: 343
diff changeset
137 }
cin
parents: 343
diff changeset
138
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
139 $this->throw(Template::Constants::ERROR_FILE, "$name: not found")
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
140 unless $nothrow;
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
141 return;
345
cin
parents: 343
diff changeset
142 }
cin
parents: 343
diff changeset
143
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
144 sub display_for {
347
cin
parents: 346
diff changeset
145 my $this = shift;
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
146 my $path = shift;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
147 my ($template, $args);
347
cin
parents: 346
diff changeset
148
cin
parents: 346
diff changeset
149 if (ref $_[0] eq 'HASH') {
cin
parents: 346
diff changeset
150 $args = shift;
cin
parents: 346
diff changeset
151 } else {
cin
parents: 346
diff changeset
152 $template = shift;
cin
parents: 346
diff changeset
153 $args = shift;
cin
parents: 346
diff changeset
154 }
cin
parents: 346
diff changeset
155
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
156 my $prefix = $this->prefix;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
157
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
158 my $info;
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
159 my $meta = $this->resolve_model($path,$args)
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
160 or return "[not found '$path']";
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
161
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
162 $info->{prefix} = join('.', grep($_, $prefix, $path));
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
163 $info->{model} = $meta->model;
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
164 $info->{metadata} = $meta;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
165
355
8dfb9df07d02 added support for the custom resolvers for the TTView
sergey
parents: 354
diff changeset
166 $template ||= $info->{template};
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
167 $template = $template ? $this->find_template($template) : $this->find_template_for($info->{metadata});
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
168
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
169 return $this->render(
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
170 $template,
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
171 hashApply(
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
172 $info,
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
173 $args
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
174 )
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
175 );
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
176 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
177
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
178 sub display_model {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
179 my $this = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
180 my $model = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
181 my ($template, $args);
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
182
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
183 if (ref $_[0] eq 'HASH') {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
184 $args = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
185 } else {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
186 $template = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
187 $args = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
188 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
189
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
190 #copy
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
191 $args = { %{$args || {}} };
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
192
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
193 $args->{prefix} = join('.',grep($_,$this->prefix,$args->{path}))
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
194 unless defined $args->{prefix};
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
195
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
196 if (is($model,MetadataBase)) {
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
197 $args->{model} = $model->model;
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
198 $args->{metadata} = $model;
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
199 } else {
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
200 $args->{model} = $model;
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
201 $args->{metadata} = Metadata->GetMetadataForModel($model);
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
202 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
203
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
204 $template = $template ? $this->find_template($template) : $this->find_template_for($args->{metadata});
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
205
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
206 return $this->render(
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
207 $template,
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
208 $args
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
209 );
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
210 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
211
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
212 # обеспечивает необходимый уровень изоляции между контекстами
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
213 # $code - код, который нужно выполнить в новом контексте
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
214 # $env - хеш с переменными, которые будут переданы в новый контекст
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
215 # в процессе будет создан клон корневого контекста, со всеми его свойствами
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
216 # затем новый контекст будет локализован и в него будут добавлены новые переменные из $env
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
217 # созданный контекст будет передан параметром в $code
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
218 sub invoke_environment {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
219 my ($this,$code,$env) = @_;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
220
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
221 $env ||= {};
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
222
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
223 my $ctx = ($this->root || $this)->clone();
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
224
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
225 my @includes = @{$this->includes || []};
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
226
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
227 if ($this->base) {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
228 unshift @includes, $this->base;
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
229 }
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
230
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
231 my $out = eval {
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
232 $ctx->localise(
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
233 hashApply(
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
234 {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
235 includes => \@includes,
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
236 aliases => $this->aliases || {},
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
237 root => $this->root || $ctx,
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
238 modules => $this->modules || {},
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
239 cache => TypeKeyedCollection->new(),
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
240 display_for => sub {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
241 $ctx->display_for(@_);
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
242 },
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
243 render => sub {
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
244 $ctx->render(@_);
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
245 },
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
246 display_model => sub {
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
247 $ctx->display_model(@_);
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
248 },
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
249 tt_cache => {}
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
250 },
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
251 $env
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
252 )
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
253 );
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
254
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
255 &$code($ctx);
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
256 };
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
257
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
258 my $e = $@;
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
259 $ctx->delocalise();
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
260
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
261 die $e if $e;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
262
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
263 return $out;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
264 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
265
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
266 # использует указанный шаблон для создания фрагмента документа
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
267 # шаблон может быть как именем, так и хешем, содержащим информацию
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
268 # о шаблоне.
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
269 # отдельно следует отметить, что данный метод создает новый контекст
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
270 # для выполнения шаблона в котором задает переменные base, parent, id
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
271 # а также создает переменные для строковых констант из labels
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
272 # хеш с переменными $args будет передан самому шаблону в момент выполнения
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
273 # если у шаблона указан класс элемента управления, то при выполнении шаблона
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
274 # будет создан экземпляр этого класса и процесс выполнения шаблона будет
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
275 # делегирован методу Render этого экземпляра.
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
276 sub render {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
277 my ($this,$template,$args) = @_;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
278
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
279 $args ||= {};
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
280
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
281 my $info = ref $template ? $template : $this->find_template($template);
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
282
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
283 if (ref($info) ne 'HASH') {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
284 carp "got an invalid template object: $info (" . ref($info) . ")";
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
285 $info = {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
286 template => $info,
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
287 base => $this->base,
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
288 initialized => 1
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
289 };
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
290 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
291
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
292 return $this->invoke_environment(
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
293 sub {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
294 my $ctx = shift;
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
295
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
296 unless($info->{initialized}) {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
297 if(my $init = $info->{template}->blocks->{INIT}) {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
298 $info->{initialized} = 1;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
299 eval {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
300 $ctx->visit($info->{template}->blocks);
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
301 $ctx->include($init);
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
302 };
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
303 $ctx->leave();
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
304 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
305 }
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
306
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
307 if (my $class = $info->{class}) {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
308 $class->new($ctx,$info->{template},$args)->Render({});
352
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
309 } else {
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
310 return $ctx->include($info->{template},$args);
675cd1829255 working on TTView: added control classes support
cin
parents: 351
diff changeset
311 }
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
312 },
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
313 hashMerge(
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
314 $info->{labels} || {},
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
315 {
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents: 349
diff changeset
316 base => $info->{base},
356
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
317 parent => $this,
97131d500f16 TTView: added identifiers support
cin
parents: 355
diff changeset
318 id => $this->get_next_id
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
319 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
320 )
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
321 )
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
322 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
323
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
324 sub resolve_model {
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
325 my ($this,$prefix) = @_;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
326
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
327 die ArgException->new(prefix => "the prefix must be specified")
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
328 unless defined $prefix;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
329
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
330 my $meta = $this->metadata;
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
331 unless($meta) {
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
332 $meta = Metadata->GetMetadataForModel($this->model);
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
333 $this->metadata($meta);
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
334 }
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
335
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
336 foreach my $part (grep length($_), split(/\.|\[(\d+)\]/, $prefix)) {
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
337 last unless $meta;
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
338 if ($part =~ /^\d+$/) {
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
339 $meta = $meta->GetItem($part);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
340 } else {
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
341 $meta = $meta->GetProperty($part);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
342 }
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
343 }
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
344
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
345 return $meta;
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
346 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
347
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
348 sub find_template_for {
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
349 my ($this,$meta, $nothrow) = @_;
347
cin
parents: 346
diff changeset
350
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
351 die ArgException->new(meta => 'An invalid metadata is supplied')
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
352 unless is($meta,MetadataBase);
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
353
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
354 return $this->find_template($meta->template)
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
355 if ($meta->template);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
356
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
357 my $type = $meta->modelType;
347
cin
parents: 346
diff changeset
358
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
359 return $this->find_template('templates/plain') unless $type;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
360
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
361 if (my $template = $this->cache->Get($type)) {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
362 return $template;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
363 } else {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
364
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
365 no strict 'refs';
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
366
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
367 my @isa = $type;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
368
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
369 while (@isa) {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
370 my $sclass = shift @isa;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
371
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
372 (my $name = $sclass) =~ s/:+/_/g;
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
373 my ($shortName) = ($sclass =~ m/(\w+)$/);
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
374
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
375 $template = $this->find_template("templates/$name",1) || $this->find_template("templates/$shortName",1);
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
376
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
377 if ($template) {
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
378 $this->cache->Set($sclass,$template);
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
379 return $template;
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
380 }
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
381
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
382 #todo $meta->GetISA
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
383 push @isa, @{"${sclass}::ISA"};
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
384 }
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
385
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
386 }
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 359
diff changeset
387 $this->throw(Template::Constants::ERROR_FILE, "can't find a template for the model $type")
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
388 unless $nothrow;
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
389
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
390 return;
347
cin
parents: 346
diff changeset
391 }
cin
parents: 346
diff changeset
392
349
86b470004d47 added lables loading
cin
parents: 348
diff changeset
393 sub get_real_file {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
394 my ($this,$fname) = @_;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
395
86b470004d47 added lables loading
cin
parents: 348
diff changeset
396 my @path = split(/\/+/,$fname);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
397
86b470004d47 added lables loading
cin
parents: 348
diff changeset
398 foreach my $provider (@{$this->load_templates || []}) {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
399 foreach my $dir (@{$provider->paths || []}) {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
400 my $realName = File::Spec->catfile($dir,@path);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
401 return $realName if -f $realName;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
402 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
403 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
404 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
405
86b470004d47 added lables loading
cin
parents: 348
diff changeset
406 sub load_labels {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
407 my ($this,$fname) = @_;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
408
86b470004d47 added lables loading
cin
parents: 348
diff changeset
409 $fname = $this->get_real_file($fname);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
410
86b470004d47 added lables loading
cin
parents: 348
diff changeset
411 my %vars;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
412
86b470004d47 added lables loading
cin
parents: 348
diff changeset
413 my $flabels = "$fname.labels";
86b470004d47 added lables loading
cin
parents: 348
diff changeset
414
86b470004d47 added lables loading
cin
parents: 348
diff changeset
415 if (-f $flabels) {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
416
86b470004d47 added lables loading
cin
parents: 348
diff changeset
417 my %labels;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
418 $labels{default} = IMPL::Resources::Strings::ParseStringsMap($flabels);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
419
86b470004d47 added lables loading
cin
parents: 348
diff changeset
420 while(my($label,$text) = each %{$labels{default}}) {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
421 $vars{$label} = sub {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
422 my ($params) = @_;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
423 my $locale = Resources->currentLocale;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
424
86b470004d47 added lables loading
cin
parents: 348
diff changeset
425 unless ($labels{$locale}) {
86b470004d47 added lables loading
cin
parents: 348
diff changeset
426 $labels{$locale} = -f "$fname.$locale" ?
86b470004d47 added lables loading
cin
parents: 348
diff changeset
427 IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") :
86b470004d47 added lables loading
cin
parents: 348
diff changeset
428 {};
86b470004d47 added lables loading
cin
parents: 348
diff changeset
429 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
430
86b470004d47 added lables loading
cin
parents: 348
diff changeset
431 return FormatMessage(($labels{$locale}{$label} || $text),$params);
86b470004d47 added lables loading
cin
parents: 348
diff changeset
432 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
433 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
434 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
435
86b470004d47 added lables loading
cin
parents: 348
diff changeset
436 return \%vars;
86b470004d47 added lables loading
cin
parents: 348
diff changeset
437 }
86b470004d47 added lables loading
cin
parents: 348
diff changeset
438
345
cin
parents: 343
diff changeset
439 1;
cin
parents: 343
diff changeset
440
cin
parents: 343
diff changeset
441 __END__
cin
parents: 343
diff changeset
442
cin
parents: 343
diff changeset
443 =pod
cin
parents: 343
diff changeset
444
cin
parents: 343
diff changeset
445 =head1 NAME
cin
parents: 343
diff changeset
446
cin
parents: 343
diff changeset
447 C<IMPL::Web::View::TTContext> - доработанная версия контекста
cin
parents: 343
diff changeset
448
cin
parents: 343
diff changeset
449 =head1 DESCRIPTION
cin
parents: 343
diff changeset
450
cin
parents: 343
diff changeset
451 Расширяет функции C<Template::Context>
cin
parents: 343
diff changeset
452
cin
parents: 343
diff changeset
453 =begin plantuml
cin
parents: 343
diff changeset
454
cin
parents: 343
diff changeset
455 @startuml
cin
parents: 343
diff changeset
456
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
457 object RootContext {
345
cin
parents: 343
diff changeset
458 document
346
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
459 globals
345
cin
parents: 343
diff changeset
460 }
cin
parents: 343
diff changeset
461
cin
parents: 343
diff changeset
462 object DocumentContext {
346
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
463 base
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
464 extends
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
465 }
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
466
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
467 object ControlContext {
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
468 base
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
469 extends
345
cin
parents: 343
diff changeset
470 }
cin
parents: 343
diff changeset
471
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
472 RootContext o-- DocumentContext
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
473 RootContext o-- ControlContext
345
cin
parents: 343
diff changeset
474
346
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
475 Document -- DocumentContext
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
476 Control - ControlContext
345
cin
parents: 343
diff changeset
477
348
f116cd9fe7d9 working on TTView: pre-alpha version
cin
parents: 347
diff changeset
478 Loader . RootContext: <<creates>>
346
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
479 Loader . Document: <<creates>>
f05634287ac7 working on the view concept
cin
parents: 345
diff changeset
480 Loader -up- Registry
345
cin
parents: 343
diff changeset
481
cin
parents: 343
diff changeset
482 @enduml
cin
parents: 343
diff changeset
483
cin
parents: 343
diff changeset
484 =end plantuml
cin
parents: 343
diff changeset
485
cin
parents: 343
diff changeset
486 =head1 MEMBERS
cin
parents: 343
diff changeset
487
cin
parents: 343
diff changeset
488 =head2 C<[get,set]base>
cin
parents: 343
diff changeset
489
cin
parents: 343
diff changeset
490 Префикс пути для поиска шаблонов
cin
parents: 343
diff changeset
491
cin
parents: 343
diff changeset
492 =head2 C<template($name)>
cin
parents: 343
diff changeset
493
cin
parents: 343
diff changeset
494 Сначала пытается загрузить шаблон используя префикс C<base>, затем без префикса.
cin
parents: 343
diff changeset
495
cin
parents: 343
diff changeset
496 =head2 C<clone()>
cin
parents: 343
diff changeset
497
cin
parents: 343
diff changeset
498 Создает копию контекста, при этом C<stash> локализуется, таким образом
cin
parents: 343
diff changeset
499 клонированный контекст имеет собственное пространство имен, вложенное в
cin
parents: 343
diff changeset
500 пространство родительского контекста.
cin
parents: 343
diff changeset
501
cin
parents: 343
diff changeset
502 =cut