resources/RooUsage.txt
[app.Builder.js] / src / JsRender / Roo.vala
index 37d40ba..25f003c 100644 (file)
@@ -70,42 +70,28 @@ namespace JsRender {
             
         }
     
-    /*    
-        setNSID : function(id)
-        {
-            
-            this.items[0]['|module'] = id;
-       
-            
-        },
-        
-        
-        getType: function() {
-            return 'Roo';
-        },
-
-    */
                
-       public   override void   removeFiles() {
-               var html = GLib.Path.get_dirname(this.path) +"/templates/" + name + ".html";
-               if (FileUtils.test(html, FileTest.EXISTS)) {
-                       GLib.FileUtils.remove(html);
-               }
-               var js = GLib.Path.get_dirname(this.path) +"/" + name + ".html";
-               if (FileUtils.test(js, FileTest.EXISTS)) {
-                       GLib.FileUtils.remove(js);
+               public   override void   removeFiles() {
+                       var html = GLib.Path.get_dirname(this.path) +"/templates/" + name + ".html";
+                       if (FileUtils.test(html, FileTest.EXISTS)) {
+                               GLib.FileUtils.remove(html);
+                       }
+                       var js = GLib.Path.get_dirname(this.path) +"/" + name + ".html";
+                       if (FileUtils.test(js, FileTest.EXISTS)) {
+                               GLib.FileUtils.remove(js);
+                       }
                }
-       }
                
         public  override void  loadItems() throws GLib.Error // : function(cb, sync) == original was async.
         {
             
                                 
-                       print("load Items!");
+                       GLib.debug("load Items!");
                        if (this.tree != null) {
                                return;
                        }
-                       print("load " + this.path);
+                       GLib.debug("load " + this.path);
 
                        var pa = new Json.Parser();
                        pa.load_from_file(this.path);
@@ -141,86 +127,17 @@ namespace JsRender {
                                this.tree.loadFromJson(tree_base, int.parse(bjs_version_str));
                        }
                        this.loaded = true;
-
+                       this.toSource(); // force it to number the lines...
 
             
         }
-        /**
-         * old code had broken xtypes and used arrays differently,
-         * this code should try and clean it up..
-         * 
-         * 
-         * /
-        fixItems : function(node, fixthis)
-        {
-            if (fixthis) {
-                // fix xtype.
-                var fn = this.guessName(node);
-                //print("guessname got " + fn);
-                if (fn) {
-                    var bits = fn.split('.');
-                    node.xtype = bits.pop();
-                    node['|xns'] = bits.join('.');
-                    
-                }
-                // fix array???
-                 
-                
-            }
-            if (!node.items || !node.items.length) {
-                return;
-            }
-            var _this = this;
-            var aitems = [];
-            var nitems = [];
-            node.items.forEach(function(i) {
-                
-                
-                
-                _this.fixItems(i, true);
-                if (i.xtype == 'Array') {
-                    aitems.push(i);
-                    return;
-                }    
-                nitems.push(i);
-            });
-            node.items = nitems; 
-            
-            if (!aitems.length) {
-                return;
-            }
-            
-            aitems.forEach(function(i) {
-                
-                if (!i.items || !i.items.length) {
-                    return;
-                }
-                var prop = i['*prop'] + '[]';
-                // colModel to cm?
-                i.items.forEach(function(c) {
-                    c['*prop']  = prop;
-                    node.items.push(c);
-                    
-                });
-                
-                
-            });
-            
-            
-            // array handling.. 
-            
-            
-            
-            
-            
-        },
-    */
+        
         
        public  override  void save()
-        {
+       {
             
-               print("--- JsRender.Roo.save");
-               print("save() - reset transStrings\n");
+               GLib.debug("--- JsRender.Roo.save");
+               GLib.debug("save() - reset transStrings\n");
                this.transStrings = new Gee.HashMap<string,string>();
                this.findTransStrings(this.tree);
                
@@ -259,7 +176,7 @@ namespace JsRender {
             
             
             
-        }
+       }
 
         
 
@@ -268,12 +185,12 @@ namespace JsRender {
        {
                 
                var top = this.tree.fqn();
-               print ("TOP = " + top + "\n" );
-               if (top.index_of("Roo.bootstrap.") < 0 &&
-                   top.index_of("Roo.mailer.") < 0
-                       ) {
-                       return;
-               }
+               GLib.debug ("TOP = " + top + "\n" );
+               if (top.index_of("Roo.bootstrap.") < 0 &&
+           top.index_of("Roo.mailer.") < 0
+               ) {
+               return;
+               }
                
                
                //now write the js file..
@@ -298,7 +215,7 @@ namespace JsRender {
                        print("Skip save - templates folder does not exist : %s\n", targetdir);
                        return;
                }
-               print("SAVE HTML -- %s\n%s\n",targetdir + "/" +  bn, html);
+               //print("SAVE HTML -- %s\n%s\n",targetdir + "/" +  bn, html);
                try {
                        this.writeFile(targetdir + "/" +  bn , html);            
                } catch (FileError e ) {
@@ -352,19 +269,24 @@ namespace JsRender {
                                if (kflag == "$") {
                                        continue;
                                }
+                               // skip cms-id nodes...
+                               if (kname == "html" && node.has("cms-id")) { 
+                                       continue;
+                               }
+                               
                                var str = iter.get_value();
                                if (this.doubleStringProps.index_of(kname) > -1) {
-                                       print("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
+                                       GLib.debug("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
                                        this.transStrings.set(str,  
-                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str)
+                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip())
                                        );
                                        continue;
                                }
                                
                                if (ktype.down() == "string" && kname[0] == '_') {
-                                       print("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
+                                       GLib.debug("flag=%s type=%s name=%s : %s\n", kflag,ktype,kname,str);
                                        this.transStrings.set(str,  
-                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str)
+                                               GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip())
                                        );
                                        continue;
                                }
@@ -384,9 +306,9 @@ namespace JsRender {
                public string  transStringsToJs()
                {
                        
-                       print("Roo.transStringsToJs()\n");
+                       GLib.debug("Roo.transStringsToJs()\n");
                        if (this.transStrings.size < 1) {
-                               print("Roo.transStringsToJs() size < 1?\n");
+                               GLib.debug("Roo.transStringsToJs() size < 1?\n");
                                return "";
                        }
                         
@@ -479,6 +401,13 @@ namespace JsRender {
          * 
          * 
          */
+        public override string toSourceCode() 
+        {
+                       this.transStrings = new Gee.HashMap<string,string>();
+                       this.findTransStrings(this.tree);
+                       return this.toSource();
+               }
+         
         public override string toSource()
         {
             // dump the file tree back out to a string.
@@ -494,10 +423,14 @@ namespace JsRender {
             if (top == null) {
                 return "";
             }
-            // get the translatable strings..
             
             
             
+            // get the translatable strings.. = we reload them again so calling methods get the right data...
+            this.transStrings = new Gee.HashMap<string,string>();
+                       this.findTransStrings(this.tree);
+            
+            
             if (top.contains("Dialog")) {
                 return this.toSourceDialog(false);
             }
@@ -536,6 +469,7 @@ namespace JsRender {
                                return "";
                        }
                        var x = new NodeToJs(this.tree, this.doubleStringProps, pad, null);
+                       x.renderer = this;
                        x.cur_line = prefix.split("\n").length;
                        
                        var ret = x.munge();
@@ -619,13 +553,11 @@ namespace JsRender {
                 "};",
                 ""
             };
-            
-             var o = this.mungeToString("    ");   
-
+             
             return this.mungeToStringWrap("    ",   
-                       this.outputHeader() + "\n" + .name + string.joinv("\n", adda), //header
+                       this.outputHeader() + "\n" + this.name + string.joinv("\n", adda), //header
                        string.joinv("\n", addb) // footer
-               )
+               );
              
              
              
@@ -642,7 +574,7 @@ namespace JsRender {
             
             
             //var items = JSON.parse(JSON.stringify(this.items[0]));
-            var o = this.mungeToString("    ");   
+             
             
             string[] adda = { " = {",
                 "",
@@ -682,7 +614,7 @@ namespace JsRender {
                        return this.mungeToStringWrap("    ",   
                        this.outputHeader() + "\n" +  this.name + string.joinv("\n", adda), // header
                        string.joinv("\n", addb) // footer
-               )
+               );
              
              
              
@@ -724,11 +656,14 @@ namespace JsRender {
                        //    topItem.background = false;
                }
             
-               var o = this.mungeToString("   ");   
-               var reg = new Regex("[^A-Za-z.]+");
-            
-               string modkey = this.modOrder + "-" + reg.replace(this.name, this.name.length, 0 , "-");
+               var  modkey = this.modOrder + "-" +   this.name;
+               try {
+                       var reg = new Regex("[^A-Za-z.]+");
             
+                        modkey = this.modOrder + "-" + reg.replace(this.name, this.name.length, 0 , "-");
+            } catch (RegexError e) {
+                       //noop..
+            }
                string  parent =   (this.parent.length > 0 ?  "'" + this.parent + "'" :  "false");
 
                
@@ -746,9 +681,9 @@ namespace JsRender {
                          
                }
             
-          
-               return 
-                       this.outputHeader() + "\n" +
+            
+            
+            var pref = this.outputHeader() + "\n" +
                        
                        this.name  +  " = new Roo.XComponent({\n" +
                        "\n" + 
@@ -768,10 +703,13 @@ namespace JsRender {
                        "  {\n" +
                        "   var _this = this;\n" + // bc
                        "   var MODULE = this;\n" + /// this looks like a better name.
-                       "   return " + o + ";" +
+                       "   return ";
+                       
+                   return this.mungeToStringWrap("   ", pref,  ";" +
                        "  }\n" +
-                       "});\n";
-                        
+                       "});\n"
+               );
+                     
               
         }