Mercurial > pub > Impl
comparison 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 |
comparison
equal
deleted
inserted
replaced
286:d357b5d85d25 | 287:2d253e6e4a88 |
---|---|
11 TTControl => 'IMPL::Web::View::TTControl', | 11 TTControl => 'IMPL::Web::View::TTControl', |
12 Loader => 'IMPL::Code::Loader' | 12 Loader => 'IMPL::Code::Loader' |
13 }, | 13 }, |
14 base => [ | 14 base => [ |
15 'IMPL::Web::View::TTControl' => sub { | 15 'IMPL::Web::View::TTControl' => sub { |
16 my ($template,$contextOpts) = @_; | 16 my ($template,$ctx) = @_; |
17 'document', | 17 'document', |
18 $template, # template | 18 $template, # template |
19 Template::Context->new($contextOpts) # context | 19 $ctx || Template::Context->new() # context |
20 } | 20 } |
21 ], | 21 ], |
22 props => [ | 22 props => [ |
23 layout => PROP_RW, | 23 layout => PROP_RW, |
24 opts => PROP_RO, | |
25 loader => PROP_RW, | 24 loader => PROP_RW, |
26 controls => PROP_RO, | 25 controls => PROP_RO, |
27 creationArgs => PROP_RO, | 26 creationArgs => PROP_RO, |
28 | 27 |
29 # store the stash separately to make require() method to work correctly | 28 # store the stash separately to make require() method to work correctly |
35 BEGIN { | 34 BEGIN { |
36 | 35 |
37 } | 36 } |
38 | 37 |
39 sub CTOR { | 38 sub CTOR { |
40 my ($this,$template,$refOpts,$loader,$vars) = @_; | 39 my ($this,$template,$ctx,$loader,$vars) = @_; |
41 | 40 |
42 $this->controls({}); | 41 $this->controls({}); |
43 $this->loader($loader) if $loader; | 42 $this->loader($loader) if $loader; |
44 | 43 |
45 $this->layout( $template->layout ) unless $this->layout; | 44 $this->layout( $template->layout ) unless $this->layout; |
46 | 45 |
47 $this->opts($refOpts); | |
48 $this->stash($this->context->stash); | 46 $this->stash($this->context->stash); |
49 $this->creationArgs($vars); | 47 $this->creationArgs($vars); |
50 | 48 |
51 my $self = $this; | 49 my $self = $this; |
52 weaken($self); | 50 weaken($self); |
80 } else { | 78 } else { |
81 | 79 |
82 my $path = $control; | 80 my $path = $control; |
83 | 81 |
84 if ( my $template = $this->loader->template($path) ) { | 82 if ( my $template = $this->loader->template($path) ) { |
85 my $opts = { %{$this->opts} }; | |
86 | 83 |
87 # factory will create a clone of the stash | 84 # factory will create a clone of the stash |
88 # $opts->{STASH} = $this->stash->clone(); | 85 # $opts->{STASH} = $this->stash->clone(); |
89 | 86 |
90 my $ctx = new Template::Context($opts); | 87 my $ctx = Template::Context->new({%{$this->context}, STASH => $this->stash });#new Template::Context($opts); |
91 | 88 |
92 $factory = new IMPL::Web::View::TTFactory( | 89 $factory = new IMPL::Web::View::TTFactory( |
93 $template->class || TTControl, | 90 $template->class || TTControl, |
94 $template, | 91 $template, |
95 $ctx, | 92 $ctx, |
96 $opts, | |
97 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ) | 93 join( '/', splice( @{[split(/\//,$path)]}, 0, -1 ) ) |
98 ); | 94 ); |
99 | 95 |
100 if ($template->class) { | 96 if ($template->class) { |
101 Loader->safe->Require($template->class); | 97 Loader->safe->Require($template->class); |
117 $args ||= {}; | 113 $args ||= {}; |
118 | 114 |
119 my $newArgs = hashMerge($this->creationArgs, $args); | 115 my $newArgs = hashMerge($this->creationArgs, $args); |
120 | 116 |
121 if ($this->layout) { | 117 if ($this->layout) { |
122 my $tlayout = $this->loader->layout($this->layout); | 118 my $text = eval { |
123 if(my $init = $tlayout->blocks->{INIT}) { | 119 #$this->context->localise(); |
124 $this->context->process( | 120 my $tlayout = $this->loader->layout($this->layout); |
125 $init, | 121 if(my $init = $tlayout->blocks->{INIT}) { |
126 hashMerge( | 122 $this->context->process( |
127 $newArgs, | 123 $init, |
128 { | 124 hashMerge( |
129 this => $this, | 125 $newArgs, |
130 template => $this->template | 126 { |
131 } | 127 template => $this->template |
132 ) | 128 } |
129 ) | |
130 ); | |
131 } | |
132 return $this->context->include( | |
133 $tlayout, | |
134 { | |
135 %{$newArgs}, | |
136 content => $this->RenderContent($newArgs), | |
137 this => $this, | |
138 template => $this->template | |
139 } | |
133 ); | 140 ); |
134 } | 141 }; |
135 return $this->context->include( | 142 my $e = $@; |
136 $tlayout, | 143 |
137 { | 144 #$this->context->delocalise(); |
138 %{$newArgs}, | 145 |
139 content => $this->RenderContent($newArgs), | 146 if ($e) { |
140 this => $this, | 147 die $e; |
141 template => $this->template | 148 } else { |
142 } | 149 return $text; |
143 ); | 150 } |
151 | |
144 } else { | 152 } else { |
145 return $this->RenderContent($newArgs); | 153 return $this->RenderContent($newArgs); |
146 } | 154 } |
147 } | 155 } |
148 | 156 |