Changeset 1145

Show
Ignore:
Timestamp:
10/31/08 00:34:05 (2 months ago)
Author:
laurentj
Message:

ticket #695: jtpl standalone, added ability to have subdirectories into a template directory

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/jtpl-standalone-tests.mn

    r1144 r1145  
    105105   expressions_parsing.php 
    106106 
     107sd lib/jelix/tpl/tests/foo/ 
     108dd tests/foo/ 
     109   test.tpl 
     110 
    107111sd lib/diff 
    108112dd tests/diff 
  • trunk/lib/jelix/tpl/jTpl.class.php

    r1143 r1145  
    232232        $fct = $fctname.md5($sel->module.'_'.$sel->resource.'_'.$sel->outputType.($trusted?'_t':'')); 
    233233#else 
     234        $this->_templateName = $tpl; 
    234235        $tpl = jTplConfig::$templatePath . $tpl; 
    235         $this->_templateName = basename($tpl); 
    236236        if ($outputtype=='') 
    237237            $outputtype = 'html'; 
    238238 
    239         $cachefile = jTplConfig::$cachePath.$outputtype.($trusted?'_t':'').'_'.$this->_templateName
     239        $cachefile = jTplConfig::$cachePath.dirname($this->_templateName).'/'.$outputtype.($trusted?'_t':'').'_'.basename($tpl)
    240240 
    241241        $mustCompile = jTplConfig::$compilationForce || !file_exists($cachefile); 
     
    250250 
    251251            $compiler = new jTplCompiler(); 
    252             $compiler->compile($tpl,$outputtype, $trusted, $this->userModifiers, $this->userFunctions); 
     252            $compiler->compile($this->_templateName,$tpl,$outputtype, $trusted, $this->userModifiers, $this->userFunctions); 
    253253        } 
    254254        require_once($cachefile); 
     
    278278            $this->_templateName = $sel->toString(); 
    279279#else 
     280            $this->_templateName = $tpl; 
    280281            $tpl = jTplConfig::$templatePath . $tpl; 
    281             $this->_templateName = basename($tpl); 
    282             $cachefile = jTplConfig::$cachePath.$outputtype.($trusted?'_t':'').'_'.$this->_templateName; 
     282            $cachefile = jTplConfig::$cachePath.dirname($this->_templateName).'/'.$outputtype.($trusted?'_t':'').'_'.basename($tpl); 
    283283 
    284284            $mustCompile = jTplConfig::$compilationForce || !file_exists($cachefile); 
     
    292292                include_once(JTPL_PATH . 'jTplCompiler.class.php'); 
    293293                $compiler = new jTplCompiler(); 
    294                 $compiler->compile($tpl, $outputtype, $trusted, $this->userModifiers, $this->userFunctions); 
     294                $compiler->compile($this->_templateName, $tpl, $outputtype, $trusted, $this->userModifiers, $this->userFunctions); 
    295295            } 
    296296            require_once($cachefile); 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r1143 r1145  
    100100     * @return boolean true if ok 
    101101     */ 
    102     public function compile($tplFile, $outputtype, $trusted, $userModifiers = array(), $userFunctions = array()){ 
     102    public function compile($tplName, $tplFile, $outputtype, $trusted, $userModifiers = array(), $userFunctions = array()){ 
    103103        $this->_sourceFile = $tplFile; 
    104104        $this->outputType = $outputtype; 
    105         $cachefile = jTplConfig::$cachePath .$this->outputType.($trusted?'_t':'').'_'. basename($tplFile); 
     105        $cachefile = jTplConfig::$cachePath .dirname($tplName).'/'.$this->outputType.($trusted?'_t':'').'_'. basename($tplName); 
    106106        $this->trusted = $trusted; 
    107107        $this->_modifier = array_merge($this->_modifier, $userModifiers); 
     
    152152 
    153153#if JTPL_STANDALONE 
    154         $_dirname = dirname($cachefile); 
    155         if (!@is_writable($_dirname)) { 
    156             // cache_dir not writable, see if it exists 
    157             if (!@is_dir($_dirname)) { 
    158                 throw new Exception (sprintf($this->_locales['file.directory.notexists'], $_dirname)); 
    159             } 
     154 
     155        $_dirname = jTplConfig::$cachePath.dirname($tplName).'/'; 
     156    echo $tplFile.'<br>'.$_dirname.'<br>'.$cachefile; 
     157        if (!is_dir($_dirname)) {  
     158                umask(0000);  
     159                mkdir($_dirname, 0777, true);  
     160            } else if (!@is_writable($_dirname)) { 
    160161            throw new Exception (sprintf($this->_locales['file.directory.notwritable'], $cachefile, $_dirname)); 
    161162        } 
  • trunk/lib/jelix/tpl/tests/exemple.php

    r1144 r1145  
    1212$tpl->display('test.tpl'); 
    1313 
     14$tpl = new jTpl(); 
     15$tpl->assign('titre', 'This is an other test !'); 
     16$tpl->display('foo/test.tpl'); 
    1417 
     18 
     19 
Download in other formats: Unified Diff Zip Archive