changeset 291:5d14baa35790

*TTView: fixed template selectors mechanism
author cin
date Thu, 21 Feb 2013 03:44:02 +0400
parents 7b0dad6117d5
children 6dc1c369eb71
files Lib/IMPL/Web/Handler/TTView.pm Lib/IMPL/Web/View/TTDocument.pm Lib/IMPL/Web/View/TTFactory.pm
diffstat 3 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Handler/TTView.pm	Wed Feb 20 17:24:57 2013 +0400
+++ b/Lib/IMPL/Web/Handler/TTView.pm	Thu Feb 21 03:44:02 2013 +0400
@@ -1,6 +1,7 @@
 package IMPL::Web::Handler::TTView;
 use strict;
 
+use Carp qw(carp);
 use List::Util qw(first);
 use IMPL::lang;
 use IMPL::Const qw(:prop);
@@ -55,6 +56,15 @@
         env         => _cached($action->context->{environment}),
         ImportClass => sub {
             my $class = shift;
+            
+            carp "ImportClass is obsolete use import instead";
+            
+            $class = Loader->safe->Require($class);
+            
+            return Factory->new($class);
+        },
+        import      => sub {
+            my $class = shift;
 
             $class = Loader->safe->Require($class);
             
@@ -168,6 +178,9 @@
             my @selector = @{$rule->{selector}};
             
             my $part = shift @selector;
+            
+            # if this rule doesn't have a selector
+            next unless $part;
 
             if ($part->{any}) {
                 #keep the rule for the next try
@@ -176,9 +189,6 @@
                 $part = shift @selector while $part->{any};
             }
             
-            # if this rule doesn't have a selector
-            next unless $part;
-            
             my $newRule = {
                 selector => \@selector,
                 data => $rule->{data},
--- a/Lib/IMPL/Web/View/TTDocument.pm	Wed Feb 20 17:24:57 2013 +0400
+++ b/Lib/IMPL/Web/View/TTDocument.pm	Thu Feb 21 03:44:02 2013 +0400
@@ -54,7 +54,10 @@
     $require = sub {
         my $control = shift;
         
-        carp("Cant load control $control outside the rendering procedure") unless $self;
+        unless($self) {
+            carp("Cant load control $control outside the rendering procedure");
+            return;
+        }
         
         if (my $factory = $controls{$control}) {
             return $factory;
@@ -89,8 +92,7 @@
     $documentContext = _clone_context( $this->context );
     
     $this->context->stash->set(require => $require);
-    $this->context->stash->set(document => sub { $self });
-    
+    $this->context->stash->set(document => sub { $self });    
     
     my $text = eval {
     
--- a/Lib/IMPL/Web/View/TTFactory.pm	Wed Feb 20 17:24:57 2013 +0400
+++ b/Lib/IMPL/Web/View/TTFactory.pm	Thu Feb 21 03:44:02 2013 +0400
@@ -45,6 +45,11 @@
 sub MergeParameters {
     my ($this,$name,$refProps) = @_;
     
+    if (ref $name) {
+        $refProps = $name;
+        $name = (ref $refProps eq 'HASH' and ($refProps->{name} || $refProps->{id})) || '*anonymous*';
+    }
+    
     my $base = $this->base;
     
     $this->context->localise();