comparison Lib/IMPL/Web/TT/Document.pm @ 154:eb478083f72b

Url support
author wizard
date Thu, 30 Sep 2010 02:13:05 +0400
parents 4369d5458bb6
children 8638dd1374bf
comparison
equal deleted inserted replaced
153:3765adf1803f 154:eb478083f72b
18 private property _context => prop_all; 18 private property _context => prop_all;
19 public property cache => prop_all; 19 public property cache => prop_all;
20 public property template => prop_get | owner_set; 20 public property template => prop_get | owner_set;
21 public property presenter => prop_all, { validate => \&_validatePresenter }; 21 public property presenter => prop_all, { validate => \&_validatePresenter };
22 public property preprocess => prop_all | prop_list, 22 public property preprocess => prop_all | prop_list,
23 public property title => prop_all;
23 private property _controlClassMap => prop_all; 24 private property _controlClassMap => prop_all;
24 } 25 }
25 26
26 our %CTOR = ( 27 our %CTOR = (
27 'IMPL::DOM::Document' => sub { nodeName => 'document' } 28 'IMPL::DOM::Document' => sub { nodeName => 'document' }
161 162
162 die new IMPL::InvalidArgumentException("A view object is required") unless blessed($value) and $value->isa('Template::View'); 163 die new IMPL::InvalidArgumentException("A view object is required") unless blessed($value) and $value->isa('Template::View');
163 } 164 }
164 165
165 sub LoadFile { 166 sub LoadFile {
166 my ($this,$filePath,$encoding,@includes) = @_; 167 my ($this,$filePath,$encoding,$includes,$vars) = @_;
167 168
168 die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath; 169 die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath;
169 170
170 $encoding ||= 'utf8'; 171 $encoding ||= 'utf8';
171 172
182 PRE_CHOMP => 1, 183 PRE_CHOMP => 1,
183 POST_CHOMP => 1, 184 POST_CHOMP => 1,
184 TRIM => 0, 185 TRIM => 0,
185 COMPILE_EXT => $this->cache ? '.ttc' : undef, 186 COMPILE_EXT => $this->cache ? '.ttc' : undef,
186 COMPILE_DIR => $this->cache, 187 COMPILE_DIR => $this->cache,
187 INCLUDE_PATH => [$inc,@includes] 188 INCLUDE_PATH => [$inc,ref $includes ? @$includes : $includes ]
188 ); 189 );
189 190
191 if ($vars) {
192 while ( my ($var,$val) = each %$vars ) {
193 $this->AddVar($var,$val);
194 }
195 }
196
190 $this->context->process($_) foreach $this->preprocess; 197 $this->context->process($_) foreach $this->preprocess;
191 198
192 $this->template($this->context->template($fileName)); 199 my $template = $this->context->template($fileName);
200 $this->title($template->title);
201 if ( $template->template ) {
202 $this->context->process($template);
203 $this->template($template->template);
204 } else {
205 $this->template($template);
206 }
207
193 } 208 }
194 209
195 sub AddVar { 210 sub AddVar {
196 my ($this,$name,$value) = @_; 211 my ($this,$name,$value) = @_;
197 212
198 $this->context->stash->set($name,$value); 213 $this->context->stash->set($name,$value);
199 } 214 }
200 215
201 sub title {
202 $_[0]->template->title;
203 }
204
205 sub Render { 216 sub Render {
206 my ($this) = @_; 217 my ($this) = @_;
207 218
208 return $this->template->process($this->context); 219 return $this->context->process($this->template);
209 } 220 }
210 221
211 # Формирует представление для произвольных объектов 222 # Формирует представление для произвольных объектов
212 sub _process { 223 sub _process {
213 my ($this,@items) = @_; 224 my ($this,@items) = @_;
246 return $result[0] if @result; 257 return $result[0] if @result;
247 carp "Looks like you have a mistake, document doesn't have a such property or child: $method"; 258 carp "Looks like you have a mistake, document doesn't have a such property or child: $method";
248 return; 259 return;
249 } 260 }
250 261
251 sub as_list {
252 $_[0]->childNodes;
253 }
254
255 sub Dispose { 262 sub Dispose {
256 my ($this) = @_; 263 my ($this) = @_;
257 264
258 $this->template(undef); 265 $this->template(undef);
259 $this->_context(undef); 266 $this->_context(undef);