Author: Raymond Bosman
Date: 2007-02-23 11:26:50 +0100 (Fri, 23 Feb 2007)
New Revision: 4678

Log:
- Refactored cache code.
- Added some {cache_block} code. (See if it is easy to enable)

Modified:
   trunk/Template/src/parser.php
   trunk/Template/src/parsers/source_to_tst/implementations/cache.php
   
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
   
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
   trunk/Template/src/parsers/tst_to_tst/implementations/cache_information.php
   trunk/Template/src/parsers/tst_to_tst/implementations/tst_walker.php
   trunk/Template/src/template.php
   trunk/Template/tests/cache_test.php
   trunk/Template/tests/templates/cache_block.tpl

Modified: trunk/Template/src/parser.php
===================================================================
--- trunk/Template/src/parser.php       2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/src/parser.php       2007-02-23 10:26:50 UTC (rev 4678)
@@ -57,6 +57,9 @@
      */
     public $symbolTable;
 
+
+    public $hasCacheBlocks = false;
+
     /**
      * Note: The source code in $code must be loaded/created before passing it 
to this parser.
      *

Modified: trunk/Template/src/parsers/source_to_tst/implementations/cache.php
===================================================================
--- trunk/Template/src/parsers/source_to_tst/implementations/cache.php  
2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/src/parsers/source_to_tst/implementations/cache.php  
2007-02-23 10:26:50 UTC (rev 4678)
@@ -64,17 +64,20 @@
         $cacheNode = null;
         if ( $cursor->match( "cache_template" ) )
         {
+            $this->parser->hasCacheBlocks = true;
             $cacheNode = new ezcTemplateCacheTstNode( $this->parser->source, 
$this->startCursor, $cursor );
             $cacheNode->type = ezcTemplateCacheTstNode::TYPE_CACHE_TEMPLATE;
         }
-      /*elseif ($cursor->match( "cache_block" ) )
+        ////////// HERE 
+        elseif ($cursor->match( "cache_block" ) )
         {
-            $cacheNode = new ezcTemplateCacheTstNode( $this->parser->source, 
$this->startCursor, $cursor );
-            $cacheNode->type = ezcTemplateCacheTstNode::TYPE_CACHE_BLOCK;
+            $this->parser->hasCacheBlocks = true;
+            $cacheNode = new ezcTemplateCacheBlockTstNode( 
$this->parser->source, $this->startCursor, $cursor );
+            //$cacheNode->type = ezcTemplateCacheTstNode::TYPE_CACHE_BLOCK;
 
-            if ( $cacheNode->isClosingBlock )
+            if ( $this->block->isClosingBlock )
             {
-                $this->block->isClosingBlock; // Set closing block.
+                $cacheNode->isClosingBlock = true; // Set closing block.
 
                 $this->appendElement( $cacheNode );
                 $this->findNextElement( $cursor );
@@ -86,7 +89,8 @@
 
                 return true;
             }
-        }*/
+        }
+        /////////// ENDHERE
         else
         {
             return false;

Modified: 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
===================================================================
--- 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
     2007-02-23 08:43:35 UTC (rev 4677)
+++ 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
     2007-02-23 10:26:50 UTC (rev 4678)
@@ -17,7 +17,11 @@
  */
 class ezcTemplateTstToAstCachedTransformer extends 
ezcTemplateTstToAstTransformer
 {
-    protected $cacheInfo = null;
+    /**
+     * Contains the {cache_template} information. 
+     */
+    protected $cacheTemplate = null;
+
     protected $preparedCache = null;
 
     private $template = null;
@@ -30,11 +34,11 @@
     private $cacheBaseName = null;
 
 
-    public function __construct( $parser, $cacheInfo, $preparedCache ) 
+    public function __construct( $parser, $cacheTemplate, $preparedCache ) 
     {
         parent::__construct( $parser );
 
-        $this->cacheInfo = $cacheInfo;
+        $this->cacheTemplate = $cacheTemplate;
         $this->preparedCache = $preparedCache;
         
         // XXX 
@@ -229,96 +233,148 @@
         }
     }
 
+    protected function translateCacheKeys($tstKeys)
+    {
+        $cacheKeys = array();
+        foreach ( $tstKeys as $key => $value )
+        {
+            // Translate the 'old' variableName to the new name.
+            $k = $value->accept($this);
+            $cacheKeys[str_replace( "this->send->", "use:" , $k->name )] = 
$k->name;
+        }
 
-    public function visitProgramTstNode( ezcTemplateProgramTstNode $type )
+        return $cacheKeys;
+    }
+
+    protected function translateTTL($tstTTL)
     {
-        if ( $this->programNode === null )
+        $ttl = null;
+        if ( $tstTTL !== null ) 
         {
-            $this->programNode = new ezcTemplateRootAstNode();
-            $this->handleProgramHeader( $this->programNode );
-            $this->outputVariable->push( self::INTERNAL_PREFIX . "output" );
+            $ttl = $tstTTL->accept($this);
+        }
 
-            $this->programNode->appendStatement( 
$this->outputVariable->getInitializationAst() );
+        return $ttl;
+    }
 
+    protected function createCacheDir()
+    {
+        $dir = $this->template->configuration->compilePath . 
DIRECTORY_SEPARATOR . $this->template->configuration->cachedTemplatesPath;
+        if ( !file_exists( $dir ) )
+        {
+            mkdir( $dir );
+        }
+    }
 
-            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+    protected function startCaching( $cb )
+    {
+        /// startCaching(); 
+        $cplen = strlen( $this->parser->template->configuration->compilePath );
+        if ($this->template->configuration->cacheManager !== false )
+        {
+            $cb->appendStatement( new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->startCaching", array( new 
ezcTemplateVariableAstNode("this->template"), new ezcTemplateLiteralAstNode( 
$this->parser->template->stream ), new 
ezcTemplateVariableAstNode("_ezcTemplateCache" ), new 
ezcTemplateVariableAstNode("_ezcCacheKeys") ) ) ) );
+        }
+      
+        $cb->appendStatement( $this->_fopenCacheFileWriteMode() ); // $fp = 
fopen( $this->cache, "w" ); 
 
