JSDOC/BuildDocs.js
authorAlan Knowles <alan@akbkhome.com>
Tue, 29 Jun 2010 08:38:25 +0000 (16:38 +0800)
committerAlan Knowles <alan@akbkhome.com>
Tue, 29 Jun 2010 08:38:25 +0000 (16:38 +0800)
JSDOC/BuildDocs.js

index 47fcc94..882b759 100644 (file)
@@ -4,9 +4,13 @@
        @namespace
 */
 
-Options = import.Options.Options;
+
 XObject = import.XObject.XObject;
 File = import.File.File;
+
+Options = import.Options.Options;
+Parser   = import.Parser.Parser;
+
 /******************    INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
 
 // should not realy be here -- or anywhere...??
@@ -18,15 +22,10 @@ File = import.File.File;
 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 :)
-     */
     
     
+    srcFiles : [],
+    
     build : function (opts)
     {
         
@@ -46,7 +45,7 @@ BuildDocs = {
         
         Options.srcFiles = this._getSrcFiles();
         this._parseSrcFiles();
-        this.symbolSet = JSDOC.Parser.symbols;
+        this.symbolSet = Parser.symbols;
          
              
         
@@ -56,7 +55,101 @@ BuildDocs = {
     },
     
     
-    
+    _getSrcFiles : function() 
+    {
+        this.srcFiles = [];
+        
+        var ext = ["js"];
+        if (JSDOC.opt.x) {
+            ext = JSDOC.opt.x.split(",").map(function($) {return $.toLowerCase()});
+        }
+        
+        for (var i = 0; i < JSDOC.opt._.length; i++) {
+            this.srcFiles = this.srcFiles.concat(
+                IO.ls(JSDOC.opt._[i], JSDOC.opt.r).filter(
+                    function($) {
+                        var thisExt = $.split(".").pop().toLowerCase();
+                        return (ext.indexOf(thisExt) > -1 || thisExt in JSDOC.handlers); // we're only interested in files with certain extensions
+                    }
+                )
+            );
+        }
+        
+        return this.srcFiles;
+    },
+
+    _parseSrcFiles : function() 
+    {
+        Parser.init();
+        
+        for (var i = 0, l = this.srcFiles.length; i < l; i++) {
+            
+            var srcFile = this.srcFiles[i];
+            
+            
+            var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
+            println(cacheFile);
+            
+            if (!JSDOC.opt.C && File.exists(cacheFile)) {
+                // check filetime?
+                
+                var c_mt = File.getTimes(cacheFile);
+                var o_mt = File.getTimes(srcFile);
+                //println(c_mt.toSource());
+               // println(o_mt.toSource());
+               
+                // this check does not appear to work according to the doc's - need to check it out.
+               
+                if (c_mt[0] > o_mt[0]) { // cached time  > original time!
+                    // use the cached mtimes..
+                    var syms =  {};
+                    
+                    eval("syms = " + File.read(cacheFile));
+                    
+                    for (var sy in syms) {
+                        //println("ADD:" + sy );
+                       JSDOC.Parser.symbols.addSymbol(syms[sy]);
+                    }
+                    continue;
+                }
+            }
+            
+            try {
+                var src = IO.readFile(srcFile);
+            }
+            catch(e) {
+                LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
+            }
+
+            // Check to see if there is a handler for this file type
+    //         var ext = FilePath.fileExtension(srcFile);
+    //                 if (JSDOC.handlers[ext]) {
+    //                         LOG.inform(" Using external handler for '" + ext + "'");
+    // 
+    //                         symbols = symbols.concat(JSDOC.handlers[ext].handle(srcFile, src));
+    //                         symbols.handler = JSDOC.handlers[ext];
+    //                 }
+    //                 else {
+                // The default (JSDOC) handler
+                var tr = new JSDOC.TokenReader();
+                var ts = new JSDOC.TokenStream(tr.tokenize(src));
+        
+                JSDOC.Parser.parse(ts, srcFile);
+                 //  println("Symbols: " + JSDOC.Parser.symbols.keys().toSource());
+                var outstr = JSDOC.prettyDump(JSDOC.toQDump(JSDOC.Parser.filesSymbols[JSDOC.Symbol.srcFile]._index,'{','}'))            
+            
+            //if (outstr.length > 3) {
+                // dont cache crap..
+                File.write(cacheFile, outstr);
+            //}
+                
+    //         }
+        }
+        
+        
+        
+        JSDOC.Parser.finish();
+    }