changeset 117:0475eb382085

Controls support (RC1)
author wizard
date Thu, 03 Jun 2010 02:41:44 +0400
parents 1722ca51537c
children 79cdd6c86409 8114aaa7feba
files Lib/IMPL/Web/TT/Control.pm Lib/IMPL/Web/TT/Document.pm
diffstat 2 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/TT/Control.pm	Mon May 31 08:30:39 2010 +0400
+++ b/Lib/IMPL/Web/TT/Control.pm	Thu Jun 03 02:41:44 2010 +0400
@@ -19,7 +19,7 @@
 	
 	if ($this->document) {
 		# load a template
-		#$args{template} = $this->document->context->template($args{template}) if ($args{template});
+		$args{template} = $this->document->context->template($args{template}) if ($args{template} and not ref $args{template});
 	}
 	$this->template($args{template}) if $args{template};
 
@@ -32,11 +32,11 @@
 	
 	if ($this->document) {
 		if ($this->template) {
-			return $this->document->context->include($this->template,{ this => $this });
+			return $this->document->context->include($this->template,{ this => $this }) ;
 		} elsif ($this->document->presenter) {
 			return $this->document->presenter->print($this);
 		} else {
-			return $this->toString();
+			return $this->toString().": ".$this->controlClass() . ": ".$this->path;
 		}
 	}
 }
--- a/Lib/IMPL/Web/TT/Document.pm	Mon May 31 08:30:39 2010 +0400
+++ b/Lib/IMPL/Web/TT/Document.pm	Thu Jun 03 02:41:44 2010 +0400
@@ -90,7 +90,7 @@
 	
 	die new IMPL::InvalidArgumentException("A controlClass must be a single word",$controlClass) unless $controlClass =~ /^\w+$/;
 	
-	eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless ref $type or $INC{$type};
+	eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless eval { $type->can('new') };
 	
 	die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node');
 	
@@ -101,6 +101,33 @@
 	};
 }
 
+sub require {
+	my ($this,$template) = @_;
+	
+	my $doc = $this->context->template($template);
+	
+	die new IMPL::InvalidOperationException("A specified template isn't a document",$template) unless eval{ $doc -> isa('Template::Document') };
+	
+	my $controlClass = $doc->class;
+	my $type = $doc->nativeType;
+	my $controlTemplate;
+	my $out = "";
+	
+	die new IMPL::InvalidOperationException("A specified template isn't a control",$template) unless $controlClass;
+	
+	if (not $this->isControlClass($controlClass)) {
+		if ($doc->template) {
+			$controlTemplate = $doc->blocks()->{$doc->template} || $this->context->template($doc->template);
+			$out = $this->context->process($doc);
+		} else {
+			$controlTemplate = $doc;
+		}
+		$this->registerControlClass($controlClass,$type,{ template => $controlTemplate } );
+	}
+	
+	return $out;
+}
+
 sub isControlClass {
 	my ($this,$name) = @_;
 	return $this->_controlClassMap->{$name} ? 1 : 0;