-            $cacheKeys = array();
-            foreach ( $this->cacheInfo->keys as $key => $value )
+        $cb->appendStatement( $this->_fwritePhpOpen() );                 // 
fwrite( $fp, "<" . "?php\n" );
+        $cb->appendStatement( $this->_assignEmptyString("total") );      // 
$total = ""
+        $cb->appendStatement( $this->_fwriteLiteral( "\$" . 
self::INTERNAL_PREFIX . "output = '';\n") );      // fwrite( $fp, 
"\\\$_ezcTemplate_output = '';\\n" );
+
+    }
+
+    protected function insertInCache( $cb, $type )
+    {
+        foreach ( $type->elements as $element )
+        {
+            $astNode = $element->accept( $this );
+            if ( is_array( $astNode ) )
             {
-                // Translate the 'old' variableName to the new name.
-                $k = $value->accept($this);
-                $cacheKeys[str_replace( "this->send->", "use:" , $k->name )] = 
$k->name;
+                foreach ( $astNode as $ast )
+                {
+                    $cb->statements[] = $ast;
+                }
             }
-
-            $ttl = null;
-            if ( $this->cacheInfo->ttl !== null ) 
+            else
             {
-                $ttl = $this->cacheInfo->ttl->accept($this);
-                //$this->cacheSystem->setTTL( $ttl );
+                $cb->statements[] = $astNode;
             }
+        }
+    }
 
-            $dir = $this->template->configuration->compilePath . 
DIRECTORY_SEPARATOR . $this->template->configuration->cachedTemplatesPath;
+    protected function stopCaching($cb)
+    {
+        $cb->appendStatement( $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, true) );
 
-            if ( !file_exists( $dir ) )
-            {
-                mkdir( $dir );
-            }
+        // $total .= $_ezcTemplate_output;
+        $cb->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total") );
             
-            $this->deleteOldCache();
+        // fclose($fp);  
+        $cb->appendStatement( $this->_fclose() );
 
+        // $_ezcTemplate_output = $total;
+        $cb->appendStatement( $this->_assignVariable( "total", 
self::INTERNAL_PREFIX . "output" ) );
+        $cb->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
+    }
 
