annotate Lib/IMPL/Web/View/TTDocument.pm @ 187:927653d01f4f

TTControl::AUTOLOAD now accesses nodeProperties Added TTControl::renderBlock property to access RENDER block of the template
author sergey
date Tue, 03 Apr 2012 07:54:25 +0400
parents 6c0fee769b0c
children 029c9610528c
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
4 use IMPL::lang qw(:declare :constants);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
5 use IMPL::DOM::Property qw(_dom);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
6 use IMPL::Web::View::TTFactory();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
7 use IMPL::Web::View::TTControl();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
8
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
9
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
10 use parent qw(
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
11 IMPL::DOM::Document
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
12 IMPL::Web::View::TTControl
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
13 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
14
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
15 BEGIN {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
16 public _dom property layout => PROP_ALL;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
17 public property opts => PROP_GET | PROP_OWNERSET;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
18 public property loader => PROP_GET | PROP_OWNERSET;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
19 public property controls => PROP_GET | PROP_OWNERSET;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
20 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
21
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22 sub CTOR {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
23 my ($this,$template,$refOpts,%args) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
24
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
25 $this->controls({});
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
26 $this->loader($args{loader}) if $args{loader};
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
27
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
28 $this->layout( $template->layout ) unless $this->layout;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
29
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
30 $this->opts($refOpts);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
31 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
32
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
33 our %CTOR = (
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
34 'IMPL::Web::View::TTControl' => sub {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
35 'document',
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
36 $_[0], # template
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
37 new Template::Context($_[1]) # context
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
38 },
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
39 'IMPL::DOM::Document' => sub {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
40 nodeName => 'document'
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
41 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
42 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
43
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
44 sub require {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
45 my ($this, $control) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
46
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
47 if (my $factory = $this->controls->{$control}) {
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
48 return $factory;
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
49 } else {
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
50
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
51 my $path = $control;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
52 if ( my $template = $this->loader->template($path) ) {
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
53 my $opts = { %{$this->opts} };
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
54 $opts->{STASH} = $this->context->stash->clone();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
55
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
56 my $ctx = new Template::Context($opts);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
57
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
58 $factory = new IMPL::Web::View::TTFactory(
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
59 typeof IMPL::Web::View::TTControl,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
60 $template,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
61 $ctx,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
62 $opts
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
63 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
64
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
65 my @parts = split(/\/+/,$control);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
66
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
67 $this->controls->{$control} = $factory;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
68 $this->context->stash->set([map { $_, 0 } @parts], $factory);
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
69
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
70 return $factory;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
71 } else {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
72 die new IMPL::KeyNotFoundException($control);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
73 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
74
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
78 sub renderBlock {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
79 $_[0]->template;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
80 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
81
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82 sub Render {
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
83 my ($this,$args) = @_;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
85 my $output = $this->IMPL::Web::TTControl::Render( { document => $this } );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87 if ($this->layout) {
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
88 $output = $this->context->include($this->layout, { content => $output } );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91 return $output;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
100
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
101 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
102
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
103 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
104
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
105 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
106
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
107 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
108
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109 use IMPL::Web::View::TTDocument();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
111 my $doc = new IMPL::Wbe::View::TTDocument($template,$ttOptions);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
112
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
113 return $doc->Render();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
114
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117 Однако, более предпочтительный способ использовать C<IMPL::Web::View::TTLoader>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
120
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
121 Документ для представления данных. Документы представляют собой иерархически организованные данные,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
122 элементами данного документа являются данные для отображения, такие как
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
123
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
124 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
125
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
126 =item * Объекты из БД
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
127
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
128 =item * Навигационные цепочки
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
129
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
130 =item * Меню и т.п.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
131
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
132 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
133
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
134 Скприт шаблона формирует структуру документа, затем сформированная структура форматируется в готовый документ.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
135 Процесс преобразования объектной модели в готовый документ может быть выполнена как вручную, так и при помощи
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
136 вспомогательного шаблона - обертки. Если у шаблона документа указан C<wrapper> в метаданных, то он будет
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
137 использован как шаблон для форматирования объектной модели, вывод самого шаблона будет проигнорирован. Если
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
138 обертка не задана, то результатом будет вывод самого скрипта шаблона.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
139
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
140 Каждый документ имеет свое собственное пространство имен, которое может быть вложенным в некоторое внешнее,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
141 указанное при создании документа.
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
142 =head2 Порядок обработки документа
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
143
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
144 =over
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
145
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
146 =item 1 Создается документ при помощи метода C<TTLoader::document()>
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
147
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
148 =item 1 При создании документа (в конструкторе), происходит выполнение блока C<CTOR>
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
149
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
150 =item 1 При вызове метода C<TTDocument::Render()> устанавливаются переменные C<this>, C<document>
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
151 и шаблон обрабатывается при помощи метода C<process()> контекста документа.
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
152
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
153 =back
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
154
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155 =head2 Загрузка элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
158
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
159 =item 1 C<document.require('my/org/input')>
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
160
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
161 =item 1 Загружает шаблон C<my/org/input.tt>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
162
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
163 =item 1 Создает фабрику элементов управления с собственным контекстом, вложенным в контекст документа.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
164
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
165 =item 1 Выполняет шаблон в пространстве имен фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
166
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
167 =item 1 Регистритует фабрику в контексте документа по пути C<my.org.input>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
168
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
169 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
170
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
171 =head2 Создание элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
172
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
173 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
174
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
175 =item 1 C<< my.org.input.new('login') >>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
176
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
177 =item 1 Если это первый элемент управления, то выполняетя статический конструктор в контексте фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
178
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
179 =item 1 Создается новый дочерний контекст к контексту фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
180
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
181 =item 1 Создается экземпляр элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
182
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
183 =item 1 Выполняется блок конструктора в контексте элемента управления, параметр C<this> имеет значение
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
184 нового экземпляра элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
185
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
186 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
187
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
188 =head1 MEMBERS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
189
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
190 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
191
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
192 =item C<CTOR($template, %options)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
193
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
194 Создает экземпляр документа с указанным шаблоном и параметрами, параметры
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
195
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
196 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
197
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
198 =cut