Mercurial > pub > Impl
comparison Lib/IMPL/Web/TT/Document.pm @ 156:8638dd1374bf
Added template property to IMPL::Web::QueryHandler::PageFormat (this allows to specify exact template (filename, ref to a scalar, ref to a file handle)).
author | wizard |
---|---|
date | Tue, 05 Oct 2010 17:20:51 +0400 |
parents | eb478083f72b |
children | c7652cf29a80 |
comparison
equal
deleted
inserted
replaced
155:05df123a2ff1 | 156:8638dd1374bf |
---|---|
10 use Scalar::Util qw(blessed); | 10 use Scalar::Util qw(blessed); |
11 use IMPL::Web::TT::Collection; | 11 use IMPL::Web::TT::Collection; |
12 use IMPL::Web::TT::Control; | 12 use IMPL::Web::TT::Control; |
13 use Carp; | 13 use Carp; |
14 use Encode(); | 14 use Encode(); |
15 use Data::Dumper; | |
15 | 16 |
16 BEGIN { | 17 BEGIN { |
17 private property _provider => prop_all; | 18 private property _provider => prop_all; |
18 private property _context => prop_all; | 19 private property _context => prop_all; |
19 public property cache => prop_all; | 20 public property cache => prop_all; |
80 render => sub { | 81 render => sub { |
81 $this->_process(@_); | 82 $this->_process(@_); |
82 }, | 83 }, |
83 encode => sub { | 84 encode => sub { |
84 Encode::encode('utf8',shift); | 85 Encode::encode('utf8',shift); |
86 }, | |
87 dump => sub { | |
88 Dumper(shift); | |
89 }, | |
90 as_list => sub { | |
91 [ map ref($_) eq 'ARRAY' ? @$_ : $_, @_ ] | |
85 } | 92 } |
86 }, | 93 }, |
87 RECURSION => 1, | 94 RECURSION => 1, |
88 LOAD_TEMPLATES => [$this->provider] | 95 LOAD_TEMPLATES => [$this->provider] |
89 ) | 96 ) |
162 | 169 |
163 die new IMPL::InvalidArgumentException("A view object is required") unless blessed($value) and $value->isa('Template::View'); | 170 die new IMPL::InvalidArgumentException("A view object is required") unless blessed($value) and $value->isa('Template::View'); |
164 } | 171 } |
165 | 172 |
166 sub LoadFile { | 173 sub LoadFile { |
167 my ($this,$filePath,$encoding,$includes,$vars) = @_; | 174 my ($this,$src,$encoding,$includes,$vars) = @_; |
168 | 175 |
169 die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath; | 176 die new IMPL::InvalidArgumentException("A template parameter is required") unless $src; |
177 | |
178 $includes = [$includes] if $includes and not ref $includes; | |
170 | 179 |
171 $encoding ||= 'utf8'; | 180 $encoding ||= 'utf8'; |
172 | 181 |
173 $this->_context(undef); | 182 $this->_context(undef); |
174 $this->_provider(undef); | 183 $this->_provider(undef); |
175 | 184 |
176 my ($vol,$dir,$fileName) = File::Spec->splitpath($filePath); | 185 if (not ref $src) { |
177 | 186 my ($vol,$dir,$fileName) = File::Spec->splitpath($src); |
178 my $inc = File::Spec->catpath($vol,$dir,''); | 187 push @$includes, File::Spec->catpath($vol,$dir,''); |
188 $src = $fileName; | |
189 } | |
179 | 190 |
180 $this->provider( | 191 $this->provider( |
181 ENCODING => $encoding, | 192 ENCODING => $encoding, |
182 INTERPOLATE => 1, | 193 INTERPOLATE => 1, |
183 PRE_CHOMP => 1, | 194 PRE_CHOMP => 1, |
184 POST_CHOMP => 1, | 195 POST_CHOMP => 1, |
185 TRIM => 0, | 196 TRIM => 0, |
186 COMPILE_EXT => $this->cache ? '.ttc' : undef, | 197 COMPILE_EXT => $this->cache ? '.ttc' : undef, |
187 COMPILE_DIR => $this->cache, | 198 COMPILE_DIR => $this->cache, |
188 INCLUDE_PATH => [$inc,ref $includes ? @$includes : $includes ] | 199 INCLUDE_PATH => $includes |
189 ); | 200 ); |
190 | 201 |
191 if ($vars) { | 202 if ($vars) { |
192 while ( my ($var,$val) = each %$vars ) { | 203 while ( my ($var,$val) = each %$vars ) { |
193 $this->AddVar($var,$val); | 204 $this->AddVar($var,$val); |
194 } | 205 } |
195 } | 206 } |
196 | 207 |
197 $this->context->process($_) foreach $this->preprocess; | 208 $this->context->process($_) foreach $this->preprocess; |
198 | 209 |
199 my $template = $this->context->template($fileName); | 210 my $template = $this->context->template($src); |
200 $this->title($template->title); | 211 $this->title($template->title); |
201 if ( $template->template ) { | 212 if ( $template->template ) { |
202 $this->context->process($template); | 213 $this->context->process($template); |
203 $this->template($template->template); | 214 $this->template($template->template); |
204 } else { | 215 } else { |