JSDOC/Packer.js
[gnome.introspection-doc-generator] / JSDOC / Packer.js
index c640e53..352a6e1 100644 (file)
@@ -105,9 +105,13 @@ Packer.prototype = {
      * @prop cleanup {Boolean} (optional) clean up temp files after done - 
      *    Defaults to false if you set tmpDir, otherwise true.
      */
-    cleanup : true, //
-    
+    cleanup : true,  
     
+    /**
+     * @prop prefix {String} (optional) prefix of directory to be stripped of when
+     *    Calculating md5 of filename 
+     */
+    prefix : '',  
     out : '', // if no target is specified - then this will contain the result
     
     packAll : function()  // do the packing (run from constructor)
@@ -278,7 +282,8 @@ Packer.prototype = {
         
         // at this point we can write a language file...
         if (this.translateJSON) {
-            this.writeTranslateFile(fn, minfile, tr.translateMap);
+            
+            this.writeTranslateFile(fn, minfile, toks);
         }
         
         this.activeFile = fn;
@@ -320,10 +325,22 @@ Packer.prototype = {
      * 
      */
     
-    writeTranslateFile : function(fn, minfile, map
+    writeTranslateFile : function(fn, minfile, toks
     {
+        
+        var map = {};
+        var _this = this;
+        toks.forEach(function (t) {
+            if (t.type == 'STRN' && t.name == 'DOUBLE_QUOTE') {
+                var sval = t.data.substring(1,t.data.length-1);
+                var ffn = fn.substring(_this.prefix.length);
+                map.push( sval);
+            }
+        })
+        
         var transfile = minfile + '.lang.trans';
         var transmd5 = minfile + '.lang';
+        print("writeTranslateFile "  + transfile);
         var i = 0;
         var v = '';
         if (File.exists(transfile)) {
@@ -336,11 +353,10 @@ Packer.prototype = {
         if (!i ) {
             return; // no strings in file...
         }
-        var ff = fn.split('/');
-        var ffn = ff[ff.length-1];
+        var ffn = fn.substring(this.prefix.length);
          
          
-        File.write(transfile, "\n" + ffn.toSource() + " : {");
+        File.write(transfile, "\n'" + ffn  + "' : {");
         var l = '';
         var _tout = {}
          
@@ -365,12 +381,12 @@ Packer.prototype = {
     {
         //print("STRING HANDLER");
        // callback when outputing compressed file, 
-       var data = tok.outData !== false ? tok.outData : tok.data;
+       var data = tok.data;
         if (!this.translateJSON) {
          //   print("TURNED OFF");
             return data;
         }
-        if (tok.name == SINGLE_QUOTE) {
+        if (tok.name == 'SINGLE_QUOTE') {
             return data;
         }
         
@@ -383,12 +399,11 @@ Packer.prototype = {
        //     return tok.outData;
        // }
         
+        var sval = tok.data.substring(1,data.length-1);
+        var fn = this.activeFile.substring(this.prefix.length);
         
         
-        
-        var ff = this.activeFile.split('/');
-        var ffn = ff[ff.length-1];
-        return '_T["' + this.md5(ffn + '-' + sval) + '"]';
+        return '_T["' + this.md5(fn + '-' + sval) + '"]';
         
         
     }