-            $ifCondition = $this->notFileExistsCache();
+    protected function addUseVariables()
+    {
+        // Add the 'use' statement, that is removed by the prepareCache walker.
+        foreach ( $this->preparedCache->useVariableTst as $useVariable)
+        {
+            $use = $useVariable->accept($this);
+            if( is_array( $use ) )
+            {
+                foreach ( $use as $u )
+                {
+                    $this->programNode->appendStatement( $u );
+                }
+            }
+            else
+            {
+                $this->programNode->appendStatement( $use );
+            }
+        }
+    }
 
+ 
+    public function visitProgramTstNode( ezcTemplateProgramTstNode $type )
+    {
+        // Is the whole template cached?
+        if ($this->cacheTemplate == null)
+        {
+            // Call the parent instead.
+            return parent::visitProgramTstNode($type);
+        }
 
-            // Create the if statement that checks whether the cache file 
exists.
-            $if = new ezcTemplateIfAstNode();
-            $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
+        $this->prepareProgram(); // Program operations, nothing to do with 
caching.
 
-            $cb->condition = $ifCondition;
-            $cb->body = new ezcTemplateBodyAstNode();
+        $cacheKeys = $this->translateCacheKeys($this->cacheTemplate->keys);
 
-            // $cb->body->statements = $type->statements;
-
-
-            // Inside.
+        $this->addUseVariables();
+        $this->addCacheKeys( $this->programNode, $cacheKeys );
             
-            /// startCaching(); 
-            $cplen = strlen( 
$this->parser->template->configuration->compilePath );
-            if ($this->template->configuration->cacheManager !== false )
-            {
-                $cb->body->appendStatement( new 
ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->startCaching", array( new 
ezcTemplateVariableAstNode("this->template"), new ezcTemplateLiteralAstNode( 
$this->parser->template->stream ), new 
ezcTemplateVariableAstNode("_ezcTemplateCache" ), new 
ezcTemplateVariableAstNode("_ezcCacheKeys") ) ) ) );
-            }
-          
-            $cb->body->appendStatement( $this->_fopenCacheFileWriteMode() ); 
// $fp = fopen( $this->cache, "w" ); 
+        $ttl = $this->translateTTL($this->cacheTemplate->ttl);
 
-            $cb->body->appendStatement( $this->_fwritePhpOpen() );             
    // fwrite( $fp, "<" . "?php\n" );
-            $cb->body->appendStatement( $this->_assignEmptyString("total") );  
    // $total = ""
-            $cb->body->appendStatement( $this->_fwriteLiteral( "\$" . 
self::INTERNAL_PREFIX . "output = '';\n") );      // fwrite( $fp, 
"\\\$_ezcTemplate_output = '';\\n" );
+        $ttlStatements = $this->checkTTL( $ttl, $cacheKeys );
+        foreach ( $ttlStatements as $s )
+        {
+            $this->programNode->appendStatement( $s );
+        }
 
+        $this->createCacheDir();
+        $this->deleteOldCache();
 
+        // Create the if statement that checks whether the cache file exists.
+        $if = new ezcTemplateIfAstNode();
+        $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
 
-            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+        $cb->condition = $this->notFileExistsCache();
+        $cb->body = new ezcTemplateBodyAstNode();
 
-            foreach ( $type->elements as $element )
-            {
-                $astNode = $element->accept( $this );
-                if ( is_array( $astNode ) )
-                {
-                    foreach ( $astNode as $ast )
-                    {
-                        $cb->body->statements[] = $ast;
-                    }
-                }
-                else
-                {
-                    $cb->body->statements[] = $astNode;
+        $this->startCaching($cb->body);
+        $this->insertInCache( $cb->body, $type );
 
-                    // $this->programNode->appendStatement( $astNode );
-
-                }
-            }
-            
         // Create the 'else' part. The else should 'include' (and execute) the 
cached file. 
         $if->conditions[] = $else = new ezcTemplateConditionBodyAstNode();
         $else->body = new ezcTemplateBodyAstNode();
@@ -327,70 +383,18 @@
         $else->body->statements[] =  $this->_includeCache();
 
 
