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
29 require_once 'Pman.php';
31 class Pman_Core_JsTemplate extends Pman {
43 header('Content-type: text/javascript');
45 $mods = $this->modulesList();
46 foreach($mods as $mod) {
47 $dir = $this->rootDir.'/Pman/'. $mod . '/jtemplates';
48 if (!file_exists($dir)) {
49 echo '// missing directory '. htmlspecialchars($dir) ."\n";
52 foreach(glob("$dir/*.html") as $fn) {
58 //new HTML_FlexyFramework_JsTemplate('/home/alan/gitlive/web.mtrack/MTrackWeb/jtemplates/TimelineTicket.html', 'Pman.template.TimelineTicket');
70 function compile($fn, $name)
72 // cached? - check file see if we have cached contents.
75 $contents = file_get_contents($fn);
76 $ar = preg_split('/(\{[^\}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
77 //echo '<PRE>' . htmlspecialchars(print_r($ar,true));
81 $ret[] = "var $name = function(t) {\n var ret=[];\n";
83 foreach($ar as $item) {
84 $in = str_repeat(" ", $indent);
86 //var_Dump(substr($item,-3,2));
88 case (!strlen($item)):
91 case ($item[0] != '{'):
92 if (!strlen(trim($item))) {
95 $ret[] = $in . "ret+= ". json_encode($item) . ";";
98 case (substr($item,1,3) == 'if('):
99 $ret[] = $in . substr($item,1,-1) . ' {';
103 case (substr($item,1,4) == 'end:'):
105 $in = str_repeat(" ", $indent);
109 case (substr($item,1,7) == 'return:'):
110 $ret[] = $in . "return;";
113 case (substr($item,1,9) == 'function:'):
115 $def = substr($item,10,-1) ;
116 list($name,$body) = explode('(', $def, 2);
119 $ret[] = $in . "var $name = function (" . $body . '{';
123 if (substr($item,-3,2) == ':h') {
124 $ret[] = $in . "ret += ". substr($item,1,-3) . ';';
127 $ret[] = $in . "ret += Roo.util.Format.htmlEncode(". substr($item,1,-1).');';
134 $in = str_repeat(" ", $indent);
135 $ret[] = $in . "return ret.join('');\n}\n";
137 echo '<PRE>' . htmlspecialchars(implode("\n",$ret));