JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index 8f7edff..bafe5a3 100644 (file)
@@ -25,7 +25,7 @@ var x = new  Packer({
     files : [ "/location/of/file1.js", "/location/of/file2.js", ... ],
     target : "/tmp/output.js",
     debugTarget : "/tmp/output.debug.js", // merged file without compression.
-    translateJson : "/tmp/translate.json",
+    translateJSON: "/tmp/translate.json",
     
     
 );
@@ -72,15 +72,12 @@ Packer = function(cfg)
     if (!this.files) {
         throw "No Files";
     }
-    if (!this.target) {
-        throw "No Target";
-    }
-    if ((typeof(cfg.tmpDir) != 'undefined') && (!cfg.cleanup)) {
-        this.cleanup = false; // do not clean up files.. = as tmpdir is set.
-    }
+    
+  
  
     this.timer =  new Date() * 1;
     this.packAll();
+    
  
 }
 Packer.prototype = {
@@ -102,7 +99,7 @@ Packer.prototype = {
      */
     tmpDir : '/tmp',
     
-    translateJson : '', // json based list of strings in all files.
+    translateJSON : '', // json based list of strings in all files.
    
     /**
      * @prop cleanup {Boolean} (optional) clean up temp files after done - 
@@ -110,12 +107,18 @@ Packer.prototype = {
      */
     cleanup : true, //
     
+    
+    out : '', // if no target is specified - then this will contain the result
+    
     packAll : function()  // do the packing (run from constructor)
     {
         
         //this.transOrigFile= bpath + '/../lang.en.js'; // needs better naming...
         //File.write(this.transfile, "");
-        File.write(this.target, "");
+        if (this.target) {
+            File.write(this.target, "");
+        }
+        
         if (this.debugTarget) {
             File.write(this.debugTarget, "");
         }
@@ -179,14 +182,20 @@ Packer.prototype = {
              
           
         }  
-        if (this.translateJson) {
+        if (this.translateJSON) {
             
                
             print("MERGING LANGUAGE");
-            File.write(this.target, "if (typeof(_T) == 'undefined') { _T={};}\n");
+            var out = "if (typeof(_T) == 'undefined') { _T={};}\n"
+            if (this.target) {
+                File.write(this.target, out);
+            } else {
+                this.out += out;
+            }
             
             
-            File.write(this.translateJson, "");
+            
+            File.write(this.translateJSON, "");
             for(var i=0; i < this.files.length; i++)  {
                 var file = this.files[i];
                 var transfile= this.tmpDir + '/' +file.replace(/\//g, '.') +'.lang.trans';
@@ -194,7 +203,12 @@ Packer.prototype = {
                 if (File.exists(transmd5)) {
                     var str = File.read(transmd5);
                     if (str.length) {
-                        File.append(this.target, str + "\n");
+                        if (this.target) {
+                            File.append(this.target, str + "\n");
+                        } else {
+                            this.out += str + "\n";
+                        }
+                        
                     }
                     if (this.cleanup) {
                         File.remove(transmd5);
@@ -203,7 +217,7 @@ Packer.prototype = {
                 if (File.exists(transfile)) {
                     var str = File.read(transfile);
                     if (str.length) {
-                        File.append(this.translateJson, str);
+                        File.append(this.translateJSON, str);
                     }
                     if (this.cleanup) {
                         File.remove(transfile);
@@ -227,7 +241,12 @@ Packer.prototype = {
             var str = File.read(minfile);
             print("using MIN FILE  "+ minfile);
             if (str.length) {
-                File.append(this.target, str + "\n");
+                if (this.target) {
+                    File.append(this.target, str + "\n");   
+                } else {
+                    this.out += str + "\n";
+                }
+                
             }
             if (this.cleanup) {
                 File.remove(minfile);
@@ -259,7 +278,7 @@ Packer.prototype = {
         var toks = tr.tokenize(new TextStream(str)); // dont merge xxx + . + yyyy etc.
         
         // at this point we can write a language file...
-        if (this.translateJson) {
+        if (this.translateJSON) {
             this.writeTranslateFile(fn, minfile, tr.translateMap);
         }
         
@@ -282,18 +301,7 @@ Packer.prototype = {
         return out;
         
         
-        
-     
-    var ts = new   TokenStream(toks);
-   // ts.dump();
-    var sp = new  ScopeParser(ts);
-    sp.buildSymbolTree();
-    sp.mungeSymboltree();
-    print(sp.warnings.join("\n"));
-    var out =  CompressWhite(sp.ts);
-    return out;
-        
-        
+         
     },
     
     timerPrint: function (str) {
@@ -358,14 +366,17 @@ Packer.prototype = {
     {
         //print("STRING HANDLER");
        // callback when outputing compressed file, 
-        if (!this.translate) {
+        if (!this.translateJSON) {
          //   print("TURNED OFF");
             return tok.outData;
         }
-        if (tok.qc != '"') {
+        if (tok.name == SINGLE_QUOTE) {
             return tok.outData;
         }
         var sval = tok.data.substring(1,tok.data.length-1);
+        // we do not clean up... quoting here!??!!?!?!?!?
+        
+        
         // blank with tabs or spaces..
         //if (!sval.replace(new RegExp("(\\\\n|\\\\t| )+",'g'), '').length) {
        //     return tok.outData;