JsTemplate.php
[Pman.Core] / JsTemplate.php
index 0e8d3bd..f05a44a 100644 (file)
@@ -43,17 +43,22 @@ class Pman_Core_JsTemplate extends Pman {
     function get()
     {
         // get the modules.
-        header('Content-type: text/javascript');
+        //header('Content-type: text/javascript');
         
         $ff = HTML_FlexyFramework::get();
         
         $pr = $ff->project;
-        $ar = explode(PATH_SEPARATOR, $ff->HTML_Template_Flexy['templateDir']);
         
-        $prefix = $pr == 'Pman' ? 'Pman.' : '';
+        $mods = $this->modulesList();
+        //print_r($mods);
         
-        foreach($ar as $mod) {
-            $dir =   dirname($mod) . '/jtemplates';
+        //$ar = explode(PATH_SEPARATOR, $ff->HTML_Template_Flexy['templateDir']);
+        
+        $prefix = empty($mods) ? '' : ($pr .'.') ;
+        $pdir = empty($mods) ? '' : ($pr .'/') ;
+
+        foreach(empty($mods) ? array($pr) : $mods as $mod ) {
+            $dir =  $this->rootDir .'/'.$pdir .  $mod . '/jtemplates';
             if (!file_exists($dir)) {
                 echo '// missing directory '. htmlspecialchars($dir) ."\n";
                 continue;
@@ -120,7 +125,7 @@ class Pman_Core_JsTemplate extends Pman {
                     continue;
                 
                 case ($inscript && ($item != '{end:}')):
-                    $ret[= $item;
+                    $ret[count($ret)-1] .= $item;
                     continue;
                 
                 case ($inscript && ($item == '{end:}')):
@@ -138,6 +143,7 @@ class Pman_Core_JsTemplate extends Pman {
                 
                 case ($item == '{script:}'): 
                     $inscript = true;
+                     $ret[] = '';
                     continue;
                 
                 case ($item[1] == '!'):
@@ -150,6 +156,13 @@ class Pman_Core_JsTemplate extends Pman {
                     $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);
@@ -181,7 +194,7 @@ class Pman_Core_JsTemplate extends Pman {
                         continue;
                     }
                     if (substr($item,-3,2) == ':b') {
-                        $ret[] = $in . "ret += Roo.util.Format.htmlEncode(".  substr($item,1,-1).').split("\n").join("<br/>\n");';
+                        $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).');';
@@ -192,7 +205,7 @@ class Pman_Core_JsTemplate extends Pman {
             
         }
         $in = str_repeat("    ", $indent);
-        $ret[] = $in .  "return ret.join('');\n}\n";
+        $ret[] = $in .  "return ret;\n}\n";
         return $head . implode("\n",$funcs) . "\n\n" .implode("\n",$out) ;
         //echo '<PRE>' . htmlspecialchars(implode("\n",$ret));