Merge branch 'master' of http://git.roojs.com:8081/app.Builder.js
authorAlan Knowles <alan@akbkhome.com>
Sat, 31 May 2014 07:18:49 +0000 (15:18 +0800)
committerAlan Knowles <alan@akbkhome.com>
Sat, 31 May 2014 07:18:49 +0000 (15:18 +0800)
JsRender/JsRender.vala [new file with mode: 0644]
JsRender/Lang.vala [new file with mode: 0644]
JsRender/Node.vala [new file with mode: 0644]
JsRender/Roo.js
JsRender/Roo.vala [new file with mode: 0644]
Palete/RooUsage.txt
Project/Base.vala

diff --git a/JsRender/JsRender.vala b/JsRender/JsRender.vala
new file mode 100644 (file)
index 0000000..a8539a0
--- /dev/null
@@ -0,0 +1,222 @@
+//<Script type="text/javascript">
+
+
+class JsRender.JsRender  : Object {
+    /**
+     * @cfg {Array} doubleStringProps list of properties that can be double quoted.
+     */
+    Array<string> doubleStringProps;
+    
+    string id;
+    string name;   // is the JS name of the file.
+    string path;  // is the full path to the file.
+    string parent;  // JS parent.
+    
+    string title;  // a title.. ?? nickname.. ??? - 
+    Project.Project project;
+    //Project : false, // link to container project!
+    
+    JsRender.Node tree; // the tree of nodes.
+    
+    Array<JsRender.Base>() cn; // child files.. (used by project ... should move code here..)
+    
+    
+    void JsRender(Project.Project project, string path) {
+        
+        this.cn = new Array<JsRender.Base>();
+        this.path = path;
+        this.project = project;
+        
+        
+    }
+    JsRender.JsRender? factory(string xt, Project.Project project, string path)
+    {
+        JsRender.JsRender ret;
+        switch (xt) {
+            case "Gtk":
+                return new JsRender.Gtk(project, path)
+            case "Roo":
+                return new JsRender.Roo(project, path)
+        }
+        return null;    
+    }
+    
+    void save ()
+    {
+            
+        var write = this.toJsonArray();
+        var generator = new Json.Generator ();
+        generator.indent = 4;
+        generator.pretty = true;
+        var node = new Json.Node();
+        node.init_object(this.toJsonArray())
+        generator.set_root(node);
+        
+        print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
+        generator.to_file(this.path);
+    }
+        
+    void   saveHTML ()
+    {
+        // NOOP
+    },
+    
+    /**
+     *
+     * load from a javascript file.. rather than bjs..
+     * 
+     *
+     */
+     /*
+    _loadItems : function(cb)
+    {
+        // already loaded..
+        if (this.items !== false) {
+            return false;
+        }
+          
+        
+        
+        var tr = new  TokenReader(  { 
+            keepDocs :true, 
+            keepWhite : true,  
+            keepComments : true, 
+            sepIdents : false,
+            collapseWhite : false,
+            filename : args[0],
+            ignoreBadGrammer: true
+        });
+        
+        var str = File.read(this.path);
+        var toks = tr.tokenize(new TextStream(str));  
+        var rf = new JsParser(toks);
+        rf.parse();
+        var cfg = rf.cfg;
+        
+        this.modOrder = cfg.modOrder || '001';
+        this.name = cfg.name.replace(/\.bjs/, ''); // BC!
+        this.parent =  cfg.parent;
+        this.permname =  cfg.permname || '';
+        this.title =  cfg.title || cfg.name;;
+        this.items = cfg.items || []; 
+        //???
+        //this.fixItems(_this, false);
+        cb();
+        return true;    
+            
+    },
+    */
+        /**
+         * accepts:
+         * { success : , failure : , scope : }
+         * 
+         * 
+         * 
+         */
+         
+    getTree ( o ) {
+        print("File.getTree tree called on base object?!?!");
+    }
+    Json.Object toJsonArray ()
+    {
+        
+        
+        var ret = new Json.Object();
+        ret.set_string_member("id", this.id);
+        ret.set_string_member("name", this.name);
+        ret.set_string_member("parent", this.parent);
+        ret.set_string_member("title", this.title);
+        ret.set_string_member("path", this.path);
+        //ret.set_string_member("items", this.items);
+        ret.set_string_member("permname", this.permname);
+        ret.set_string_member("modOrder", this.modOrder);
+        
+        return ret;
+    }
+    
+    
+
+    string getTitle ()
+    {
+        if (this.title.length > 0) {
+            return this.title;
+        }
+        var a = this.path.split('/');
+        return a[a.length-1];
+    }
+    string getTitleTip()
+    {
+        if (this.title.length > 0) {
+            return '<b>' + this.title + '</b> ' + this.path;
+        }
+        return this.path;
+    }
+    /*
+        sortCn: function()
+        {
+            this.cn.sort(function(a,b) {
+                return a.path > b.path;// ? 1 : -1;
+            });
+        },
+    */
+        // should be in palete provider really..
+        
+    string guessName function(JsRender.Node ar) // turns the object into full name.
+    {
+         // eg. xns: Roo, xtype: XXX -> Roo.xxx
+        if (!ar.hasXnsType()) {
+           return '';
+        }
+        
+        return ar.get("|xns") +'.' + ar.get("|xtype");
+                          
+                            
+    }
+         
+        
+    /*
+    copyTo: function(path, cb)
+    {
+        var _this = this;
+        this.loadItems(function() {
+            
+            _this.path = path;
+            cb();
+        });
+        
+    },
+    */
+    
+    /**
+     * 
+     * munge JSON tree into Javascript code.
+     *
+     * NOTE - needs a deep copy of original tree, before starting..
+     *     - so that it does not modify current..
+     * 
+     * FIXME: + or / prefixes to properties hide it from renderer.
+     * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
+     * FIXME: needs to understand what properties might be translatable (eg. double quotes)
+     * 
+     * @arg {object} obj the object or array to munge..
+     * @arg {boolean} isListener - is the array being sent a listener..
+     * @arg {string} pad - the padding to indent with. 
+     */
+    
+    function mungeToString(string pad)
+    {
+        return this.tree.mungeToString(false, pad);
+        
+    }
+    
+      
+}
+    
+     
+
+
+
+
+
+
diff --git a/JsRender/Lang.vala b/JsRender/Lang.vala
new file mode 100644 (file)
index 0000000..dd47b40
--- /dev/null
@@ -0,0 +1,228 @@
+//<script type="text/javscript">
+
+/**
+       @namespace
+*/
+// test
+// valac gitlive/app.Builder.js/JsRender/Lang.vala --pkg gee-1.0 -o /tmp/Lang ;/tmp/Lang
+
+
+void main () {
+     new JsRender.Lang_Class();
+    print(JsRender.Lang.keyword("delete") + "\n");
+}
+namespace JsRender { 
+    public Lang_Class Lang = null;
+    
+    public class Lang_Class : Object {
+        
+        GLib.List<string> coreObjects;
+        Gee.HashMap<string,string> whitespaceNames;
+        Gee.HashMap<string,string> newlineNames;
+        Gee.HashMap<string,string> keywordNames;
+        Gee.HashMap<string,string> puncNames;
+        Gee.HashMap<string,string> matchingNames;
+        public Lang_Class ()
+        {
+            if (Lang != null) {
+                print("lang not null\n");
+                return;
+            }
+            print("init\n");
+            this.init();
+            print("init Lang");
+            Lang = this;
+            
+        }
+        
+        
+        public bool isBuiltin(string  name) {
+            return (this.coreObjects.index(name) > -1);
+        }
+        
+        public string whitespace (string ch) {
+            return this.whitespaceNames.get(ch);
+        }
+        public string  newline (string ch) {
+            return this.newlineNames.get(ch);
+        }
+        public string keyword(string word) {
+            return this.keywordNames.get("="+word);
+        }
+        
+        public string matching(string name) {
+            return this.matchingNames.get(name);
+        }
+        
+        public bool isKeyword(string word) {
+            return this.keywordNames.get("=" + word) != null;
+            
+        }
+        public string punc (string ch) {
+            return this.puncNames[ch];
+        }
+        
+        public bool isNumber (string str) {
+            return Regex.match_simple("^(.[0-9]|[0-9]+.|[0-9])[0-9]*([eE][+-][0-9]+)?$",str);
+        }
+    
+        public bool  isHexDec (string str) {
+            return Regex.match_simple("^0x[0-9A-F]+$",str);
+        }
+    
+        public bool isWordChar (string str) {
+            return Regex.match_simple("^[a-zA-Z0-9$_.]+$", str);
+        }
+    
+        public bool isSpace (string str) {
+            return this.whitespaceNames.get(str) != null;
+        }
+    
+        public bool isNewline (string str) {
+            return this.newlineNames.get(str) != null;
+        }
+         public bool isBoolean (string str) {
+            return str == "false" || str == "true";
+        }
+        
+        
+        void init() {
+            
+            this.coreObjects = new GLib.List<string>();
+            
+            this.whitespaceNames = new Gee.HashMap<string,string>();
+            this.newlineNames = new Gee.HashMap<string,string>();
+            this.keywordNames = new Gee.HashMap<string,string>();
+            this.puncNames = new Gee.HashMap<string,string>();
+            this.matchingNames = new Gee.HashMap<string,string>();
+            
+            
+            
+            string[] co = { "_global_", "Array", "Boolean", "Date", "Error", 
+                "Function", "Math", "Number", "Object", "RegExp", "String" };
+            for(var i =0; i< co.length;i++ ) {
+                this.coreObjects.append(co[i]);
+            }
+            string[] ws =  {
+                " :SPACE",
+                "\f:FORMFEED",
+                "\t:TAB" //,
+              //  "\u0009:UNICODE_TAB",
+              //  "\u000A:UNICODE_NBR",
+              //  "\u0008:VERTICAL_TAB"
+            };
+            for(var i =0; i< ws.length;i++ ) {
+                var x = ws[i].split(":");
+                this.whitespaceNames.set(x[0],x[1]);
+            }
+            
+            ws = {
+                "\n:NEWLINE",
+                "\r:RETURN" //,
+    //            "\u000A:UNICODE_LF",
+      //          "\u000D:UNICODE_CR",
+        //        "\u2029:UNICODE_PS",
+          //      "\u2028:UNICODE_LS"
+            };
+            for(var i =0; i< ws.length;i++ ) {
+                var x = ws[i].split(":");
+                this.newlineNames.set(x[0],x[1]);
+            }
+            ws = {
+                "=break:BREAK",
+                "=case:CASE",
+                "=catch:CATCH",
+                "=const:VAR",
+                "=continue:CONTINUE",
+                "=default:DEFAULT",
+                "=delete:DELETE",
+                "=do:DO",
+                "=else:ELSE",
+                "=false:FALSE",
+                "=finally:FINALLY",
+                "=for:FOR",
+                "=function:FUNCTION",
+                "=if:IF",
+                "=in:IN",
+                "=instanceof:INSTANCEOF",
+                "=new:NEW",
+                "=null:NULL",
+                "=return:RETURN",
+                "=switch:SWITCH",
+                "=this:THIS",
+                "=throw:THROW",
+                "=true:TRUE",
+                "=try:TRY",
+                "=typeof:TYPEOF",
+                "=void:VOID",
+                "=while:WHILE",
+                "=with:WITH",
+                "=var:VAR"
+             };
+            for(var i =0; i< ws.length;i++ ) {
+                var x = ws[i].split(":");
+                this.keywordNames.set(x[0],x[1]);
+            }
+        
+      
+            ws={
+                "; SEMICOLON",
+                ", COMMA",
+                "? HOOK",
+                ": COLON",
+                "|| OR", 
+                "&& AND",
+                "| BITWISE_OR",
+                "^ BITWISE_XOR",
+                "& BITWISE_AND",
+                "=== STRICT_EQ", 
+                "== EQ",
+                "= ASSIGN",
+                "!== STRICT_NE",
+                "!= NE",
+                "<< LSH",
+                "<= LE", 
+                "< LT",
+                ">>> URSH",
+                ">> RSH",
+                ">= GE",
+                "> GT", 
+                "++ INCREMENT",
+                "-- DECREMENT",
+                "+ PLUS",
+                "- MINUS",
+                "* MUL",
+                "/ DIV", 
+                "% MOD",
+                "! NOT",
+                "~ BITWISE_NOT",
+                ". DOT",
+                "[ LEFT_BRACE",
+                "] RIGHT_BRACE",
+                "{ LEFT_CURLY",
+                "} RIGHT_CURLY",
+                "( LEFT_PAREN",
+                ") RIGHT_PAREN"
+            };
+            for(var i =0; i< ws.length;i++ ) {
+                var x = ws[i].split(" ");
+                this.puncNames.set(x[0],x[1]);
+            }
+        
+           ws = {
+               "LEFT_PAREN:RIGHT_PAREN",
+               "RIGHT_PAREN:LEFT_PAREN",
+               "LEFT_CURLY:RIGHT_CURLY",
+               "RIGHT_CURLY:LEFT_CURLY",
+               "LEFT_BRACE:RIGHT_BRACE",
+               "RIGHT_BRACE:LEFT_BRACE"
+           };
+           for(var i =0; i< ws.length;i++ ) {
+               var x = ws[i].split(":");
+               this.matchingNames.set(x[0],x[1]);
+           }
+        }
+        
+        
+    }
+}
\ No newline at end of file
diff --git a/JsRender/Node.vala b/JsRender/Node.vala
new file mode 100644 (file)
index 0000000..c7fe904
--- /dev/null
@@ -0,0 +1,317 @@
+
+// test..
+// valac gitlive/app.Builder.js/JsRender/Lang.vala gitlive/app.Builder.js/JsRender/Node.vala --pkg gee-1.0 --pkg=json-glib-1.0 -o /tmp/Lang ;/tmp/Lang
+
+class JsRender.Node  {
+    
+    GLib.List<JsRender.Node> items; // child items..
+    
+    Gee.HashMap<string,string> props; // the properties..
+    
+  
+    
+    public bool is_array;
+    
+    Node()
+    {
+        this.items = new GLib.List<JsRender.Node>();
+        this.props = new Gee.HashMap<string,string>();
+        this.is_array = false;
+        
+    }
+    
+    
+    
+    
+    bool isArray()
+    {
+        return this.is_array;
+    }
+    bool hasChildren()
+    {
+        return this.items.length() > 0;
+    }
+    bool hasXnsType()
+    {
+        if (this.props.get("|xns") != null && this.props.get("xtype") != null) {
+            return true;
+            
+        }
+        return false;
+    }
+    // wrapper around get props that returns empty string if not found.
+    string get(string key)
+    {
+        var k = this.props.get(key);
+        if (k == null) {
+            return "";
+        }
+        return k;
+        
+    }
+     
+    /* creates javascript based on the rules */
+    
+  
+    
+    string mungeToString (bool isListener, string pad,  GLib.List<string> doubleStringProps)
+    {
+        
+         
+        pad = pad.length < 1 ? "    " : pad;
+        
+        
+         
+        
+        //isListener = isListener || false;
+
+       //var keys = this.keys();
+        var isArray = this.isArray();
+        
+        
+        var els = new GLib.List<string>(); 
+        var skip = new Gee.ArrayList<string>();
+        if (!isArray && this.hasXnsType() ) {
+                // this.mungeXtype(obj['|xns'] + '.' + obj['xtype'], els); ??????
+                
+                
+               skip.add("|xns");
+               skip.add("xtype");
+               
+        }
+        //var newitems = new Gee.ArrayList<JsRender.Node>();
+        var oprops = new Gee.HashMap<string,JsRender.Node>();
+        
+        if (!isArray && this.hasChildren()) {
+            // look for '*props'
+           
+            for (var ii =0; ii< this.items.length(); ii++) {
+                var pl = this.items.nth_data(ii);
+                if (!pl.props.has_key("*prop")) {
+                    //newitems.add(pl);
+                    continue;
+                }
+                
+                //print(JSON.stringify(pl,null,4));
+                // we have a prop...
+                //var prop = pl['*prop'] + '';
+                //delete pl['*prop'];
+                var prop = pl.get("*prop");
+                // name ends in [];
+                if (! Regex.match_simple("\\[\\]$", prop)) {
+                    // it's a standard prop..
+                    
+                    // munge property..??
+                    oprops.set(prop, pl);
+                    
+                    
+                    //keys.push(prop);
+                    continue;
+                }
+                
+                prop  = prop.substring(0,  -2); //strip []
+                // it's an array type..
+                if (!oprops.has_key(prop)) {
+                    var cn = new JsRender.Node();
+                    oprops.set(prop, cn);
+                    
+                }
+                // ignores the fact it might be duplciated...
+                oprops.get(prop).is_array = true;
+                oprops.get(prop).items.append(pl);
+              
+                
+                
+                
+            }
+            
+            //obj.items = newitems;
+            //if (!obj.items.length) {
+            //    delete obj.items;
+            //}
+            
+        }
+        if (this.isArray()) {
+            
+            
+            for (var i=0;i< this.items.length();i++) {
+                var el = this.items.nth_data(i);
+                
+                els.append("%d".printf(i) + " : " + el.mungeToString(false, pad,doubleStringProps));
+                
+            }
+            var spad = pad.substring(0, pad.length-4);
+            return   "{\n" +
+                pad  + string.join(",\n" + pad , els) + 
+                "\n" + spad +  "}";
+               
+            
+            
+            
+          
+        } 
+        string left;
+        Regex func_regex ;
+        try {
+            func_regex = new Regex("^\\s+|\\s+$");
+        } catch (Error e) {
+            print("failed to build regex");
+            return "";
+        }
+        var piter = this.props.map_iterator();
+        while (piter.next() ) {
+            var k = piter.get_key();
+            var v = piter.get_value();
+            
+            if (skip.contains(k) ) {
+                continue;
+            }
+            
+            
+            string leftv = k[0] == '|' ? k.substring(1) : k;
+            // skip builder stuff. prefixed with  '.' .. just like unix fs..
+            if (leftv[0] == '.') { // |. or . -- do not output..
+                continue;
+            }
+             if (k[0] == '*') {
+                // ignore '*prop';
+                continue;
+             }
+                
+            
+            if (JsRender.Lang.isKeyword(leftv) || JsRender.Lang.isBuiltin(leftv)) {
+                left = "'" + leftv + "'";
+            } else if (Regex.match_simple("[^A-Za-z_]+",leftv)) { // not plain a-z... - quoted.
+                var val = this.quoteString(leftv);
+                
+                left = "'" + val.substring(1, val.length-1).replace("'", "\\'") + "'";
+            } else {
+                left = leftv;
+            }
+            left += " : ";
+            
+            if (isListener) {
+            // change the lines...
+                            
+                string str;
+                try {
+                    str = func_regex.replace(v,v.length, 0, "");
+                } catch(Error e) {
+                    print("regex failed");
+                    return "";
+                }
+                
+                var lines = str.split("\n");
+                if (lines.length > 1) {
+                    str = string.join("\n" + pad, lines);
+                }
+                
+                els.append(left  + str);
+                continue;
+            }
+             
+            // next.. is it a function..
+            if (k[0] == '|') {
+                // does not hapepnd with arrays.. 
+                if (v.length < 1) {  //if (typeof(el) == 'string' && !obj[i].length) { //skip empty.
+                    continue;
+                }
+                
+                string str;
+                try {
+                    str = func_regex.replace(v,v.length, 0, "");
+                } catch(Error e) {
+                    print("regex failed");
+                    return "";
+                }
+                
+                var lines = str.split("\n");
+                if (lines.length > 1) {
+                    str =  string.join("\n" + pad, lines);
+                }
+                
+                els.append(left + str);
+                continue;
+            }
+            // standard..
+            
+            
+            if (JsRender.Lang.isNumber(v) || JsRender.Lang.isBoolean(v)) { // boolean or number...?
+                els.append(left + v );
+                continue;
+            }
+            
+            // strings..
+            if (doubleStringProps.length() < 1) {
+                els.append(left + this.quoteString(v));
+                continue;
+            }
+           
+            if (doubleStringProps.index(k) > -1) {
+                els.append(left + this.quoteString(v));
+                continue;
+            }
+             
+            // single quote.. v.substring(1, v.length-1).replace("'", "\\'") + "'";
+            els.append(left + "'" + v.substring(1, v.length-1).replace("'", "\\'") + "'");
+            
+
+           
+           
+           
+        }
+        var iter = oprops.map_iterator();
+        while (iter.next()) {
+            var k = iter.get_key();
+            var vo = iter.get_value();
+            string leftv = k[0] == '|' ? k.substring(1) : k;
+            if (JsRender.Lang.isKeyword(leftv) || JsRender.Lang.isBuiltin(leftv)) {
+                left = "'" + leftv + "'";
+            } else if (Regex.match_simple("[^A-Za-z_]+",leftv)) { // not plain a-z... - quoted.
+                var val = this.quoteString(leftv);
+                
+                left = "'" + val.substring(1, val.length-1).replace("'", "\\'") + "'";
+            } else {
+                left = leftv;
+            }
+            left += " : ";
+            
+            var right = vo.mungeToString(k == "listeners", pad + "    ",doubleStringProps);
+            
+            //if (!left.length && isArray) print(right);
+            
+            if (right.length > 0){
+                els.append(left + right);
+            }
+        
+            
+        }
+        if (els.length() < 1) {
+            return "";
+        }
+        // oprops...    
+            
+        var spad = pad.substring(0, pad.length-4);
+        return   "{\n" +
+            pad  + string.join(",\n" + pad , els) + 
+            "\n" + spad +  "}";
+           
+           
+               
+        
+        
+    }
+    static Json.Generator gen = null;
+    
+    string quoteString(string str)
+    {
+        if (Node.gen == null) {
+            Node.gen = new Json.Generator();
+        }
+        var builder = new Json.Builder();
+        builder.add_string_value(str);
+        Node.gen.set_root (builder.get_root ());
+        return  Node.gen.to_data (null);   
+    }
+    
+}
index d46b0fd..bb9394a 100644 (file)
@@ -666,7 +666,7 @@ Roo = XObject.define(
             
         }
         */
