# HG changeset patch # User wizard # Date 1275518504 -14400 # Node ID 0475eb382085642bb4e10252f25232ddbd948a6e # Parent 1722ca51537cdb1483fd5fbf0de991b58eba8db9 Controls support (RC1) diff -r 1722ca51537c -r 0475eb382085 Lib/IMPL/Web/TT/Control.pm --- 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; } } } diff -r 1722ca51537c -r 0475eb382085 Lib/IMPL/Web/TT/Document.pm --- 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;