Beispiel #1
0
 /**
  * Render
  * @param View $view
  * @param string $path
  * @param array $params
  * @return boolean
  */
 public function render($view, $path, array $params = [])
 {
     $this->fire('HamlEngineRender', [$view, $path, $params]);
     $php = $this->getPhpCacheFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_php;
     $haml = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_haml;
     $yml = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_yml;
     if (file_exists($yml)) {
         $meta = Yaml::parse(file_get_contents($yml));
     } else {
         $meta = [];
     }
     $path_php = false;
     $engine = $this->php_engine;
     if (file_exists($haml)) {
         if (!file_exists($php) || filemtime($php) != filemtime($haml)) {
             $this->log()->debug("render haml file `{$haml}`");
             $haml_code = file_get_contents($haml);
             $php_code = $this->haml_engine->compileString($haml_code, $haml);
             $this->filesystem()->checkPathDir(dirname($php));
             file_put_contents($php, $php_code);
             touch($haml);
         }
         $path_php = $path;
         $engine->setFolder($this->getPhpCacheFolder())->setSuffixPhp($this->suffix_php);
     } else {
         $file = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->ext_php;
         if (file_exists($file)) {
             $path_php = $path;
             $engine->setFolder($this->getFolder())->setSuffixPhp($this->ext_php);
         }
     }
     if ($path_php) {
         $this->renderStyle($view, $path);
         $this->renderScript($view, $path);
         $this->php_engine->setMeta($meta)->render($view, $path_php, $params);
     } else {
         return false;
     }
     return true;
 }