annotate Lib/IMPL/Web/View/TTDocument.pm @ 346:f05634287ac7

working on the view concept
author cin
date Mon, 30 Sep 2013 01:37:50 +0400
parents 72799d1211c5
children
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);
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
6 use IMPL::lang qw(:hash is);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
7 use Carp qw(carp);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
8 use mro;
309
cin
parents: 308
diff changeset
9 use IMPL::Exception();
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
10 use IMPL::declare {
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
11 require => {
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
12 TTRegistry => 'IMPL::Web::View::TTRegistry',
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
13 TTFactory => 'IMPL::Web::View::TTFactory',
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
14 TTControl => 'IMPL::Web::View::TTControl',
309
cin
parents: 308
diff changeset
15 Loader => 'IMPL::Code::Loader',
cin
parents: 308
diff changeset
16 OpException => '-IMPL::InvalidOperationException'
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
17 },
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
18 base => [
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
19 'IMPL::Web::View::TTControl' => sub {
309
cin
parents: 308
diff changeset
20 my ($template,$ctx,$vars) = @_;
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
21 $ctx ||= Template::Context->new();
309
cin
parents: 308
diff changeset
22 return $template, $ctx, $vars; # context
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
23 }
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
24 ]
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
25 };
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
26
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
27 sub CTOR {
311
cin
parents: 310
diff changeset
28 my ($this,$template,$ctx) = @_;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
29
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
30 $this->layout( $template->layout ) unless $this->layout;
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
31 $this->title( $template->title ) unless $this->title;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
32 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
33
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
34 sub Render {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
35 my ($this,$args) = @_;
345
cin
parents: 344
diff changeset
36
cin
parents: 344
diff changeset
37 my $ctx = $this->context;
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
38
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
39 $args ||= {};
310
0a9d51cf6dfd *TTView: refactoring, document supports custom classes, layouts are become controls
sergey
parents: 309
diff changeset
40 $args->{document} = $this;
345
cin
parents: 344
diff changeset
41 $args->{render} = sub {
cin
parents: 344
diff changeset
42 my ($model,$factory) = @_;
cin
parents: 344
diff changeset
43
cin
parents: 344
diff changeset
44 $factory = $ctx->require($factory) unless is($factory,TTFactory);
cin
parents: 344
diff changeset
45
cin
parents: 344
diff changeset
46 return $factory->new({document => $this, model => $model})->Render();
cin
parents: 344
diff changeset
47 };
290
7b0dad6117d5 *TTView: fixed memory leak
sergey
parents: 289
diff changeset
48
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
49
313
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
50 if ($this->layout) {
345
cin
parents: 344
diff changeset
51 my $layout = $this->registry->Require($this->layout)->new();
313
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
52
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
53 my $next = $this->next::can();
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
54
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
55 return $layout->Render({
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
56 content => sub { $this->$next($args) },
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
57 template => $this->template,
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
58 document => $this
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
59 });
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
60 } else {
313
ec4ec1f056fe TTView: page content now rendered lazy therefore a page layout must wrap the document content
cin
parents: 311
diff changeset
61 return $this->next::method($args);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
62 }
190
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
63 }
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
64
303
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
65 sub GetTemplate {
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
66 my ($this,$name) = @_;
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
67
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
68 $this->template->blocks->{$name};
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
69 }
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
70
308
sergey
parents: 307
diff changeset
71 sub DTOR {
sergey
parents: 307
diff changeset
72 my $this = shift;
sergey
parents: 307
diff changeset
73
sergey
parents: 307
diff changeset
74 $this->registry->Dispose() if $this->registry;
sergey
parents: 307
diff changeset
75 }
sergey
parents: 307
diff changeset
76
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
78
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
83 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95
343
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
96 Позволяет строить представления при помощи Template Toolkit, при этом расширяет
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
97 шаблоны до элементов управления, чтобы была возмлжность реализации функционала
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
98 средствами C<Perl>.
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
99
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
100 Структура представления.
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
101
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
102 =begin text
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
103
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
104 + view
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
105 |- document.tt
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
106 |-+items
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
107 | |- title.tt
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
108 | |- item.tt
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
109 |
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
110 |-+layouts
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
111 |-
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
112
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
113 =end text
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
114
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
115 =begin text
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
116
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
117
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
118
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
119 =end text
9bdccdf1f50b Added a templates context
cin
parents: 313
diff changeset
120
344
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
121 =begin plantuml
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
122
344
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
123 @startuml
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
124
345
cin
parents: 344
diff changeset
125 object "doc: TTDocument" as doc
cin
parents: 344
diff changeset
126 object "docCtx: TTContext" as docctx
cin
parents: 344
diff changeset
127 object "factory: TTFactory" as factory
cin
parents: 344
diff changeset
128 object "registry: TTRegistry" as registry
cin
parents: 344
diff changeset
129 object "control: TTControl" as ctl
cin
parents: 344
diff changeset
130 object "ctlCtx: TTContext" as ctlctx
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
131
345
cin
parents: 344
diff changeset
132 doc -up-> docctx
cin
parents: 344
diff changeset
133 registry --> "0..*" factory
cin
parents: 344
diff changeset
134 factory .> doc: <<creates>>
cin
parents: 344
diff changeset
135 factory .up.> ctl: <<creates>>
cin
parents: 344
diff changeset
136 docctx -up-> registry
cin
parents: 344
diff changeset
137 ctl -> ctlctx
cin
parents: 344
diff changeset
138 ctlctx --> registry
cin
parents: 344
diff changeset
139 ctlctx --> doc
344
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
140
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
141 @enduml
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
142
f1d67615a5b1 uml diagram
cin
parents: 343
diff changeset
143 =end plantuml
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
144
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
145 =cut