6 * just need to add this to HTML
8 * <script src="{baseURL}/Core/JsTemplate.js">
14 * first part should return a list of files to include.
15 * $x = new Pman_Core_JsTemplate($cfg)
19 * second part should compile and deliver.
23 * // should return {baseurl}/Pman/JsTemplate/mod/file
30 class Pman_Core_JsTemplate extends Pman {
42 header('Content-type: text/javascript');
44 $mods = $this->modulesList();
45 foreach($mods as $mod) {
46 $dir = $this->rootDir.'/Pman/'. $mod . '/jtemplates';
47 if (!file_exists($dir)) {
48 echo '// missing directory '. htmlspecialchars($dir) ."\n";
51 foreach(glob("$dir/*.html") as $fn) {
57 //new HTML_FlexyFramework_JsTemplate('/home/alan/gitlive/web.mtrack/MTrackWeb/jtemplates/TimelineTicket.html', 'Pman.template.TimelineTicket');
69 function compile($fn, $name)
71 // cached? - check file see if we have cached contents.
74 $contents = file_get_contents($fn);
75 $ar = preg_split('/(\{[^\}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
76 //echo '<PRE>' . htmlspecialchars(print_r($ar,true));
80 $ret[] = "var $name = function(t) {\n var ret=[];\n";
82 foreach($ar as $item) {
83 $in = str_repeat(" ", $indent);
85 //var_Dump(substr($item,-3,2));
87 case (!strlen($item)):
90 case ($item[0] != '{'):
91 if (!strlen(trim($item))) {
94 $ret[] = $in . "ret+= ". json_encode($item) . ";";
97 case (substr($item,1,3) == 'if('):
98 $ret[] = $in . substr($item,1,-1) . ' {';
102 case (substr($item,1,4) == 'end:'):
104 $in = str_repeat(" ", $indent);
108 case (substr($item,1,7) == 'return:'):
109 $ret[] = $in . "return;";
112 case (substr($item,1,9) == 'function:'):
114 $def = substr($item,10,-1) ;
115 list($name,$body) = explode('(', $def, 2);
118 $ret[] = $in . "var $name = function (" . $body . '{';
122 if (substr($item,-3,2) == ':h') {
123 $ret[] = $in . "ret += ". substr($item,1,-3) . ';';
126 $ret[] = $in . "ret += Roo.util.Format.htmlEncode(". substr($item,1,-1).');';
133 $in = str_repeat(" ", $indent);
134 $ret[] = $in . "return ret.join('');\n}\n";
136 echo '<PRE>' . htmlspecialchars(implode("\n",$ret));