-            // /////////////////////////////////////////////
-            // 
-            // 
-            // RETURN STATEMENT inside..
-            // fwrite( $fp, "\\\$_ezcTemplate_output .= " . var_export( 
$ezcTemplate_output, true) . ";" ); 
+        if ($this->template->configuration->cacheManager !== false )
+        {
+            $cb->body->appendStatement( new 
ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->stopCaching", array() )));
+        }
 
-        // Close the caching.
-            if ($this->template->configuration->cacheManager !== false )
-            {
-                $cb->body->appendStatement( new 
ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->stopCaching", array() )));
-            }
- 
+        $this->stopCaching($cb->body);
         
-            $cb->body->appendStatement( $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, true) );
+        // Outside.
+        $this->programNode->appendStatement( $if );
 
-            // $total .= $_ezcTemplate_output;
-            $cb->body->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total") );
-                
-            // fclose($fp);  
-            $cb->body->appendStatement( $this->_fclose() );
-
-            // $_ezcTemplate_output = $total;
-            $cb->body->appendStatement( $this->_assignVariable( "total", 
self::INTERNAL_PREFIX . "output" ) );
-
-
-            $cb->body->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
-
-
-            // Outside.
-        
-            // Add the 'use' statement, that is removed by the prepareCache 
walker.
-            // XXX can probably be an array, test it.
-            foreach ( $this->preparedCache->useVariableTst as $useVariable)
-            {
-                $use = $useVariable->accept($this);
-                if( is_array( $use ) )
-                {
-                    foreach ( $use as $u )
-                    {
-                        $this->programNode->appendStatement( $u );
-                    }
-                }
-                else
-                {
-                    $this->programNode->appendStatement( $use );
-                }
-            }
-
-            $this->addCacheKeys( $this->programNode, $cacheKeys );
-            
-            $ttlStatements = $this->checkTTL( $ttl, $cacheKeys );
-            foreach ( $ttlStatements as $s )
-            {
-                $this->programNode->appendStatement( $s );
-            }
-
-            $this->programNode->appendStatement( $if );
-
-
-            
-            // RETURN STATEMENT outside..
-            $this->programNode->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
-
-        }
+        // RETURN STATEMENT outside..
+        $this->programNode->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
     }
 
     protected function addCacheKeys( $programNode, $cacheKeys )
@@ -581,7 +585,7 @@
 
     public function visitCacheTstNode( ezcTemplateCacheTstNode $type )
     {
-        if ( $type->type == ezcTemplateCacheTstNode::TYPE_CACHE_TEMPLATE )
+        if ( $type->type == ezcTemplateCacheTstNode::TYPE_CACHE_TEMPLATE ) // 
Can be removed?
         {
             // Modify the root node.
             $this->programNode->cacheTemplate = true;
@@ -612,11 +616,133 @@
         }
         else
         {
-            $cb = new ezcTemplateCacheBlockAstNode( 
$type->elements->accept($this) );
+            //$cb = new ezcTemplateCacheBlockAstNode( 
$type->elements->accept($this) );
             
             return $cb;
         }
     }
