annotate Lib/IMPL/Web/View/TTDocument.pm @ 182:adc7669172c4

sync
author sergey
date Mon, 26 Mar 2012 02:01:05 +0400
parents 47dac58691ee
children ae8072f2f2a3
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
47 if (! $this->controls->{$control}) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
48
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
49 (my $path = $control) =~ tr/\./\//;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
50 if ( my $template = $this->loader->template($path) ) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
51 my $opts = ${$this->opts};
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
52 $opts->{STASH} = $this->context->stash->clone();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
53
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
54 my $ctx = new Template::Context($opts);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
55
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
56 my $factory = new IMPL::Web::View::TTFactory(
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
57 typeof IMPL::Web::View::TTControl,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
58 $template,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
59 $ctx,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
60 $opts
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
61 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
62
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
63 my @parts = split(/\.+/,$control);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
64
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
65 $this->context->stash->set([map { $_, 0 } @parts], $factory);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
66
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
67 } else {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
68 die new IMPL::KeyNotFoundException($control);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
69 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
70
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
71 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
72 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
73
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
74 sub Render {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75 my ($this,$param) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77 my $output = $this->context->process($this->template, {this => $this} );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
78
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 if ($this->layout) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80 $output = $this->context->include($this->layout,{ content => $output });
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
83 return $output;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
100
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
101 use IMPL::Web::View::TTDocument();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
102
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
103 my $doc = new IMPL::Wbe::View::TTDocument($template,$ttOptions);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
104
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
105 return $doc->Render();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
106
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
107 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
108
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109 Однако, более предпочтительный способ использовать C<IMPL::Web::View::TTLoader>.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
111 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
112
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
113 Документ для представления данных. Документы представляют собой иерархически организованные данные,
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
114 элементами данного документа являются данные для отображения, такие как
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118 =item * Объекты из БД
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
120 =item * Навигационные цепочки
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
121
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
122 =item * Меню и т.п.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
123
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
124 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
125
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
126 Скприт шаблона формирует структуру документа, затем сформированная структура форматируется в готовый документ.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
127 Процесс преобразования объектной модели в готовый документ может быть выполнена как вручную, так и при помощи
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
128 вспомогательного шаблона - обертки. Если у шаблона документа указан C<wrapper> в метаданных, то он будет
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
129 использован как шаблон для форматирования объектной модели, вывод самого шаблона будет проигнорирован. Если
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
130 обертка не задана, то результатом будет вывод самого скрипта шаблона.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
131
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
132 Каждый документ имеет свое собственное пространство имен, которое может быть вложенным в некоторое внешнее,
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 =head2 Загрузка элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
136
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
137 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
138
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
139 =item 1 C<document.require(my.org.input)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
140
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
141 =item 1 Загружает шаблон C<my/org/input.tt>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
142
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
143 =item 1 Создает фабрику элементов управления с собственным контекстом, вложенным в контекст документа.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
144
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
145 =item 1 Выполняет шаблон в пространстве имен фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
146
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
147 =item 1 Регистритует фабрику в контексте документа по пути C<my.org.input>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
148
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
149 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
150
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
151 =head2 Создание элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
152
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
153 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
154
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155 =item 1 C<< my.org.input.new('login') >>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157 =item 1 Если это первый элемент управления, то выполняетя статический конструктор в контексте фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
158
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
159 =item 1 Создается новый дочерний контекст к контексту фабрики
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
160
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
161 =item 1 Создается экземпляр элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
162
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
163 =item 1 Выполняется блок конструктора в контексте элемента управления, параметр C<this> имеет значение
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
164 нового экземпляра элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
165
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
166 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
167
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
168 =head1 MEMBERS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
169
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
170 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
171
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
172 =item C<CTOR($template, %options)>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
173
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
174 Создает экземпляр документа с указанным шаблоном и параметрами, параметры
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
175
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
176 =back
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
177
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
178 =cut