JSDOC/BuildDocs.js
authorAlan Knowles <alan@akbkhome.com>
Tue, 29 Jun 2010 06:22:02 +0000 (14:22 +0800)
committerAlan Knowles <alan@akbkhome.com>
Tue, 29 Jun 2010 06:22:02 +0000 (14:22 +0800)
JSDOC/BuildDocs.js

index e69de29..e34bd4d 100644 (file)
@@ -0,0 +1,344 @@
+//<script type="text/javascript">
+/**
+       This is the main container for the JSDOC application.
+       @namespace
+*/
+
+Options = import.Options.Options;
+XObject = import.XObject.XObject;
+
+/******************    INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
+
+// should not realy be here -- or anywhere...??
+
+
+
+
+
+BuildDocs = {
+    
+    VERSION : "2.0.0",
+    /**
+     * apply properties to an object
+     * 
+     * @param object to get properties (eg. JSDOC.Token.prototype)
+     * @param object of properties, - eg. a list of all the methods
+     * @param default (optional) -- no idea :)
+     */
+    
+    
+    build : function (opts)
+    {
+        
+        XObject.extend(Options, opts);
+         
+
+        
+        if (JSDOC.opt.v) JSDOC.opt.LOG.verbose = true;
+        if (JSDOC.opt.o) JSDOC.opt.LOG.out = IO.open(JSDOC.opt.o);
+        
+        if (JSDOC.opt.T) {
+            //JSDOC.opt.LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
+            //IO.include("frame/Testrun.js");
+            //IO.include("test.js");
+        }
+        else {
+            JSDOC.opt.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
+            JSDOC.opt.LOG.inform("With options: ");
+            for (var o in JSDOC.opt) {
+                JSDOC.opt.LOG.inform("    "+o+": "+JSDOC.opt[o]);
+            }
+            
+            var jsdoc = new JSDOC.JsDoc();
+            
+            if (JSDOC.opt.hasOwnProperty('Z')) { // secret debugging option
+                JSDOC.opt.LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
+                //IO.include("frame/Dumper.js");
+                var symbols = jsdoc.symbolSet.toArray();
+                for (var i = 0, l = symbols.length; i < l; i++) {
+                    var symbol = symbols[i];
+                    print("// symbol: " + symbol.alias);
+                    print(symbol.serialize());
+                }
+            }
+            else {
+                var template = JSDOC.opt.t; // || System.getProperty("jsdoc.template.dir");
+                println("Template: " + JSDOC.opt.t);
+                
+                function includeJs(fn)
+                {
+                    return "include '" + fn +"';";
+                }
+                
+                eval(includeJs(template + 'publish.js'));
+                
+                JSDOC.publish = publish;
+                
+                //var handler = jsdoc.symbolSet.handler;
+                //if (handler && handler.publish) {
+                //     handler.publish(jsdoc.symbolSet);
+                //}
+                //else {
+                    if (typeof(template) != "undefined") {
+                        // publish is in template!!    
+                        JSDOC.publish(jsdoc.symbolSet);
+                         
+                    }
+                    else {
+                        JSDOC.opt.LOG.warn("No template or handlers given. Might as well read the usage notes.");
+                        opt.usage();
+                    }
+                //}
+            }
+        }
+        
+        if (JSDOC.opt.LOG.warnings.length) {
+            print(JSDOC.opt.LOG.warnings.length+" warning"+(JSDOC.opt.LOG.warnings.length != 1? "s":"")+".");
+        }
+        
+        if (JSDOC.opt.LOG.out) {
+            JSDOC.opt.LOG.out.flush();
+            JSDOC.opt.LOG.out.close();
+        }
+        
+        
+        
+        
+        
+        
+    },
+    
+    
+    
+    
+    
+    
+    apply : function(o, c, defaults){
+        if(defaults){
+            // no "this" reference for friendly out of scope calls
+            JSDOC.apply(o, defaults);
+        }
+        if(o && c && typeof c == 'object'){
+            for(var p in c){
+                o[p] = c[p];
+            }
+        }
+        return o;
+    },
+        
+    
+    /**
+     * Qdump is used to generated cache dumps of objects
+     * @arg mixed t - object/array to dump
+     * @arg string prefix output with
+     * @arg string suffix output with
+     * @arg mixed defaults for the object - so they are not dumped..
+     */
+    
+    toQDump : function(t, pref, suf, defs)
+    {
+        //println("got ToDump: " + pref +" ??? " + suf);
+        //var ret = "JSDOC.Symbol.fromDump(";
+        var qret   = "";
+        defs = (typeof(defs) == "undefined") ? {} : defs;
+           
+        var isAr = t.constructor == Array;
+        var k = '';
+        var v = '';
+        for (var i in t) {
+           // println("dump: " + i + " : " +typeof(t[i]));
+            
+            if (!isAr) {
+                k = typeof(i) == "number" ? i +":" : i.toSource()+":" ;
+            } else {
+                if (typeof(i) != "number") {
+                    continue;
+                }
+                
+            }
+            
+            v = t[i];
+            //} else {
+              //  v = i;
+            //}
+            
+            
+            
+            var def = defs[i];
+            //if ((typeof(defs[i]) != 'undefined')  && (v.toSource() == defs[i]).toSource()) {
+            //    continue;
+            //}
+            
+            
+            
+            
+            switch(typeof(v)) {
+                case "function":
+                    continue;
+              
+                    
+           
+                case 'string':
+                    if (def == v) {
+                        continue;
+                    }
+                
+                    if (!v.length) { // ?? skip empty!!
+                        continue;
+                    }
+                    
+                   if (qret.length) {
+                        qret+=",";
+                    }
+
+                    qret += k + v.toSource();
+                    continue;
+                case 'boolean':    
+              
+                case 'number':
+                    if (def == v) {
+                        continue;
+                    }
+                    if (qret.length) {
+                        qret+=",";
+                    }
+
+                    qret += k + v;
+                    
+                    continue;
+                
+                // undefined?
+                case "object":
+                    
+                    //if (i == 'tags') {
+                    //    println(k +"?:" + (v.constructor == Array ? "ARRAY" : "OBJECT"));
+                    //}
+                  
+                    // what about raw objects...
+                    if (v.constructor == Array)  {
+                        //println("ARRAYLEN:" + v.length);
+                        var toadd = JSDOC.toQDump(v, '[', ']');
+                        if (k == 'tags') {
+                            println("Array: " + toadd);
+                        }
+                        
+                        if (toadd == "[]") {
+                          continue;
+                        }
+                        
+                        if (qret.length) {
+                            qret+=",";
+                        }
+                        qret += k + toadd;
+                        //println("AFT AR:" + qret);
+                        continue;
+                    }
+                    if (v.constructor == Object)  {
+                        var toadd = JSDOC.toQDump(v, '{', '}');
+                       if (toadd == "{}") {
+                            continue;
+                        }
+                        
+                        if (qret.length) {
+                            qret+=",";
+                        }
+                        qret += k + toadd;
+                        //println("AFT AR:" + qret);
+                        continue;
+                    }
+                    //println("v:toQdump" + typeof(v['toQDump']));
+                    if (typeof(v['toQDump']) != "undefined") {
+                        if (qret.length) {
+                            qret+=",";
+                        }
+
+                        qret += k + v.toQDump(v);
+                        continue;
+                    }
+                    println("SKIP   " + i + " : " +typeof(t[i]) + ":" + t[i].toSource());
+                    continue;
+                
+                default:
+                    println("SKIP   " + i + " : " +typeof(t[i]) );
+                
+                    continue;
+                
+            }
+        }
+       // println(qret);
+        //throw "done";
+        return pref + qret + suf;
+    },
+    /**
+     * 
+     * Depreciated - use Script.prettyDump() - cant remember real name..
+     * 
+     * 
+     */
+    
+    prettyDump : function(src)
+    {
+       // println("tidy SRC");
+       return Script.prettyDump(src);
+       /*
+        var ar = Script.tokenize(src);
+       println("tidy" + ar.length);
+        var eret = '';
+        var indent = "";
+        var lbr = 0;
+        
+        // this is reallllllllly sloooooowwwwww!!! = perhaps we should just dump it straight to the file!!!
+        
+        for( var i =0 ;i< ar.length; i++) {
+            
+            //println(ar[i].toSource());
+            var tok = ar[i];
+            //println("tidy" + i + ":" + tok.val);
+            if ( (tok.val == '{') ||  (tok.val == '[') || (tok.val == '(') ) {
+                indent += "  ";
+                eret += tok.val;
+                lbr = true;
+                continue;
+            }
+            if ( (tok.val == '}') ||  (tok.val == ']') || (tok.val == ')') ) {
+                
+                indent = indent.substring(2); // strip spaces..
+                if (i < (ar.length-1) && ar[i+1].val == ',') {
+                    ar[i].val +=",";
+                    i++;
+                    
+                }
+                eret += (lbr ? "" : "\n" +  indent ) + tok.val  ;
+                lbr = true;
+                continue;
+            }
+            if ( (tok.val == ',')) {
+                eret += tok.val;
+                lbr = true;
+                continue;
+            }
+            if (lbr) {
+                eret += "\n" + indent;
+            }
+            lbr = false;
+            eret += tok.val;
+            
+            
+       }
+       return eret;
+        */
+    }
+
+    
+};
+  
+
+
+
+
+
+
+
+
+