src/JsRender/NodeToJs.vala
[app.Builder.js] / src / JsRender / NodeToJs.vala
index 7a3ebd4..f3a0a0d 100644 (file)
@@ -4,6 +4,13 @@
  * 
  * usage : x = (new JsRender.NodeToJs(node)).munge();
  * 
+ *
+ *  We are changing this to output as we go.
+ *   However... since line-endings on properties have ',' (not ;) like vala.
+ *           we have to be a bit smarter about how to output.
+ *
+ *   
+ *
 */
 
 
@@ -19,7 +26,7 @@ public class JsRender.NodeToJs : Object {
        Node node;
        Gee.ArrayList<string>  doubleStringProps;  // need to think if this is a good idea like this
        string pad;
-       JsRender jsrender;
+       public JsRender renderer;
          
        Gee.HashMap<string,string> out_props;
        Gee.HashMap<string,string> out_listeners;       
@@ -44,18 +51,25 @@ public class JsRender.NodeToJs : Object {
                //this.ar_props = new Gee.HashMap<string,string>();
                
                
+               
+               // this is the bit that causes issues - we have to output as we go, otherwise we 
+               // can not work out which line is which...
+               
                this.out_props = new Gee.HashMap<string,string>();
                this.out_listeners = new Gee.HashMap<string,string>();  
+               
+               
                this.out_nodeprops = new Gee.HashMap<string,Node>() ;
                this.out_children = new Gee.ArrayList<Node> ();
-               this.out_props_array = new Gee.HashMap<string,Gee.ArrayList<Node>>() ;
+               
+               this.out_props_array = new Gee.HashMap<string,Gee.ArrayList<Node>>(); // filled in by 'checkChildren'
                this.out_props_array_plain = new Gee.HashMap<string,Gee.ArrayList<string>>() ;
        
                
                
                this.cur_line = parent == null ? 0 : parent.cur_line  ; //-1 as we usuall concat onto the existin gline?
                if (parent != null) {
-                       this.jsrender = parent.jsrender;
+                       this.renderer = parent.renderer;
                }
                this.ret = "";
                this.top = parent == null ? this : parent.top;
@@ -265,14 +279,28 @@ public class JsRender.NodeToJs : Object {
        
        }
        
-       
-       
+       /**
+       * Line endings
+       *     if we end with a ','
+       *
+       */
+
+       char last_line_end = 0; 
        
-       public void addLine(string str= "")
+       /**
+       * add a line - note we will end up with an extra line break 
+       *     at beginning of nodes doing this..
+       *
+       * @param str = text to add..
+       * @param line_end = 0  (just add a line break)
+       *        line_end = ','  and ","
+       *  
+       */
+       public void addLine(string str, char line_end)
        {
+               this.ret += (this.line_end == 0 ? "" : this.last_line_end) + "\n"; 
                this.cur_line ++;
-               this.ret += str+ "\n";
+               this.ret += str ;
                //this.ret +=  "/*%d(%d-%d)*/ ".printf(this.cur_line -1, this.node.line_start,this.node.line_end) + str + "\n";
                
                
@@ -294,7 +322,12 @@ public class JsRender.NodeToJs : Object {
                return x.ret;
        }
        
-
+       /**
+       * loop through items[] array see if any of the children have '* prop'
+       * -- which means they are a property of this node.
+       * -- ADD TO : this.opt_props_array  
+       *
+       */
        
        public void checkChildren () 
        {
@@ -320,7 +353,7 @@ public class JsRender.NodeToJs : Object {
                        //var prop = pl['*prop'] + '';
                        //delete pl['*prop'];
                        var prop = pl.get("* prop");
-                       print("got prop "+ prop + "\n");
+                       //print("got prop "+ prop + "\n");
                        
                        // name ends in [];
                        if (! Regex.match_simple("\\[\\]$", prop)) {
@@ -337,7 +370,7 @@ public class JsRender.NodeToJs : Object {
 
                        
                        var sprop  = prop.replace("[]", "");
-                       print("sprop is : " + sprop + "\n");
+                       //print("sprop is : " + sprop + "\n");
                        
                        // it's an array type..
                        //var old = "";
@@ -436,7 +469,7 @@ public class JsRender.NodeToJs : Object {
                
                for (var i = 0; i< keys.size; i++) {
                        var key = this.node.get_key(keys.get(i));
-                       print("ADD KEY %s\n", key);
+                       //("ADD KEY %s\n", key);
                        string k;
                        string ktype;
                        string kflag;
@@ -476,7 +509,7 @@ public class JsRender.NodeToJs : Object {
                                 
 
                                this.out_props.set("html", "Pman.Cms.content(" + 
-                                       this.node.quoteString(this.jsrender.name + "::" + this.node.get("cms-id")) +
+                                       this.node.quoteString(this.renderer.name + "::" + this.node.get("cms-id")) +
                                         ", " +
                                        this.node.quoteString(v) +
                                         ")");
@@ -584,7 +617,7 @@ public class JsRender.NodeToJs : Object {
                                //      "']"
                                //);
                                this.out_props.set(left, "_this._strings['" + 
-                                       GLib.Checksum.compute_for_string (ChecksumType.MD5, v) +
+                                       GLib.Checksum.compute_for_string (ChecksumType.MD5, v.strip()) +
                                        "']" + com);
                                continue;
                        }