-         getHelpUrl : function(cls)
+        getHelpUrl : function(cls)
         {
             return 'http://www.akbkhome.com/roojs1/docs/symbols/' + cls + '.html';
         }
diff --git a/JsRender/Roo.vala b/JsRender/Roo.vala
new file mode 100644 (file)
index 0000000..e69de29
index e0bed2d..0b6e1ef 100644 (file)
@@ -87,8 +87,7 @@ right:
   Roo.form.NumberField         
   Roo.form.Checkbox         
   Roo.form.Radio         
-  Roo.form.ComboBox
-  Roo.form.ComboBoxArray         
+  Roo.form.ComboBox         
   Roo.form.TextArea         
   Roo.form.HtmlEditor         
   Roo.form.FCKeditor         
@@ -287,11 +286,6 @@ right:
   Roo.data.Store
   Roo.data.SimpleStore
 
-left:
-    Roo.form.ComboBoxArray:combo
-right:
-    Roo.form.ComboBox
-
 left:
   Roo.data.Store:proxy
 right:
@@ -351,6 +345,7 @@ right:
     Roo.bootstrap.Progress
     Roo.bootstrap.TabPanel
     Roo.bootstrap.DateField
+    Roo.bootstrap.TimeField
     Roo.bootstrap.CheckBox
     Roo.bootstrap.Radio
     Roo.bootstrap.ComboBox
index 744affd..9a21b0a 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 
-public class Project.Base {
+public class Project.Project {
     
     
     string id = "";
@@ -24,7 +24,7 @@ public class Project.Base {
     string xtype = "";
     
     
-    void Base (string path) {
+    void Project (string path) {
         
         this.name = name;