comparison Lib/IMPL/Web/View/TTDocument.pm @ 345:72799d1211c5

sync
author cin
date Fri, 27 Sep 2013 16:28:27 +0400
parents f1d67615a5b1
children
comparison
equal deleted inserted replaced
344:f1d67615a5b1 345:72799d1211c5
19 'IMPL::Web::View::TTControl' => sub { 19 'IMPL::Web::View::TTControl' => sub {
20 my ($template,$ctx,$vars) = @_; 20 my ($template,$ctx,$vars) = @_;
21 $ctx ||= Template::Context->new(); 21 $ctx ||= Template::Context->new();
22 return $template, $ctx, $vars; # context 22 return $template, $ctx, $vars; # context
23 } 23 }
24 ],
25 props => [
26 layout => PROP_RW,
27 layoutBase => PROP_RW,
28 registry => PROP_RW,
29 baseLocation => PROP_RW
30 ] 24 ]
31 }; 25 };
32 26
33 sub CTOR { 27 sub CTOR {
34 my ($this,$template,$ctx) = @_; 28 my ($this,$template,$ctx) = @_;
35 29
36 $this->layout( $template->layout ) unless $this->layout; 30 $this->layout( $template->layout ) unless $this->layout;
37 $this->title( $template->title ) unless $this->title; 31 $this->title( $template->title ) unless $this->title;
38 my $doc = $this;
39 weaken($doc);
40 $this->registry->context->stash->update({
41 document => sub { $doc }
42 });
43 } 32 }
44 33
45 sub Render { 34 sub Render {
46 my ($this,$args) = @_; 35 my ($this,$args) = @_;
36
37 my $ctx = $this->context;
47 38
48 $args ||= {}; 39 $args ||= {};
49 $args->{document} = $this; 40 $args->{document} = $this;
41 $args->{render} = sub {
42 my ($model,$factory) = @_;
43
44 $factory = $ctx->require($factory) unless is($factory,TTFactory);
45
46 return $factory->new({document => $this, model => $model})->Render();
47 };
50 48
51 49
52 if ($this->layout) { 50 if ($this->layout) {
53 my $layout = $this->registry->Require(join('/',$this->layoutBase, $this->layout))->new(); 51 my $layout = $this->registry->Require($this->layout)->new();
54 52
55 my $next = $this->next::can(); 53 my $next = $this->next::can();
56 54
57 return $layout->Render({ 55 return $layout->Render({
58 content => sub { $this->$next($args) }, 56 content => sub { $this->$next($args) },
122 120
123 =begin plantuml 121 =begin plantuml
124 122
125 @startuml 123 @startuml
126 124
127 namespace IMPL::Web::View { 125 object "doc: TTDocument" as doc
126 object "docCtx: TTContext" as docctx
127 object "factory: TTFactory" as factory
128 object "registry: TTRegistry" as registry
129 object "control: TTControl" as ctl
130 object "ctlCtx: TTContext" as ctlctx
128 131
129 TTDocument "0 .. *" .. TTLoader 132 doc -up-> docctx
130 TTDocument --|> TTControl 133 registry --> "0..*" factory
131 134 factory .> doc: <<creates>>
132 TTControl .. TTContext 135 factory .up.> ctl: <<creates>>
133 136 docctx -up-> registry
134 TTFactory -- TTControl 137 ctl -> ctlctx
135 TTFactory .. TTContext 138 ctlctx --> registry
136 139 ctlctx --> doc
137 class TTRegistry
138
139 }
140 140
141 @enduml 141 @enduml
142 142
143 =end plantuml 143 =end plantuml
144 144