+
+
+    public function visitCacheBlockTstNode( ezcTemplateCacheBlockTstNode $type 
)
+    {
+        $newStatement = array();
+        
+        $newStatement[] = $this->_comment(" ---> start {cache_block}");
+
+
+
+
+        $ifCondition = $this->notFileExistsCache();
+
+        $if = new ezcTemplateIfAstNode();
+        $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
+
+        $cb->condition = $ifCondition;
+        $cb->body = new ezcTemplateBodyAstNode();
+
+        foreach ( $type->elements as $element )
+        {
+            $astNode = $element->accept( $this );
+            if ( is_array( $astNode ) )
+            {
+                foreach ( $astNode as $ast )
+                {
+                    $cb->body->statements[] = $ast;
+                }
+            }
+            else
+            {
+                $cb->body->statements[] = $astNode;
+            }
+        }
+        
+        // Create the 'else' part. The else should 'include' (and execute) the 
cached file. 
+        $if->conditions[] = $else = new ezcTemplateConditionBodyAstNode();
+        $else->body = new ezcTemplateBodyAstNode();
+
+        $else->body->statements = array();
+        $else->body->statements[] =  $this->_includeCache();
+
+            if ($this->template->configuration->cacheManager !== false )
+            {
+                $cb->body->appendStatement( new 
ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->stopCaching", array() )));
+            }
+ 
+        
+            $cb->body->appendStatement( $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, true) );
+
+            // $total .= $_ezcTemplate_output;
+            $cb->body->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total") );
+                
+            // fclose($fp);  
+            $cb->body->appendStatement( $this->_fclose() );
+
+            // $_ezcTemplate_output = $total;
+            $cb->body->appendStatement( $this->_assignVariable( "total", 
self::INTERNAL_PREFIX . "output" ) );
+
+
+            $cb->body->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
+
+
+// SKIP STUFF
+            $cacheKeys = array();
+            echo ("JAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+            $this->addCacheKeys( $myNode, $cacheKeys );
+
+            var_dump($myNode);
+
+            $newStatement[] = $if;
+
+            return $newStatement;
+
+
+
+
+
+        
+//        // $total .= $_ezcTemplate_output
+//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total");
+//
+//        // fwrite( $fp, "\\\<variableName> .= " . var_export( 
<variableName>, true) . ";" ); 
+//        $newStatement[] = $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, false);
+//
+//        // $_ezcTemplate_output = "";
+//        $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" );
+//
+//        // $output .= $_ezcTemplate_output;
+//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total");
+//
+//        // Place everything in the code block.
+//        $newStatement[] = new ezcTemplatePhpCodeAstNode( "\$code = '" );
+//
+//       
+//        $this->isInDynamicBlock = true;
+//        $tmp = new ezcTemplateDynamicBlockAstNode( $this->createBody( 
$node->elements ) );
+//        $tmp->escapeSingleQuote = true;
+//        $newStatement[] = $tmp;
+//        $this->isInDynamicBlock = false;
+//
+//        // $newStatement = array();
+//        $newStatement[] = new ezcTemplatePhpCodeAstNode( "';\n" );
+//
+//        // fwrite( $fp, $code );
+//        $newStatement[] = $this->_fwriteVariable( "code" ); 
+//
+//        // eval( $code );
+//        $newStatement[] = new ezcTemplateGenericStatementAstNode( 
+//            new ezcTemplateFunctionCallAstNode( "eval", array( 
$this->createVariableNode( "code" ) ) ) );
+//
+//        // $total .= _ezcTemplate_output
+//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total" ); 
+//
+//        // $ezcTemplate_output = "";
+//        $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" ); 
+
+        $newStatement[] = $this->_comment(" <--- stop {/cache_block}");
+
+        return $newStatement;
+    }
+
 }
 
 ?>

Modified: 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
===================================================================
--- 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
    2007-02-23 08:43:35 UTC (rev 4677)
+++ 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php
    2007-02-23 10:26:50 UTC (rev 4678)
