$contents = file_get_contents($fn);
- $ar = preg_split('/(\{[^\}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $ar = preg_split('/(\{[^\\n}]+})/', $contents, -1, PREG_SPLIT_DELIM_CAPTURE);
$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..?
$fstart = -1;
- $indent = 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;
- if ($inscript && ($item != '{end:}') {
+ case ($inscript && ($item != '{end:}')):
$ret[] = $item;
- }
+ continue;
+ case ($inscript && ($item == '{end:}')):
+ $inscript = false;
+ continue;
+
+
case ($item[0] != '{'):
if (!strlen(trim($item))) {
continue;
continue;
- case (substr($item,1,6) == 'script:'):
+ case ($item == '{script:}'):
$inscript = true;
+ $ret[] = '';
continue;
+ case ($item[1] == '!'):
+ $ret[] = $in . substr($item,2,-1) .';';
+ continue;
case (substr($item,1,3) == 'if('):
$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 . "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";
- return $head . implode("\n",$funcs) . "\n" .implode("\n",$out) ;
+ $ret[] = $in . "return ret;\n}\n";
+ return $head . implode("\n",$funcs) . "\n\n" .implode("\n",$out) ;
//echo '<PRE>' . htmlspecialchars(implode("\n",$ret));