HamlPHP::parseFile PHP Method

parseFile() public method

Parses a haml file and returns the compile result.
public parseFile ( string $fileName )
$fileName string
    public function parseFile($fileName)
    {
        if ($this->_cacheEnabled) {
            if ($this->_storage === null) {
                throw new Exception('Storage not set');
            }
            $fileId = $this->_storage->generateContentId($fileName);
            if ($this->isCacheEnabled() && $this->_storage->isFresh($fileId, $fileName)) {
                return $this->_storage->fetch($fileId);
            }
            // file is not fresh, so compile and cache it
            $this->_storage->cache($fileId, $this->_compiler->parseFile($fileName));
            return $this->_storage->fetch($fileId);
        }
        // not using cache
        return $this->_compiler->parseFile($fileName);
    }

Usage Example

Example #1
0
 /**
  * Renders a template using Haml.php.
  *
  * @see View::render()
  * @throws RuntimeException If Haml lib directory does not exist.
  * @param string $template The template name specified in Slim::render()
  * @return string
  */
 public function render($template)
 {
     if (!is_dir(self::$hamlDirectory)) {
         throw new RuntimeException('Cannot set the HamlPHP lib directory : ' . self::$hamlDirectory . '. Directory does not exist.');
     }
     require_once self::$hamlDirectory . '/HamlPHP/HamlPHP.php';
     require_once self::$hamlDirectory . '/HamlPHP/Storage/FileStorage.php';
     $parser = new HamlPHP(new FileStorage(self::$hamlCacheDirectory));
     return $parser->parseFile(self::$hamlTemplatesDirectory . $template, $this->data);
 }
All Usage Examples Of HamlPHP::parseFile