annotate Lib/IMPL/Web/View/TTDocument.pm @ 287:2d253e6e4a88

*TTView refactoring
author cin
date Tue, 19 Feb 2013 03:05:10 +0400
parents d357b5d85d25
children 3a9cfea098dd
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::TTDocument;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
2 use strict;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
3
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
4 use Scalar::Util qw(weaken);
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
5 use IMPL::Const qw(:prop);
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
6 use IMPL::lang qw(:hash);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
7
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
8 use IMPL::declare {
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
9 require => {
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
10 TTFactory => 'IMPL::Web::View::TTFactory',
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
11 TTControl => 'IMPL::Web::View::TTControl',
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
12 Loader => 'IMPL::Code::Loader'
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
13 },
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
14 base => [
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
15 'IMPL::Web::View::TTControl' => sub {
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
16 my ($template,$ctx) = @_;
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
17 'document',
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
18 $template, # template
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
19 $ctx || Template::Context->new() # context
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
20 }
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
21 ],
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
22 props => [
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
23 layout => PROP_RW,
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
24 loader => PROP_RW,
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
25 controls => PROP_RO,
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
26 creationArgs => PROP_RO,
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
27
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
28 # store the stash separately to make require() method to work correctly
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
29 # even when a stash of the context is modified during the processing
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
30 stash => PROP_RO
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
31 ]
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
32 };
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
33
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
34 BEGIN {
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
35
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
36 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
37
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
38 sub CTOR {
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
39 my ($this,$template,$ctx,$loader,$vars) = @_;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
40
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
41 $this->controls({});
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
42 $this->loader($loader) if $loader;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
43
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
44 $this->layout( $template->layout ) unless $this->layout;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
45
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
46 $this->stash($this->context->stash);
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
47 $this->creationArgs($vars);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
48
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
49 my $self = $this;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
50 weaken($self);
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
51
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
52 $this->templateVars(require => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
53 my $doc = $self;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
54 die new IMPL::Exception("A document is destroyed or invalid") unless $doc;
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
55 $doc->RequireControl(@_);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
56 });
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
57
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
58 $this->templateVars(document => sub { $self } );
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
59 $this->InitInstance($vars);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
60 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
61
189
08015e2803f1 IMPL::Vew::Web - fixed memory leaks, more tests
cin
parents: 188
diff changeset
62 sub templateVars {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
63 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
64 my $name = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
65
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
66 if (@_) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
67 return $this->stash->set($name, shift);
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
68 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
69 return $this->stash->get($name);
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
70 }
189
08015e2803f1 IMPL::Vew::Web - fixed memory leaks, more tests
cin
parents: 188
diff changeset
71 }
08015e2803f1 IMPL::Vew::Web - fixed memory leaks, more tests
cin
parents: 188
diff changeset
72
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
73 sub RequireControl {
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 263
diff changeset
74 my ($this, $control) = @_;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
75
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
76 if (my $factory = $this->controls->{$control}) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
77 return $factory;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
78 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
79
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
80 my $path = $control;
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 263
diff changeset
81
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
82 if ( my $template = $this->loader->template($path) ) {
189
08015e2803f1 IMPL::Vew::Web - fixed memory leaks, more tests
cin
parents: 188
diff changeset
83
245
7c517134c42f Added Unsupported media type Web exception
sergey
parents: 241
diff changeset
84 # factory will create a clone of the stash
7c517134c42f Added Unsupported media type Web exception
sergey
parents: 241
diff changeset
85 # $opts->{STASH} = $this->stash->clone();
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 187
diff changeset
86
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
87 my $ctx = Template::Context->new({%{$this->context}, STASH => $this->stash });#new Template::Context($opts);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
88
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
89 $factory = new IMPL::Web::View::TTFactory(
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 245
diff changeset
90 $template->class || TTControl,
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
91 $template,
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
92 $ctx,
267
bbc0da7ef90e *IMPL::Web::View refactoring
cin
parents: 263
diff changeset
93 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) )
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
94 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
95
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
96 if ($template->class) {
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
97 Loader->safe->Require($template->class);
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
98 }
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
99
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
100 $this->controls->{$control} = $factory;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
101
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
102 return $factory;
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 187
diff changeset
103
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
104 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
105 die new IMPL::KeyNotFoundException($control);
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
106 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
107 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
108 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110 sub Render {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
111 my ($this,$args) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
112
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
113 $args ||= {};
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
114
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
115 my $newArgs = hashMerge($this->creationArgs, $args);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
116
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
117 if ($this->layout) {
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
118 my $text = eval {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
119 #$this->context->localise();
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
120 my $tlayout = $this->loader->layout($this->layout);
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
121 if(my $init = $tlayout->blocks->{INIT}) {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
122 $this->context->process(
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
123 $init,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
124 hashMerge(
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
125 $newArgs,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
126 {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
127 template => $this->template
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
128 }
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
129 )
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
130 );
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
131 }
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
132 return $this->context->include(
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
133 $tlayout,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
134 {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
135 %{$newArgs},
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
136 content => $this->RenderContent($newArgs),
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
137 this => $this,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
138 template => $this->template
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
139 }
286
d357b5d85d25 *TTView refactoring
sergey
parents: 285
diff changeset
140 );
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
141 };
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
142 my $e = $@;
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
143
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
144 #$this->context->delocalise();
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
145
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
146 if ($e) {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
147 die $e;
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
148 } else {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
149 return $text;
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
150 }
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
151
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
152 } else {
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
153 return $this->RenderContent($newArgs);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
154 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
190
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
157 sub RenderContent {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
158 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
159 return $this->SUPER::Render(@_);
190
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
160 }
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
161
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
162 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
163
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
164 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
165
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
166 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
167
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
168 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
169
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
170 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
171
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
172 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
173
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
174 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
175
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
176 use IMPL::Web::View::TTDocument();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
177
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
178 my $doc = new IMPL::Wbe::View::TTDocument($template,$ttOptions);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
179
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
180 return $doc->Render();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
182 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
183
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
184 Однако, более предпочтительный способ использовать C<IMPL::Web::View::TTLoader>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
185
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
186 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
187
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
188 Документ для представления данных. Документы представляют собой иерархически организованные данные,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
189 элементами данного документа являются данные для отображения, такие как
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
190
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
191 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
192
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
193 =item * Объекты из БД
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
194
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
195 =item * Навигационные цепочки
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
196
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
197 =item * Меню и т.п.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
198
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
199 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
200
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
201 Скприт шаблона формирует структуру документа, затем сформированная структура форматируется в готовый документ.
192
a9faf883cdce IMPL::Web::View refactoring
cin
parents: 191
diff changeset
202 Процесс форматирования объектной модели в готовый документ может быть выполнена как вручную, так и при помощи
189
08015e2803f1 IMPL::Vew::Web - fixed memory leaks, more tests
cin
parents: 188
diff changeset
203 вспомогательного шаблона - обертки. Если у шаблона документа указан C<layout> в метаданных, то он будет
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
204 использован как шаблон для форматирования объектной модели, вывод самого шаблона будет проигнорирован. Если
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
205 обертка не задана, то результатом будет вывод самого скрипта шаблона.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
206
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
207 Использование объектной модели документа позволяет решить задачи по созданию контейнеров,
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
208 у которых может быть сложное содежимое. Примером таких элементов могут быть формы,
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
209 внутри форм элементы управления также могут группироваться.
192
a9faf883cdce IMPL::Web::View refactoring
cin
parents: 191
diff changeset
210
193
sergey
parents: 192
diff changeset
211 =head2 Элементы управления (компоненты)
sergey
parents: 192
diff changeset
212
sergey
parents: 192
diff changeset
213 Документ состоит из узлов, часть которых наследуется от C<IMPL::Web::View::TTControl>, такие узлы называются
sergey
parents: 192
diff changeset
214 элементами управления. Каждый элемент управления имеет собственный контекст, который наследуется от контекста
sergey
parents: 192
diff changeset
215 документа.
sergey
parents: 192
diff changeset
216
sergey
parents: 192
diff changeset
217 =head2 Фабрика элементов управления
sergey
parents: 192
diff changeset
218
sergey
parents: 192
diff changeset
219 Для создания элементов управления используются фабрики. Каждый элемен управления имеет свой шаблон для
sergey
parents: 192
diff changeset
220 форматиорвания содержимого, фабрика связывает шаблон и класс элемента управления, для чего при загрузке
sergey
parents: 192
diff changeset
221 шаблона используется свойство C<type> из метаданных. Фабрика загружается в документ при том только один
sergey
parents: 192
diff changeset
222 раз, повторные загрузки фабрики возвращают уже загруженную. Для загрузки фабрики используется метод
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
223 C<require()> с указанием элемента управления.
190
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
224
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
225 =head2 Порядок обработки документа
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
226
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
227 Построение представления данных состоит из двух этапов
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
228
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
229 =over
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
230
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
231 =item 1 Создание объектной модели документа. На данном этапе создаются все элементы управления.
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
232
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
233 =item 1 Преобразование объектной модели в конечнное представление. На данном этапе происходит
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
234 форматирование документа.
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
235
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
236 =back
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
237
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
238
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
239 =head2 Загрузка элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
240
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
241 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
242
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
243 =item 1 C<TInput = require('my/org/input')>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
244
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
245 =item 1 Загружается шаблон C<my/org/input.tt>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
246
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
247 =item 1 Создается фабрика элементов управления с собственным контекстом, унаследованным от контекст документа.
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
248
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
249 =item 1 При первом создании элемента управления фабрика инициализируется выполнением блока C<INIT>.
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
250
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
251 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
252
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
253 =head2 Создание элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
254
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
255 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
256
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
257 =item 1 C<< TInput.new('login') >>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
258
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
259 =item 1 Создается новый дочерний контекст к контексту фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
260
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
261 =item 1 Создается экземпляр элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
262
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
263 =item 1 Выполняется блок конструктора C<CTOR> в контексте элемента управления, параметр C<this> имеет значение
181
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 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
267
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
268 =head1 MEMBERS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
269
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
270 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
271
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
272 =item C<CTOR($template, $contextOpts, $loader[, $vars])>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
273
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
274 Создает экземпляр документа с указанным шаблоном и параметрами.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
275
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
276 =over
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
277
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
278 =item C<$template>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
279
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
280 C<Template::Document> шаблон документа.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
281
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
282 =item C<$contextOpts>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
283
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
284 C<HASH> Параметры контекста C<Template::Context> для документа. Эти параметры будут сохранены
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
285 в свойстве C<opts>, а также на их основе будет создан контекст текщего документа. Как правило
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
286 эти параметы задаются загрузчиком документа C<IMPL::Web::View::TTLoader>, таким образом, что
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
287 C<Template::Stash> создаваемого контекста наследует переменные из контекста загрузчика.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
288
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
289 =item C<$loader>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
290
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
291 C<IMPL::Web::View::TTLoader> загрузчик, который будет использоваться для загрузки элементов управления,
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
292 а также для получения обертки, заданной в свойстве документа C<layout>.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
293
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
294 =item C<$vars>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
295
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
296 C<HASH> Необязательный параметр. переменные которые будут переданы в блок конструктора C<INIT>.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
297 Как правило они используются для передачи данных для построения документа
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
298
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
299 =back
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
300
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
301 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
302
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
303 =over
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
304
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
305 =item C<templateVars($name[,$newValue])>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
306
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
307 Получает или задает переменную для шаблона документа. Имя переменнной может быть составным,
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
308 например C<'my.var.name'>, см. C<Template::Stash::set()>.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
309
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
310 =item C<RequireControl($controlName)>
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
311
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
312 Загружает фабрику элемента управления, если она уже была загружена, возвращает на нее ссылку.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
313 При загрузки фабрики для нее создается собственный контекст на основе параметров из свойства
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
314 C<opts> и ее пространство имен наследуется от пространства имен документа из свойства C<stash>.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
315
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
316 =item C<Render($vars)>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
317
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
318 Выполняет блок C<renderBlock> документа для получения конечного представления, C<$vars>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
319 содержит переменные для блока.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
320
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
321 =item C<RenderContent($vars)>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
322
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
323 Выполняет шаблон документа для получения представления содержимого, в отличии от
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
324 метода C<Render> не использует обертку указанную в свойстве C<layout>, если обертка
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
325 не указана, то эти методы идентичны.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
326
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
327 =item C<[get,set]layout>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
328
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
329 Обертка, которая будет использована для построения представления документа. В обертке
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
330 будет доступна специальная переменная C<content>, при обращении к которой будет B<выполнен>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
331 метод C<RenderContent()> и возвращен результат его работы. Для получения шаблона обертки
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
332 используется загрузчик из свойства C<loader>.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
333
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
334 =item C<[get]opts>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
335
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
336 Параметры контекста, используются для создания контекстов фабрик элементов управления.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
337
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
338 =item C<[get]loader>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
339
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
340 Загрузчик, используется для загрузки шаблонов фабрик элементов управления и обертки.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
341
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
342 =item C<[get]controls>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
343
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
344 C<HASH> Коллекция загруженных фабрик элементов управления, ключем является
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
345 квалифицированное имя элемента управления.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
346
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
347 =item C<[get]stash>
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
348
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
349 C<Template::Stash> Пространство имен документа, оно используется как родительское
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
350 для пространств имен загружаемых фабрик элементов управления.
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
351
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
352 =back
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
353
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
354 =head1 TEMPLATES
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
355
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
356 =begin text
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
357
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
358 [%META layout='default'%]
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
359 [% BLOCK CTOR;
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
360 section('top','TOP');
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
361 section('bottom','BOTTOM');
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
362 section('client','CLIENT');
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
363 END %]
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
364 [% BLOCK TOP;
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
365 TMenu = require('my/org/Menu');
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
366 append(TMenu.new());
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
367 END %]
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
368
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
369 =end
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
370
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
371 =cut