JSDOC/BuildDocs.js
[gnome.introspection-doc-generator] / JSDOC / BuildDocs.js
1 //<script type="text/javascript">
2 /**
3         This is the main container for the JSDOC application.
4         @namespace
5 */
6
7 Options = import.Options.Options;
8 XObject = import.XObject.XObject;
9 File = import.File.File;
10 /******************    INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
11
12 // should not realy be here -- or anywhere...??
13
14
15
16
17
18 BuildDocs = {
19     
20     VERSION : "2.0.0",
21     /**
22      * apply properties to an object
23      * 
24      * @param object to get properties (eg. JSDOC.Token.prototype)
25      * @param object of properties, - eg. a list of all the methods
26      * @param default (optional) -- no idea :)
27      */
28     
29     
30     build : function (opts)
31     {
32         
33         XObject.extend(Options, opts);
34          
35         Options.init();
36         
37     
38          
39         
40         Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
41         Options.LOG.inform("With options: ");
42         File.mkdir(
43         
44         
45         // the -c option: use a configuration file - not supported at present..
46         
47          
48              
49         
50          
51         
52         
53     },
54     
55     
56     
57     
58     
59     
60     apply : function(o, c, defaults){
61         if(defaults){
62             // no "this" reference for friendly out of scope calls
63             JSDOC.apply(o, defaults);
64         }
65         if(o && c && typeof c == 'object'){
66             for(var p in c){
67                 o[p] = c[p];
68             }
69         }
70         return o;
71     },
72         
73     
74     /**
75      * Qdump is used to generated cache dumps of objects
76      * @arg mixed t - object/array to dump
77      * @arg string prefix output with
78      * @arg string suffix output with
79      * @arg mixed defaults for the object - so they are not dumped..
80      */
81     
82     toQDump : function(t, pref, suf, defs)
83     {
84         //println("got ToDump: " + pref +" ??? " + suf);
85         //var ret = "JSDOC.Symbol.fromDump(";
86         var qret   = "";
87         defs = (typeof(defs) == "undefined") ? {} : defs;
88            
89         var isAr = t.constructor == Array;
90         var k = '';
91         var v = '';
92         for (var i in t) {
93            // println("dump: " + i + " : " +typeof(t[i]));
94             
95             if (!isAr) {
96                 k = typeof(i) == "number" ? i +":" : i.toSource()+":" ;
97             } else {
98                 if (typeof(i) != "number") {
99                     continue;
100                 }
101                 
102             }
103             
104             v = t[i];
105             //} else {
106               //  v = i;
107             //}
108             
109             
110             
111             var def = defs[i];
112             //if ((typeof(defs[i]) != 'undefined')  && (v.toSource() == defs[i]).toSource()) {
113             //    continue;
114             //}
115             
116             
117             
118             
119             switch(typeof(v)) {
120                 case "function":
121                     continue;
122               
123                     
124            
125                 case 'string':
126                     if (def == v) {
127                         continue;
128                     }
129                 
130                     if (!v.length) { // ?? skip empty!!
131                         continue;
132                     }
133                     
134                    if (qret.length) {
135                         qret+=",";
136                     }
137
138                     qret += k + v.toSource();
139                     continue;
140                 case 'boolean':    
141               
142                 case 'number':
143                     if (def == v) {
144                         continue;
145                     }
146                     if (qret.length) {
147                         qret+=",";
148                     }
149
150                     qret += k + v;
151                     
152                     continue;
153                 
154                 // undefined?
155                 case "object":
156                     
157                     //if (i == 'tags') {
158                     //    println(k +"?:" + (v.constructor == Array ? "ARRAY" : "OBJECT"));
159                     //}
160                   
161                     // what about raw objects...
162                     if (v.constructor == Array)  {
163                         //println("ARRAYLEN:" + v.length);
164                         var toadd = JSDOC.toQDump(v, '[', ']');
165                         if (k == 'tags') {
166                             println("Array: " + toadd);
167                         }
168                         
169                         if (toadd == "[]") {
170                           continue;
171                         }
172                         
173                         if (qret.length) {
174                             qret+=",";
175                         }
176                         qret += k + toadd;
177                         //println("AFT AR:" + qret);
178                         continue;
179                     }
180                     if (v.constructor == Object)  {
181                         var toadd = JSDOC.toQDump(v, '{', '}');
182                        if (toadd == "{}") {
183                             continue;
184                         }
185                         
186                         if (qret.length) {
187                             qret+=",";
188                         }
189                         qret += k + toadd;
190                         //println("AFT AR:" + qret);
191                         continue;
192                     }
193                     //println("v:toQdump" + typeof(v['toQDump']));
194                     if (typeof(v['toQDump']) != "undefined") {
195                         if (qret.length) {
196                             qret+=",";
197                         }
198
199                         qret += k + v.toQDump(v);
200                         continue;
201                     }
202                     println("SKIP   " + i + " : " +typeof(t[i]) + ":" + t[i].toSource());
203                     continue;
204                 
205                 default:
206                     println("SKIP   " + i + " : " +typeof(t[i]) );
207                 
208                     continue;
209                 
210             }
211         }
212        // println(qret);
213         //throw "done";
214         return pref + qret + suf;
215     },
216     /**
217      * 
218      * Depreciated - use Script.prettyDump() - cant remember real name..
219      * 
220      * 
221      */
222     
223     prettyDump : function(src)
224     {
225        // println("tidy SRC");
226        return Script.prettyDump(src);
227        /*
228         var ar = Script.tokenize(src);
229        println("tidy" + ar.length);
230         var eret = '';
231         var indent = "";
232         var lbr = 0;
233         
234         // this is reallllllllly sloooooowwwwww!!! = perhaps we should just dump it straight to the file!!!
235         
236         for( var i =0 ;i< ar.length; i++) {
237             
238             //println(ar[i].toSource());
239             var tok = ar[i];
240             //println("tidy" + i + ":" + tok.val);
241             if ( (tok.val == '{') ||  (tok.val == '[') || (tok.val == '(') ) {
242                 indent += "  ";
243                 eret += tok.val;
244                 lbr = true;
245                 continue;
246             }
247             if ( (tok.val == '}') ||  (tok.val == ']') || (tok.val == ')') ) {
248                 
249                 indent = indent.substring(2); // strip spaces..
250                 if (i < (ar.length-1) && ar[i+1].val == ',') {
251                     ar[i].val +=",";
252                     i++;
253                     
254                 }
255                 eret += (lbr ? "" : "\n" +  indent ) + tok.val  ;
256                 lbr = true;
257                 continue;
258             }
259             if ( (tok.val == ',')) {
260                 eret += tok.val;
261                 lbr = true;
262                 continue;
263             }
264             if (lbr) {
265                 eret += "\n" + indent;
266             }
267             lbr = false;
268             eret += tok.val;
269             
270             
271        }
272        return eret;
273         */
274     }
275
276     
277 };
278   
279
280
281
282
283
284  
285
286
287
288