X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JsTemplate.php;h=f1387913c57aa7251c3a593c07d4f5afd314b684;hb=2667e5de2255d3c16b10f3d5a9d8af0718ab8e79;hp=14eb098313cc5858eeeac5f9e7ae8ee9edb6be9b;hpb=85cd9c9a886c5507b91d04a869fd642d23391803;p=Pman.Core diff --git a/JsTemplate.php b/JsTemplate.php index 14eb0983..f1387913 100644 --- a/JsTemplate.php +++ b/JsTemplate.php @@ -30,6 +30,9 @@ require_once 'Pman.php'; class Pman_Core_JsTemplate extends Pman { + + var $modDir = false; + function getAuth() { parent::getAuth(); @@ -37,20 +40,48 @@ class Pman_Core_JsTemplate extends Pman { } - function get() + function get($v, $opts=array()) { + + $this->sessionState(0); // get the modules. header('Content-type: text/javascript'); + $ff = HTML_FlexyFramework::get(); + + $pr = $ff->project; + $mods = $this->modulesList(); - foreach($mods as $mod) { - $dir = $this->rootDir.'/Pman/'. $mod . '/jtemplates'; + //print_r($mods); + + //$ar = explode(PATH_SEPARATOR, $ff->HTML_Template_Flexy['templateDir']); + array_push($mods, $pr); + + foreach($mods as $mod ) + { + $prefix = $mod == $pr ? "" : "{$pr}."; + //var_dump($prefix); + $pdir = $mod == $pr ? '' : ($pr .'/') ; + + $dir = $this->rootDir .'/'.$pdir . $mod . '/jtemplates'; if (!file_exists($dir)) { echo '// missing directory '. htmlspecialchars($dir) ."\n"; + continue; } // got a directory.. + + $ar = glob("$dir/*.html") ; + if (empty($ar)) { + echo '// no template is directory '. htmlspecialchars($dir) ."\n"; + continue; + } + + echo "{$prefix}{$mod} = {$prefix}{$mod} || {};\n"; + echo "{$prefix}{$mod}.template = {$prefix}{$mod}.template || {};\n\n"; + foreach(glob("$dir/*.html") as $fn) { - var_Dump($fn); + $name = "{$prefix}{$mod}.template." . preg_replace('/\.html$/i', '', basename($fn)); + echo $this->compile($fn, $name) . "\n"; } @@ -60,7 +91,7 @@ class Pman_Core_JsTemplate extends Pman { } - + exit; @@ -73,37 +104,78 @@ class Pman_Core_JsTemplate extends Pman { $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 '
' . 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[count($ret)-1] .= $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; + $ret[] = ''; + continue; + + case ($item[1] == '!'): + $ret[] = $in . substr($item,2,-1) .';'; + continue; + + case (substr($item,1,3) == 'if('): $ret[] = $in . substr($item,1,-1) . ' {'; $indent++; continue; + case (substr($item,1,5) == 'else:'): + $indent--; + $in = str_repeat(" ", $indent); + $ret[] = $in . "} else { "; + $indent++; + continue; + case (substr($item,1,4) == 'end:'): $indent--; $in = str_repeat(" ", $indent); $ret[] = $in . "}"; + if ($fstart == $indent) { + $fstart = -1; + $ret = &$out; + } continue; case (substr($item,1,7) == 'return:'): @@ -111,7 +183,9 @@ class Pman_Core_JsTemplate extends Pman { continue; case (substr($item,1,9) == 'function:'): + $fstart = $indent; $indent++; + $ret = &$funcs; $def = substr($item,10,-1) ; list($name,$body) = explode('(', $def, 2); @@ -124,6 +198,10 @@ class Pman_Core_JsTemplate extends Pman { $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("
\n");'; + continue; + } $ret[] = $in . "ret += Roo.util.Format.htmlEncode(". substr($item,1,-1).');'; continue; @@ -132,9 +210,9 @@ class Pman_Core_JsTemplate extends Pman { } $in = str_repeat(" ", $indent); - $ret[] = $in . "return ret.join('');\n}\n"; - - echo '' . htmlspecialchars(implode("\n",$ret)); + $ret[] = $in . "return ret;\n}\n"; + return $head . implode("\n",$funcs) . "\n\n" .implode("\n",$out) ; + //echo '' . htmlspecialchars(implode("\n",$ret));