You are here

public function HamlParser::parse in Sassy 7

* Parses a Haml file. * If an output directory is given the resulting PHP is cached. *

Parameters

string path to file to parse: * @param mixed boolean: true to use the default cache directory, false to use * the source file directory. string: path to the cache directory. * null: disable caching * @param string output file extension * @param integer permission for the output directory and file * @return mixed string: the resulting PHP if no output directory is specified * or the output filename if the output directory is specified. * boolean: false if the output file could not be written.

File

phamlp/haml/HamlParser.php, line 400

Class

HamlParser
HamlParser class. Parses {@link http://haml-lang.com/ Haml} view files. @package PHamlP @subpackage Haml

Code

public function parse($sourceFile, $cacheDir = null, $permission = 0755, $sourceExtension = '.haml', $outputExtension = '.php') {
  if (is_string($cacheDir) || is_bool($cacheDir)) {
    if (is_bool($cacheDir)) {
      $cacheDir = $cacheDir ? dirname(__FILE__) . DIRECTORY_SEPARATOR . 'haml-cache' : dirname($sourceFile);
    }
    $outputFile = $cacheDir . DIRECTORY_SEPARATOR . basename($sourceFile, $sourceExtension) . $outputExtension;
    if (!is_file($outputFile) || @filemtime($sourceFile) > @filemtime($outputFile)) {
      if (!is_dir($cacheDir)) {
        @mkdir($cacheDir, $permission);
      }
      $return = file_put_contents($outputFile, $this
        ->haml2PHP($sourceFile)) === false ? false : $outputFile;
      if ($return !== false) {
        @chmod($outputFile, $permission);
      }
    }
    else {
      $return = $outputFile;
    }
  }
  else {
    $return = $this
      ->haml2PHP($sourceFile);
  }
  return $return;
}