sync
[app.Builder.js] / JsRender / NodeToJs.vala
index 6941fed..9826e3e 100644 (file)
 
 public class JsRender.NodeToJs : Object {
 
-       JsRender.Node node;
+        Node node;
        Gee.ArrayList<string>  doubleStringProps;
        string pad;
        Gee.ArrayList<string> els;
-        Gee.ArrayList<string> skip;
+        //Gee.ArrayList<string> skip;
        Gee.HashMap<string,string> ar_props;
 
 
        
-       public NodeToJs(JsRender.Node node, Gee.ArrayList<string> doubleStringProps, pad) 
+       public NodeToJs( Node node, Gee.ArrayList<string> doubleStringProps, string pad) 
        {
                this.node = node;
                this.doubleStringProps = doubleStringProps;
                this.pad = pad;
                this.els = new Gee.ArrayList<string>(); 
-               this.skip = new Gee.ArrayList<string>();
+               //this.skip = new Gee.ArrayList<string>();
                this.ar_props = new Gee.HashMap<string,string>();
 
        }
@@ -34,9 +34,55 @@ public class JsRender.NodeToJs : Object {
        public string munge ( )
        {
                //return this.mungeToString(this.node);
-       }
 
-       public string mungeChild(pad ,cnode)
+       
+               
+               this.checkChildren();
+               this.readProps();
+               this.readArrayProps();
+               this.readListeners();
+
+               if (!this.node.props.has_key("* xinclude")) {
+                       this.iterChildren();
+               }
+               
+               
+               
+               
+               if (this.els.size < 1) {
+                       return "";
+               }
+               // oprops...    
+                       
+               var spad = pad.substring(0, this.pad.length-4);
+               var str_props = gLibStringListJoin(",\n" + this.pad , this.els) ;
+               //print ("STR PROPS: " + str_props);
+               if (!this.node.props.has_key("* xinclude")) {
+                       return   "{\n" +
+                               this.pad  + str_props + 
+                               "\n" + spad +  "}";
+               }
+               // xinclude...
+
+
+               return "Roo.apply(" + this.node.props.get("* xinclude") + "._tree(), "+
+                        "{\n" +
+                               this.pad  + str_props + 
+                               "\n" + spad +  "})";
+                    
+       } 
+
+       string gLibStringListJoin( string sep, Gee.ArrayList<string> ar) 
+       {
+               var ret = "";
+               for (var i = 0; i < ar.size; i++) {
+                       ret += i>0 ? sep : "";
+                       ret += ar.get(i);
+               }
+               return ret;
+
+       }
+       public string mungeChild(string pad ,  Node cnode)
        {
                var x = new  NodeToJs(cnode, this.doubleStringProps, pad);
                return x.munge();
@@ -45,7 +91,7 @@ public class JsRender.NodeToJs : Object {
        
 
        
-       public string checkChildren () 
+       public void checkChildren () 
        {
                
                 
@@ -76,7 +122,7 @@ public class JsRender.NodeToJs : Object {
                                // it's a standard prop..
                                
                                // munge property..??
-                               this.els.add( prop  + " : " + this.mungeChild (  pad + "        ",  pl));
+                               this.els.add( prop  + " : " + this.mungeChild (  this.pad + "    ",  pl));
                                
                                
                                //keys.push(prop);
@@ -99,7 +145,7 @@ public class JsRender.NodeToJs : Object {
                                old = this.ar_props.get(sprop);
                        }
                        var nstr  = old += old.length > 0 ? ",\n" : "";
-                       nstr += this.mungeChild( pad + "                ",   pl.mungeToString ( ));
+                       nstr += this.mungeChild( this.pad + "           ",   pl);
                        
                        this.ar_props.set(sprop, nstr);
                         
@@ -112,12 +158,15 @@ public class JsRender.NodeToJs : Object {
  * 
  * standard properties (use to set)
  *          If they are long values show the dialog..
- * 
+ *
+ * someprop : ....
  * bool is_xxx  :: can show a pulldown.. (true/false)
  * string html  
  * $ string html  = string with value interpolated eg. baseURL + ".." 
  *  Clutter.ActorAlign x_align  (typed)  -- shows pulldowns if type is ENUM? 
- * $ untypedvalue = javascript untyped value... 
+ * $ untypedvalue = javascript untyped value...  
+ * _ string html ... = translatable..
+
  * 
  * object properties (not part of the GOjbect being wrapped?
  * # Gee.ArrayList<Xcls_fileitem> fileitems
@@ -149,32 +198,42 @@ public class JsRender.NodeToJs : Object {
        {
                string left;
                Regex func_regex ;
+
+               if (this.node.props.has_key("$ xns")) {
+        
+                       this.els.add("'|xns' : '" + this.node.props.get("$ xns") + "'");
+
+               }
+
+               
                try {
                        func_regex = new Regex("^\\s+|\\s+$");
                } catch (Error e) {
                        print("failed to build regex");
-                       return "";
+                       return;
                }
                var piter = this.node.props.map_iterator();
                while (piter.next() ) {
-                       var k = piter.get_key();
+                       var kk = piter.get_key().split(" ");
                        var v = piter.get_value();
+                       var k = kk[kk.length-1];
+
                        
-                       if (this.skip.contains(k) ) {
-                               continue;
-                       }
+                       //if (this.skip.contains(k) ) {
+                       //      continue;
+                       //}
                        if (  Regex.match_simple("\\[\\]$", k)) {
                                
                                
 
                        }
                        
-                       string leftv = k[0] == '$' ? k.substring(2) : k;
+                       string leftv = k;
                        // skip builder stuff. prefixed with  '.' .. just like unix fs..
-                       if (leftv[0] == '.') { // |. or . -- do not output..
+                       if (kk[0][0] == '.') { // |. or . -- do not output..
                                continue;
                        }
-                        if (k[0] == '*') {
+                        if (kk[0][0] == '*') {
                                // ignore '*prop';
                                continue;
                         }
@@ -193,8 +252,16 @@ public class JsRender.NodeToJs : Object {
                        
                        
                         
-                       // next.. is it a function..
-                       if (k[0] == '|') {
+                       // next.. is it a function.. or a raw string..
+                       if (
+                               kk[0][0] == '|' 
+                               || 
+                               kk[0][0] == '$' 
+                               || 
+                               kk[0] == "function"
+                              
+                               // ??? any others that are raw output..
+                               ) {
                                // does not hapepnd with arrays.. 
                                if (v.length < 1) {  //if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
                                        continue;
@@ -214,7 +281,7 @@ public class JsRender.NodeToJs : Object {
                                var lines = str.split("\n");
                                var nstr = "" + str;
                                if (lines.length > 0) {
-                                       nstr =  string.joinv("\n" + pad, lines);
+                                       nstr =  string.joinv("\n" + this.pad, lines);
                                }
                                //print("==> " +  str + "\n");
                                this.els.add(left + nstr);
@@ -223,7 +290,19 @@ public class JsRender.NodeToJs : Object {
                        // standard..
                        
                        
-                       if (Lang.isNumber(v) || Lang.isBoolean(v)) { // boolean or number...?
+                       if (
+                               Lang.isNumber(v) 
+                               || 
+                               Lang.isBoolean(v)
+                               ||
+                               kk[0].down() == "boolean"
+                               || 
+                               kk[0].down() == "bool"
+                               || 
+                               kk[0].down() == "number"
+                               || 
+                               kk[0].down() == "int"
+                           ) { // boolean or number...?
                                this.els.add(left + v.down() );
                                continue;
                        }
@@ -253,6 +332,7 @@ public class JsRender.NodeToJs : Object {
        
                // handle the childitems  that are arrays.. eg. button[] = {  }...
                
+               string left;
                
                var iter = this.ar_props.map_iterator();
                while (iter.next()) {
@@ -275,7 +355,7 @@ public class JsRender.NodeToJs : Object {
                        
                        
                        if (right.length > 0){
-                               this.els.add(left + "[\n" +  pad + "     " +  right + "\n" + pad + "]");
+                               this.els.add(left + "[\n" +  this.pad + "        " +  right + "\n" + this.pad + "]");
                        }
                
                        
@@ -302,18 +382,18 @@ public class JsRender.NodeToJs : Object {
                        var str = liter.get_value().strip();
                        var lines = str.split("\n");
                        if (lines.length > 0) {
-                               str = string.joinv("\n" + pad + "          ", lines);
+                               str = string.joinv("\n" + this.pad + "     ", lines);
                        }
                        
 
                        
-                       itms +=  pad + "        "  + liter.get_key().replace("|", "")  + " : " + str;
+                       itms +=  this.pad + "   "  + liter.get_key().replace("|", "")  + " : " + str;
 
                        i++;
                
                        
                }
-               itms += "\n" + pad + "}";
+               itms += "\n" + this.pad + "}";
                //print ( "ADD " + itms); 
                this.els.add(itms);
 
@@ -324,13 +404,13 @@ public class JsRender.NodeToJs : Object {
                
                
                // finally munge the children...
-               if (this.node.items.size < 0) {
+               if (this.node.items.size < 1) {
                        return;
                }
                var itms = "items : [\n";
                var n = 0;
-               for(var i = 0; i < this.items.size;i++) {
-                       var ele = this.items.get(i);
+               for(var i = 0; i < this.node.items.size;i++) {
+                       var ele = this.node.items.get(i);
                        if (ele.props.has_key("* prop")) {
                                continue;
                        }
@@ -338,42 +418,24 @@ public class JsRender.NodeToJs : Object {
                                 itms += ",\n";
                        }
                        n++;
-                       itms += pad + " "  +
-                               this.mungeChild( pad + "                ",  ele);
+                       itms += this.pad + "    "  +
+                               this.mungeChild( this.pad + "        ",  ele);
                        
                        
                }
-               itms +=  "\n"+  pad + "]"  + "\n";
+               itms +=  "\n"+  this.pad + "]"  + "\n";
                this.els.add(itms);
        }
 
                // finally output listeners...
                
-
+       public void xIncludeToString()
+       {
                
 
+       }
 
-
-                       
-               if (els.size < 1) {
-                       return "";
-               }
-               // oprops...    
-                       
-               var spad = pad.substring(0, pad.length-4);
-               var str_props = gLibStringListJoin(",\n" + pad , els) ;
-               //print ("STR PROPS: " + str_props);
-               
-               return   "{\n" +
-                       pad  + str_props + 
-                       "\n" + spad +  "}";
-                  
-                  
-                          
-               
-               
-       } 
-
+}