7 * Load a template, if the template does not exists or it
8 * has changed, this class will compile it and update the cache
12 protected static $cache_dir;
13 protected static $templates_dir;
15 private function __construct()
17 /* The class can't be instanced */
20 public static function setCacheDir($dir)
23 throw new Exception("{$dir} is not a valid directory");
25 if (!is_writable($dir)) {
26 throw new Exception("{$dir} can't be written");
28 self
::$cache_dir = $dir;
31 public static function setTemplateDir($dir)
34 throw new Exception("{$dir} is not a valid directory");
36 self
::$templates_dir = $dir;
39 // doInclude(string $file) {{{
41 * Load a PHP file using Haanga's root dir as
44 * @param string $file File
48 public static function doInclude($file)
50 require_once dirname(__FILE__
)."/".$file;
54 public static function Load($file, $vars = array(), $return=FALSE, $blocks=array())
57 if (empty(self
::$cache_dir) ||
empty(self
::$templates_dir)) {
58 throw new Exception("Cache dir or template dir is missing");
61 $tpl = self
::$templates_dir.'/'.$file;
63 $php = self
::$cache_dir.'/'.$fnc.'.php';
65 if (!is_file($php) && !is_file($tpl)) {
66 throw new Exception("View {$file} doesn't exists");
69 if (!is_file($php) ||
filemtime($tpl) > filemtime($php)) {
71 require_once dirname(__FILE__
)."/haanga.php";
72 $compiler = new Haanga_Main_Runtime
;
75 //$compiler->setDebug($php.".dump");
76 $code = $compiler->compile_file($tpl, $tpl);
77 file_put_contents($php, "<?php".$code);
79 $callback = "haanga_".$fnc;
80 if (!is_callable($callback)) {
84 return $callback($vars, $return, $blocks);
93 * vim600: sw=4 ts=4 fdm=marker