diff 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
line wrap: on
line diff
--- a/Lib/IMPL/Web/TT/Document.pm	Thu Sep 30 18:11:32 2010 +0400
+++ b/Lib/IMPL/Web/TT/Document.pm	Tue Oct 05 17:20:51 2010 +0400
@@ -12,6 +12,7 @@
 use IMPL::Web::TT::Control;
 use Carp;
 use Encode();
+use Data::Dumper;
 
 BEGIN {
     private property _provider => prop_all;
@@ -82,6 +83,12 @@
                     },
                     encode => sub {
                     	Encode::encode('utf8',shift);
+                    },
+                    dump => sub {
+                    	Dumper(shift);
+                    },
+                    as_list => sub {
+                    	[ map ref($_) eq 'ARRAY' ? @$_ : $_, @_ ]
                     }
                 },
                 RECURSION => 1,
@@ -164,18 +171,22 @@
 }
 
 sub LoadFile {
-    my ($this,$filePath,$encoding,$includes,$vars) = @_;
+    my ($this,$src,$encoding,$includes,$vars) = @_;
     
-    die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath;
+    die new IMPL::InvalidArgumentException("A template parameter is required") unless $src;
+    
+    $includes = [$includes] if $includes and not ref $includes;
     
     $encoding ||= 'utf8';
     
     $this->_context(undef);
     $this->_provider(undef);
     
-    my ($vol,$dir,$fileName) = File::Spec->splitpath($filePath);
-    
-    my $inc = File::Spec->catpath($vol,$dir,'');
+    if (not ref $src) {
+    	my ($vol,$dir,$fileName) = File::Spec->splitpath($src);
+    	push @$includes, File::Spec->catpath($vol,$dir,'');
+    	$src = $fileName;
+    }
     
     $this->provider(
         ENCODING => $encoding,
@@ -185,7 +196,7 @@
         TRIM => 0,
         COMPILE_EXT => $this->cache ? '.ttc' : undef,
         COMPILE_DIR => $this->cache,
-        INCLUDE_PATH => [$inc,ref $includes ? @$includes : $includes ]
+        INCLUDE_PATH => $includes 
     );
     
     if ($vars) {
@@ -196,7 +207,7 @@
     
     $this->context->process($_) foreach $this->preprocess;
     
-    my $template = $this->context->template($fileName);
+    my $template = $this->context->template($src);
     $this->title($template->title);
     if ( $template->template ) {
     	$this->context->process($template);