Changeset 1507

Show
Ignore:
Timestamp:
04/06/08 15:47:09 (1 month ago)
Author:
mikey
Message:

refactored rasmus template engine to be much simpler in usage and configuration
added unit test for net::stubbles::websites::rasmus::stubRasmusProcessor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/rasmus/stubRasmusProcessor.php

    r1442 r1507  
    77 * @subpackage  websites_rasmus 
    88 */ 
    9 stubClassLoader::load('net::stubbles::websites::processors::stubAbstractProcessor', 
    10                       'net::stubbles::websites::processors::stubPageBasedProcessor' 
     9stubClassLoader::load('net::stubbles::util::stubRegistry', 
     10                      'net::stubbles::util::validators::stubRegexValidator', 
     11                      'net::stubbles::websites::processors::stubAbstractProcessor' 
    1112); 
    1213/** 
     
    1617 * @subpackage  websites_rasmus 
    1718 */ 
    18 class stubRasmusProcessor extends stubAbstractProcessor implements stubPageBasedProcessor 
     19class stubRasmusProcessor extends stubAbstractProcessor 
    1920{ 
    2021    /** 
    21      * page to display 
     22     * registry key under which the page path is stored 
     23     */ 
     24    const PAGEPATH_REGISTRY_KEY = 'net.stubbles.websites.rasmus.pagePath'; 
     25    /** 
     26     * the default path where pages are located 
    2227     * 
    23      * @var  stubPage 
     28     * @var  string 
    2429     */ 
    25     protected $page
     30    protected static $defaultPath
    2631 
    2732    /** 
    28      * selects the page to display with help of the page factory 
    29      * 
    30      * @param  stubPageFactory  $pageFactory 
     33     * static initializer 
    3134     */ 
    32     public function selectPage(stubPageFactory $pageFactory) 
     35    // @codeCoverageIgnoreStart 
     36    public static function __static() 
    3337    { 
    34         $this->page = $pageFactory->getPage($pageFactory->getPageName($this->request)); 
     38        self::$defaultPath = realpath(stubConfig::getConfigPath() . '/../pages'); 
    3539    } 
     40    // @codeCoverageIgnoreEnd 
    3641 
    3742    /** 
     
    4045    public function process() 
    4146    { 
    42         $this->page->render($this->request, $this->session, $this->response); 
    43         $this->response->addHeader('X-Generator', 'Rasmus\' Template Engine :-) powered by Stubbles, http://stubbles.net/'); 
     47        $this->response->write($this->render($this->getPageName())); 
     48    } 
     49 
     50    /** 
     51     * retrieves the page name 
     52     * 
     53     * @return  string 
     54     */ 
     55    protected function getPageName() 
     56    { 
     57        if ($this->request->hasValue('page') === true) { 
     58            $pageName = $this->request->getValidatedValue(new stubRegexValidator('/([a-zA-Z0-9_])/'), 'page'); 
     59            if (null != $pageName && file_exists(stubRegistry::getConfig(self::PAGEPATH_REGISTRY_KEY, self::$defaultPath) . DIRECTORY_SEPARATOR . $pageName . '.php') === true) { 
     60                return $pageName; 
     61            } 
     62        } 
     63 
     64        return 'index'; 
     65    } 
     66 
     67    /** 
     68     * does the real rendering by including the page file 
     69     * 
     70     * @param   string  $pageName 
     71     * @return  string 
     72     */ 
     73    protected function render($pageName) 
     74    { 
     75        ob_start(); 
     76        include stubRegistry::getConfig(self::PAGEPATH_REGISTRY_KEY, self::$defaultPath) . DIRECTORY_SEPARATOR . $pageName . '.php'; 
     77        return ob_get_clean(); 
    4478    } 
    4579} 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r1504 r1507  
    5252        $suite->addTestFile($dir . '/processors/stubProcessorResolverXJConfFactoryTestCase.php'); 
    5353        $suite->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); 
     54         
     55        // rasmus 
     56        $suite->addTestFile($dir . '/rasmus/stubRasmusProcessorTestCase.php'); 
    5457 
    5558        // xml