Changeset 1142

Show
Ignore:
Timestamp:
10/30/08 10:07:07 (2 months ago)
Author:
laurentj
Message:

Worked on jtpl standalone : added a new object for the configuration, replacing the constant for better flexibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/buildjtpl.php

    r421 r1142  
    2121'PACKAGE_ZIP'=>array( 
    2222    "create a zip package", 
     23    false, 
     24    ), 
     25'WITH_TESTS'=>array( 
     26    "includes tests", 
    2327    false, 
    2428    ), 
     
    4852$SVN_REVISION = Subversion::revision(); 
    4953 
    50 if($VERSION == 'SVN'){ 
    51     $VERSION = 'SVN-'.$SVN_REVISION; 
    52     $IS_NIGHTLY = true; 
    53 }else{ 
    54     $IS_NIGHTLY = false; 
     54$IS_NIGHTLY = (strpos($VERSION,'SVN') !== false); 
     55 
     56if($IS_NIGHTLY){ 
     57    $PACKAGE_NAME='jtpl-'.str_replace('SVN', '', $VERSION); 
     58    if(substr($PACKAGE_NAME,-1,1) == '.') 
     59      $PACKAGE_NAME = substr($PACKAGE_NAME,0,-1); 
     60    $VERSION = str_replace('SVN', $SVN_REVISION, $VERSION); 
     61
     62else { 
     63    $PACKAGE_NAME='jtpl-'.$VERSION; 
    5564} 
    5665 
    5766if($PACKAGE_TAR_GZ || $PACKAGE_ZIP ){ 
    58     if($IS_NIGHTLY) 
    59         $PACKAGE_NAME = 'jtpl-nightly'; 
    60     else 
    61         $PACKAGE_NAME = 'jtpl-'.$VERSION; 
    62  
    6367    $BUILD_TARGET_PATH = jBuildUtils::normalizeDir($MAIN_TARGET_PATH).$PACKAGE_NAME.'/'; 
    6468}else{ 
     
    7478//... execution des manifests 
    7579jManifest::process('build/manifests/jtpl-standalone.mn', '.', $BUILD_TARGET_PATH, ENV::getAll()); 
     80 
     81if($WITH_TESTS) { 
     82    jManifest::process('build/manifests/jtpl-standalone-tests.mn', '.', $BUILD_TARGET_PATH, ENV::getAll()); 
     83} 
     84 
    7685 
    7786 
  • trunk/build/config/jtpl-dist.ini

    r292 r1142  
    22PACKAGE_TAR_GZ = 1 
    33PACKAGE_ZIP = 1 
     4WITH_TESTS = 0 
  • trunk/build/config/jtpl-test.ini

    r292 r1142  
    22PACKAGE_TAR_GZ = 
    33PACKAGE_ZIP = 
     4WITH_TESTS = 1 
  • trunk/build/manifests/jtpl-standalone.mn

    r706 r1142  
    5050sd lib/jelix/tpl/templates/ 
    5151dd templates/ 
    52  
    53 sd lib/jelix/tpl/tests_std/ 
    54 dd tests_std/ 
    55    exemple.php 
    56    test.tpl 
  • trunk/build/VERSION

    r154 r1142  
    1 SVN 
     11.0pre.SVN 
  • trunk/lib/jelix/tpl/jTpl.class.php

    r1070 r1142  
    232232        $fct = $fctname.md5($sel->module.'_'.$sel->resource.'_'.$sel->outputType.($trusted?'_t':'')); 
    233233#else 
    234         $tpl = JTPL_TEMPLATES_PATH . $tpl; 
     234        $tpl = jTplConfig::$templatePath . $tpl; 
    235235        $this->_templateName = basename($tpl); 
    236         $cachefile = JTPL_CACHE_PATH.$outputtype.($trusted?'_t':'').'_'.$this->_templateName; 
    237  
    238         $mustCompile = $GLOBALS['jTplConfig']['compilation_force']['force'] || !file_exists($cachefile); 
     236        $cachefile = jTplConfig::$cachePath.$outputtype.($trusted?'_t':'').'_'.$this->_templateName; 
     237 
     238        $mustCompile = jTplConfig::$compilationForce || !file_exists($cachefile); 
    239239        if (!$mustCompile) { 
    240240            if (filemtime($tpl) > filemtime($cachefile)) { 
     
    276276            $this->_templateName = $sel->toString(); 
    277277#else 
    278             $tpl = JTPL_TEMPLATES_PATH . $tpl; 
     278            $tpl = jTplConfig::$templatePath . $tpl; 
    279279            $this->_templateName = basename($tpl); 
    280             $cachefile = JTPL_CACHE_PATH.$outputtype.($trusted?'_t':'').'_'.$this->_templateName; 
    281  
    282             $mustCompile = $GLOBALS['jTplConfig']['compilation_force']['force'] || !file_exists($cachefile); 
     280            $cachefile = jTplConfig::$cachePath.$outputtype.($trusted?'_t':'').'_'.$this->_templateName; 
     281 
     282            $mustCompile = jTplConfig::$compilationForce || !file_exists($cachefile); 
    283283            if (!$mustCompile) { 
    284284                if (filemtime($tpl) > filemtime($cachefile)) { 
     
    291291                $compiler = new jTplCompiler(); 
    292292                $compiler->setUserPlugins( $this->userModifiers, $this->userFunctions); 
    293                 $compiler->compile($tpl,$outputtype,$trusted); 
     293                $compiler->compile($tpl, $outputtype, $trusted); 
    294294            } 
    295295            require_once($cachefile); 
     
    358358    public static function getEncoding (){ 
    359359#if JTPL_STANDALONE 
    360         return $GLOBALS['jTplConfig']['charset']
     360        return jTplConfig::$charset
    361361#else 
    362362        return $GLOBALS['gJConfig']->charset; 
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r1112 r1142  
    8181 
    8282#if JTPL_STANDALONE 
    83         require_once(JTPL_LOCALES_PATH.$GLOBALS['jTplConfig']['lang'].'.php'); 
    84         $this->_locales = $GLOBALS['jTplConfig']['locales']
     83        require_once(jTplConfig::$localizedMessagesPath.jTplConfig::$lang.'.php'); 
     84        $this->_locales = jTplConfig::$localizedMessages
    8585#endif 
    8686    } 
     
    9898        $this->_sourceFile = $tplFile; 
    9999        $this->outputType = ($outputtype==''?'html':$outputtype); 
    100         $cachefile = JTPL_CACHE_PATH .$this->outputType.($trusted?'_t':'').'_'. basename($tplFile); 
     100        $cachefile = jTplConfig::$cachePath .$this->outputType.($trusted?'_t':'').'_'. basename($tplFile); 
    101101        $this->trusted = $trusted; 
    102102        $this->_modifier = array_merge($this->_modifier, $userModifiers); 
     
    499499                        } else { 
    500500#if JTPL_STANDALONE 
    501                             $result.='${$GLOBALS[\'jTplConfig\'][\'localesGetter\']}(\''.$locale.'\')'; 
     501                            $result.='${jTplConfig::$localesGetter}(\''.$locale.'\')'; 
    502502#else 
    503503                            $result.='jLocale::get(\''.$locale.'\')'; 
     
    575575 
    576576#if JTPL_STANDALONE 
    577         if(isset($GLOBALS['jTplConfig']['tplpluginsPathList'][$this->outputType])){ 
    578             foreach($GLOBALS['jTplConfig']['tplpluginsPathList'][$this->outputType] as $path){ 
     577        if(isset(jTplConfig::$pluginPathList[$this->outputType])){ 
     578            foreach(jTplConfig::$pluginPathList[$this->outputType] as $path){ 
    579579#else 
    580580        global $gJConfig; 
  • trunk/lib/jelix/tpl/jtpl_standalone_prepend.php

    r1026 r1142  
    55* @contributor Laurent Jouanneau 
    66* @copyright   2006 Mathaud Loic 
    7 * @copyright   2006 Jouanneau Laurent 
     7* @copyright   2006-2008 Jouanneau Laurent 
    88* @link        http://www.jelix.org 
    99* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
    1010*/ 
    11 if(!defined('JTPL_PATH')) 
    12     define('JTPL_PATH', dirname(__FILE__) . '/'); 
    13 if(!defined('JTPL_CACHE_PATH')) 
    14     define('JTPL_CACHE_PATH', realpath(JTPL_PATH.'temp/') . '/'); 
    15 if(!defined('JTPL_PLUGIN_PATH')) 
    16     define('JTPL_PLUGIN_PATH', realpath(JTPL_PATH.'plugins/') . '/'); 
    17 if(!defined('JTPL_LOCALES_PATH')) 
    18     define('JTPL_LOCALES_PATH', realpath(JTPL_PATH.'locales/') . '/'); 
    19 if(!defined('JTPL_TEMPLATES_PATH')) 
    20     define('JTPL_TEMPLATES_PATH', realpath(JTPL_PATH.'templates/') . '/'); 
    2111 
    22 $GLOBALS['jTplConfig'] = array( 
    23     'tplpluginsPathList'=> array( 
    24         'common' => array(JTPL_PLUGIN_PATH . 'common/'), 
    25         'html' => array(JTPL_PLUGIN_PATH . 'html/') 
    26     ), 
    27     'compilation_force' => false, 
    28     'lang'=>'fr', 
    29     'charset'=>'UTF-8', 
    30     'localesGetter' => 'getLocales' 
    31 ); 
     12define('JTPL_PATH', dirname(__FILE__) . '/'); 
     13 
     14function getDummyLocales($locale) { 
     15    return $locale; 
     16
     17 
     18class jTplConfig { 
     19 
     20    /** 
     21     * the path of the directory which contains the 
     22     * templates 
     23     */ 
     24    static $templatePath = ''; 
     25 
     26    /** 
     27     * boolean which indicates if the templates 
     28     * should be compiled at each call or not 
     29     */ 
     30    static $compilationForce = false; 
     31 
     32    /** 
     33     * the lang activated in the templates 
     34     */ 
     35    static $lang = 'fr'; 
     36 
     37    /** 
     38     * the charset used in the templates 
     39     */ 
     40    static $charset = 'UTF-8'; 
     41 
     42    /** 
     43     * the function which allow to retrieve the locales used in your templates 
     44     */ 
     45    static $localesGetter = 'getDummyLocales'; 
     46 
     47    /** 
     48     * the path of the cache directory 
     49     */ 
     50    static $cachePath = ''; 
     51 
     52    /** 
     53     * the path of the directory which contains the 
     54     * localization files of jtpl 
     55     */ 
     56    static $localizedMessagesPath = ''; 
     57 
     58    /** 
     59     * @internal 
     60     */ 
     61    static $localizedMessages = array(); 
     62 
     63    /** 
     64     * @internal 
     65     */ 
     66    static $pluginPathList = array(); 
     67     
     68     
     69    static function addPluginsRepository($path){ 
     70        if(trim($path) == '') return; 
     71        if(!file_exists($path)){ 
     72            throw new Exception('The given path, '.$path.' doesn\'t exists'); 
     73        } 
     74        if(substr($path,-1) !='/') 
     75            $path.='/'; 
     76 
     77        if ($handle = opendir($path)) { 
     78            while (false !== ($f = readdir($handle))) { 
     79                if ($f{0} != '.' && is_dir($path.$f)) { 
     80                    self::$pluginPathList[$f][]= $path.$f.'/'; 
     81                } 
     82            } 
     83            closedir($handle); 
     84        }         
     85    } 
     86
     87 
     88jTplConfig::$cachePath = realpath(JTPL_PATH.'temp/') . '/'; 
     89jTplConfig::$localizedMessagesPath = realpath(JTPL_PATH.'locales/') . '/'; 
     90jTplConfig::$templatePath = realpath(JTPL_PATH.'templates/') . '/'; 
     91 
     92jTplConfig::addPluginsRepository(realpath(JTPL_PATH.'plugins/')); 
    3293 
    3394include(JTPL_PATH . 'jTpl.class.php'); 
    3495 
    3596 
    36 function getLocales($locale) { 
    37     return $locale; 
    38 } 
    3997 
    4098 
  • trunk/lib/jelix/tpl/locales/fr.php

    r1026 r1142  
    11<?php 
    22 
    3 $GLOBALS['jTplConfig']['locales'] =array( 
     3jTplConfig::$localizedMessages =array( 
    44    'errors.tpl.not.found'=>'Le fichier template %s est introuvable', 
    55    'file.directory.notexists'=>'Le répertoire demandé (%s) n\'existe pas', 
  • trunk/lib/jelix/tpl/tests_std/exemple.php

    r1026 r1142  
    11<?php  
    22 
     3include '../jtpl_standalone_prepend.php'; 
    34 
    4 include 'jtpl_standalone_prepend.php'; 
     5jTplConfig::$templatePath = dirname(__FILE__) . '/'; 
    56 
    67$tpl = new jTpl(); 
     
    89$countries = array('France', 'Italie', 'Espagne', 'Belgique'); 
    910$tpl->assign('countries', $countries); 
    10 $tpl->assign('titre', 'Ceci est un test !'); 
     11$tpl->assign('titre', 'This is a test !'); 
    1112$tpl->display('test.tpl'); 
    1213 
  • trunk/testapp/scripts/tests.php

    r919 r1142  
    2121$jelix->process(new jCmdLineRequest()); 
    2222 
    23 ?> 
Download in other formats: Unified Diff Zip Archive