Example #1
0
 /**
  * Set debug from config file and handle passed file name
  *
  * @param  string  $name
  */
 public function __construct($name = NULL, $data = NULL, $type = NULL)
 {
     // Attempt to autoload template if name is empty
     if (!$name) {
         $name = $this->haml_autoload();
     }
     // load file
     $this->_file = $this->load_file_path($name);
     // load cache library
     $cache = new Kohaml_Cache('kohaml');
     $this->cache_file = $cache->check($this->_file);
     $debug = Kohana::config('kohaml.debug');
     // if cache file does not exists then cache output from Kohaml
     if (!$cache->skip() || $debug) {
         $kohaml = new Kohaml($debug);
         // put file contents into an array then pass to render
         $output = $kohaml->compile(file($this->_file), $name);
         // cache output
         if (!$debug) {
             $cache->cache($output);
         }
     }
     if (!$type) {
         $type = Kohana::config('kohaml.ext');
     }
     // taken from view construct
     $this->set_filename($name, $type);
     if (is_array($data) and !empty($data)) {
         // Preload data using array_merge, to allow user extensions
         $this->kohana_local_data = array_merge($this->kohana_local_data, $data);
     }
 }
Example #2
0
 /**
  * Handler
  *
  * @param   mixed    $files
  * @param   boolean  $style of the output
  * @return  string
  */
 private static function handler($files, $style)
 {
     // set variables
     self::$cache_folder = Kohana::config('kosass.cache_folder');
     // if files is not an array convert to one
     if (!is_array($files)) {
         $files = array($files);
     }
     // set files
     self::$files = $files;
     // add absolute path to file names
     self::get_files_path();
     // load cache library
     $cache = new Kohaml_Cache('kosass');
     // check for debug
     $debug = FALSE;
     //Kohana::config('kosass.debug');
     // init Kosass
     $kosass = new Kosass($style, $debug);
     // loop files
     foreach (self::$files as $file) {
         // add cache file name
         self::$cache_files[] = $cache->check($file);
         $name = basename($file, '.' . Kohana::config('kosass.ext'));
         // if cache file does not exists then cache output from Kohaml
         if (!$cache->skip() || $debug) {
             // put file contents into an array then pass to render
             $output = $kosass->compile(file($file), $name);
             // cache output
             if (!$debug) {
                 $cache->cache($output);
             }
         }
     }
     // destroy static variables
     self::destruct();
 }