// get the modules.
header('Content-type: text/javascript');
- $ff = HTML_FlexyFramework::get()->HTML_Template_Flexy;
- print_R($ff);
+ $ff = HTML_FlexyFramework::get();
- $mods = $this->modulesList();
- foreach($mods as $mod) {
- $dir = $this->rootDir.'/Pman/'. $mod . '/jtemplates';
+ $pr = $ff->project;
+ $ar = explode(PATH_SEPARATOR, $ff->HTML_Template_Flexy['templateDir']);
+
+ $prefix = $pr == 'Pman' ? 'Pman.' : '';
+
+ foreach($ar as $mod) {
+ $dir = dirname($mod) . '/jtemplates';
if (!file_exists($dir)) {
echo '// missing directory '. htmlspecialchars($dir) ."\n";
+ continue;
}
// got a directory..
+ $mn = basename(dirname($mod));
+ $ar = glob("$dir/*.html") ;
+ if (empty($ar)) {
+ echo '// no template is directory '. htmlspecialchars($dir) ."\n";
+ continue;
+ }
+
+ echo "{$prefix}{$mn} = {$prefix}{$mn} || {};\n";
+ echo "{$prefix}{$mn}.template = {$prefix}{$mn}.template || {};\n\n";
+
foreach(glob("$dir/*.html") as $fn) {
- var_Dump($fn);
+ $name = "{$prefix}{$mn}.template." . preg_replace('/\.html$/i', '', basename($fn));
+ echo $this->compile($fn, $name) . "\n";
}
$contents = file_get_contents($fn);
- $ar = preg_split('/(\{[^\}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $ar = preg_split('/(\{[^\\n}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
+
+
+
+
//echo '<PRE>' . htmlspecialchars(print_r($ar,true));
- $ret = array();
+ $out= array();
- $ret[] = "var $name = function(t) {\n var ret=[];\n";
- $indent = 1;
+ $head = "$name = function(t)\n{\n var ret = [];\n\n";
+
+ $funcs = array();
+ // do not allow nested functions..?
+ $fstart = -1;
+ $indent = 2;
+ $inscript = false;
+ $ret = &$out;
foreach($ar as $item) {
$in = str_repeat(" ", $indent);
-
+ $indent = max($indent , 1);
//var_Dump(substr($item,-3,2));
switch(true) {
case (!strlen($item)):
continue;
+ case ($inscript && ($item != '{end:}')):
+ $ret[] = $item;
+ continue;
+
+ case ($inscript && ($item == '{end:}')):
+ $inscript = false;
+ continue;
+
+
case ($item[0] != '{'):
if (!strlen(trim($item))) {
continue;
}
- $ret[] = $in . "ret+= ". json_encode($item) . ";";
+ $ret[] = $in . "ret += ". json_encode($item) . ";";
+ continue;
+
+
+ case ($item == '{script:}'):
+ $inscript = true;
+ continue;
+
+ case ($item[1] == '!'):
+ $ret[] = $in . substr($item,2,-1) .';';
continue;
+
case (substr($item,1,3) == 'if('):
$ret[] = $in . substr($item,1,-1) . ' {';
$indent++;
$indent--;
$in = str_repeat(" ", $indent);
$ret[] = $in . "}";
+ if ($fstart == $indent) {
+ $fstart = -1;
+ $ret = &$out;
+ }
continue;
case (substr($item,1,7) == 'return:'):
continue;
case (substr($item,1,9) == 'function:'):
+ $fstart = $indent;
$indent++;
+ $ret = &$funcs;
$def = substr($item,10,-1) ;
list($name,$body) = explode('(', $def, 2);
$ret[] = $in . "ret += ". substr($item,1,-3) . ';';
continue;
}
+ if (substr($item,-3,2) == ':b') {
+ $ret[] = $in . "ret += Roo.util.Format.htmlEncode(". substr($item,1,-3).').split("\n").join("<br/>\n");';
+ continue;
+ }
$ret[] = $in . "ret += Roo.util.Format.htmlEncode(". substr($item,1,-1).');';
continue;
}
$in = str_repeat(" ", $indent);
$ret[] = $in . "return ret.join('');\n}\n";
-
- echo '<PRE>' . htmlspecialchars(implode("\n",$ret));
+ return $head . implode("\n",$funcs) . "\n\n" .implode("\n",$out) ;
+ //echo '<PRE>' . htmlspecialchars(implode("\n",$ret));