JsTemplate.php
[Pman.Core] / JsTemplate.php
index 7651df3..a4f7003 100644 (file)
@@ -94,7 +94,7 @@ 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);
         
         
         
@@ -103,7 +103,7 @@ class Pman_Core_JsTemplate extends Pman {
         
         $out= array();
         
-        $head = "$name = function(t) {\n    var ret=[];\n";
+        $head = "$name = function(t)\n{\n    var ret = [];\n\n";
         
         $funcs = array();
         // do not allow nested functions..?
@@ -126,7 +126,8 @@ class Pman_Core_JsTemplate extends Pman {
                 case ($inscript && ($item == '{end:}')):
                     $inscript = false;
                     continue;
-                
+                 
+             
                 case ($item[0] != '{'):
                     if (!strlen(trim($item))) {
                         continue;
@@ -135,10 +136,13 @@ class Pman_Core_JsTemplate extends Pman {
                     continue;
                 
                 
-                case (substr($item,1,6) == 'script:'): 
+                case ($item == '{script:}'): 
                     $inscript = true;
                     continue;
                 
+                case ($item[1] == '!'):
+                    $ret[] = $in . substr($item,2,-1) .';';
+                    continue;
                 
                 
                 case (substr($item,1,3) == 'if('):
@@ -185,7 +189,7 @@ class Pman_Core_JsTemplate extends Pman {
         }
         $in = str_repeat("    ", $indent);
         $ret[] = $in .  "return ret.join('');\n}\n";
-        return $head . implode("\n",$funcs) . "\n" .implode("\n",$out) ;
+        return $head . implode("\n",$funcs) . "\n\n" .implode("\n",$out) ;
         //echo '<PRE>' . htmlspecialchars(implode("\n",$ret));