@@ -518,6 +518,20 @@
    }
 
     /**
+     * Prepare for the program run.
+     * Caching uses this method as well.
+     */
+    protected function prepareProgram()
+    {
+        // Prepare for program run
+        $this->programNode = new ezcTemplateRootAstNode();
+        $this->handleProgramHeader( $this->programNode );
+        $this->outputVariable->push( self::INTERNAL_PREFIX . "output" );
+        $this->programNode->appendStatement( 
$this->outputVariable->getInitializationAst() );
+    }
+
+
+    /**
      * Visits the program TST node.
      *
      * Note: This is the first node in the TST tree.
@@ -529,14 +543,8 @@
     {
         if ( $this->programNode === null )
         {
-            // Prepare for program run
-            $this->programNode = new ezcTemplateRootAstNode();
-            $this->handleProgramHeader( $this->programNode );
+            $this->prepareProgram();
 
-            $this->outputVariable->push( self::INTERNAL_PREFIX . "output" );
-
-            $this->programNode->appendStatement( 
$this->outputVariable->getInitializationAst() );
-
             foreach ( $type->elements as $element )
             {
                 $astNode = $element->accept( $this );

Modified: 
trunk/Template/src/parsers/tst_to_tst/implementations/cache_information.php
===================================================================
--- trunk/Template/src/parsers/tst_to_tst/implementations/cache_information.php 
2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/src/parsers/tst_to_tst/implementations/cache_information.php 
2007-02-23 10:26:50 UTC (rev 4678)
@@ -37,9 +37,6 @@
 
         foreach ( $node->keys as $key )
         {
-            // XXX cannot translate.
-            // Translate the 'old' variableName to the new name.
-           // $k = $key->accept($this);
             $this->cacheKeys[] = $key;
         }
 
@@ -47,11 +44,7 @@
         if ( $node->ttl != null ) 
         {
             $this->hasTTL = true;
-            // XXX cannot translate.
-            // $this->programNode->ttl = $type->ttl->accept($this);
         }
-
-        // return new ezcTemplateNopAstNode();
     }
 
  

Modified: trunk/Template/src/parsers/tst_to_tst/implementations/tst_walker.php
===================================================================
--- trunk/Template/src/parsers/tst_to_tst/implementations/tst_walker.php        
2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/src/parsers/tst_to_tst/implementations/tst_walker.php        
2007-02-23 10:26:50 UTC (rev 4678)
@@ -355,7 +355,11 @@
     }
 
 
+    public function visitCacheBlockTstNode( ezcTemplateCacheBlockTstNode $node 
)
+    {
+    }
 
+
     protected function acceptAndUpdate( ezcTemplateTstNode &$node )
     {
         $ret = $node->accept( $this );

Modified: trunk/Template/src/template.php
===================================================================
--- trunk/Template/src/template.php     2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/src/template.php     2007-02-23 10:26:50 UTC (rev 4678)
@@ -297,15 +297,18 @@
             $parser = new ezcTemplateParser( $source, $this );
             $this->properties["tstTree"] = $parser->parseIntoNodeTree();
 
-            $fetchCacheInfo = new ezcTemplateFetchCacheInformation(); 
-            $this->properties["tstTree"]->accept( $fetchCacheInfo );
 
             // $tstTreeWalker = new ezcTemplateTstWalker();
             // $this->properties["tstTree"]->accept( $tstTreeWalker );
 
             // Check if caching is needed.
-            if ( $fetchCacheInfo->cacheTst !== null )
+
+//            if ( $fetchCacheInfo->cacheTst !== null )
+            if ( $parser->hasCacheBlocks )
             {
+                $fetchCacheInfo = new ezcTemplateFetchCacheInformation(); 
+                $this->properties["tstTree"]->accept( $fetchCacheInfo );
+
                 $cachePreparation = new ezcTemplateCachePreparation();
                 $this->properties["tstTree"]->accept( $cachePreparation );
 

Modified: trunk/Template/tests/cache_test.php
===================================================================
--- trunk/Template/tests/cache_test.php 2007-02-23 08:43:35 UTC (rev 4677)
+++ trunk/Template/tests/cache_test.php 2007-02-23 10:26:50 UTC (rev 4678)
@@ -57,24 +57,38 @@
             $this->fail( "Expected the directory to exists: " . $cacheDir );
         }
     }
-   
+  
     // 
/////////////////////////////////////////////////////////////////////////////////////////
     // Cache block is not implemented, and should give an exception.
 
+    
+    
+//    public function testCacheBlock()
+//    {
+//        $t = new ezcTemplate( );
+//        $t->send->user = new TestUser( "Bernard", "Black" );
+//
+//        try
+//        {
+//            $out = $t->process( "cache_block.tpl");
+//            $this->fail( "{cache_block} should throw an exception");
+//        }
+//        catch ( ezcTemplateParserException $e )
+//        {
+//        }
+//    }
+     
+    /*
     public function testCacheBlock()
     {
-        $t = new ezcTemplate( );
+        $t = new ezcTemplate();
         $t->send->user = new TestUser( "Bernard", "Black" );
 
-        try
-        {
-            $out = $t->process( "cache_block.tpl");
-            $this->fail( "{cache_block} should throw an exception");
-        }
-        catch ( ezcTemplateParserException $e )
-        {
-        }
+        echo "\n" . $t->configuration->compilePath . "\n";
+        $out = $t->process( "cache_block.tpl");
+        echo $out;
     }
+     */
  
     public function testCacheBlockWithBeginText()
     {
@@ -446,8 +460,6 @@
         // $this->assertEquals( "4", $t->receive->calc);
         // $this->assertEquals( "I am rubber, you are glue.", 
$t->receive->quote);
     }
-
- 
 }
 
 class TestUser

Modified: trunk/Template/tests/templates/cache_block.tpl
===================================================================
--- trunk/Template/tests/templates/cache_block.tpl      2007-02-23 08:43:35 UTC 
(rev 4677)
+++ trunk/Template/tests/templates/cache_block.tpl      2007-02-23 10:26:50 UTC 
(rev 4678)
@@ -1,8 +1,8 @@
-{cache_template}
-
 {use $user}
 [{$user->name}]
+{var $a}
 
 {cache_block}
+       {$a = 2}
        [{$user->name}]
 {/cache_block}

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to