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
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
36         
37         if (JSDOC.opt.v) JSDOC.opt.LOG.verbose = true;
38         if (JSDOC.opt.o) JSDOC.opt.LOG.out = IO.open(JSDOC.opt.o);
39         
40         if (JSDOC.opt.T) {
41             //JSDOC.opt.LOG.inform("JsDoc Toolkit running in test mode at "+new Date()+".");
42             //IO.include("frame/Testrun.js");
43             //IO.include("test.js");
44         }
45         else {
46             JSDOC.opt.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
47             JSDOC.opt.LOG.inform("With options: ");
48             for (var o in JSDOC.opt) {
49                 JSDOC.opt.LOG.inform("    "+o+": "+JSDOC.opt[o]);
50             }
51             
52             var jsdoc = new JSDOC.JsDoc();
53             
54             if (JSDOC.opt.hasOwnProperty('Z')) { // secret debugging option
55                 JSDOC.opt.LOG.warn("So you want to see the data structure, eh? This might hang if you have circular refs...");
56                 //IO.include("frame/Dumper.js");
57                 var symbols = jsdoc.symbolSet.toArray();
58                 for (var i = 0, l = symbols.length; i < l; i++) {
59                     var symbol = symbols[i];
60                     print("// symbol: " + symbol.alias);
61                     print(symbol.serialize());
62                 }
63             }
64             else {
65                 var template = JSDOC.opt.t; // || System.getProperty("jsdoc.template.dir");
66                 println("Template: " + JSDOC.opt.t);
67                 
68                 function includeJs(fn)
69                 {
70                     return "include '" + fn +"';";
71                 }
72                 
73                 eval(includeJs(template + 'publish.js'));
74                 
75                 JSDOC.publish = publish;
76                 
77                 //var handler = jsdoc.symbolSet.handler;
78                 //if (handler && handler.publish) {
79                 //      handler.publish(jsdoc.symbolSet);
80                 //}
81                 //else {
82                     if (typeof(template) != "undefined") {
83                         // publish is in template!!     
84                         JSDOC.publish(jsdoc.symbolSet);
85                          
86                     }
87                     else {
88                         JSDOC.opt.LOG.warn("No template or handlers given. Might as well read the usage notes.");
89                         opt.usage();
90                     }
91                 //}
92             }
93         }
94         
95         if (JSDOC.opt.LOG.warnings.length) {
96             print(JSDOC.opt.LOG.warnings.length+" warning"+(JSDOC.opt.LOG.warnings.length != 1? "s":"")+".");
97         }
98         
99         if (JSDOC.opt.LOG.out) {
100             JSDOC.opt.LOG.out.flush();
101             JSDOC.opt.LOG.out.close();
102         }
103         
104         
105         
106         
107         
108         
109     },
110     
111     
112     
113     
114     
115     
116     apply : function(o, c, defaults){
117         if(defaults){
118             // no "this" reference for friendly out of scope calls
119             JSDOC.apply(o, defaults);
120         }
121         if(o && c && typeof c == 'object'){
122             for(var p in c){
123                 o[p] = c[p];
124             }
125         }
126         return o;
127     },
128         
129     
130     /**
131      * Qdump is used to generated cache dumps of objects
132      * @arg mixed t - object/array to dump
133      * @arg string prefix output with
134      * @arg string suffix output with
135      * @arg mixed defaults for the object - so they are not dumped..
136      */
137     
138     toQDump : function(t, pref, suf, defs)
139     {
140         //println("got ToDump: " + pref +" ??? " + suf);
141         //var ret = "JSDOC.Symbol.fromDump(";
142         var qret   = "";
143         defs = (typeof(defs) == "undefined") ? {} : defs;
144            
145         var isAr = t.constructor == Array;
146         var k = '';
147         var v = '';
148         for (var i in t) {
149            // println("dump: " + i + " : " +typeof(t[i]));
150             
151             if (!isAr) {
152                 k = typeof(i) == "number" ? i +":" : i.toSource()+":" ;
153             } else {
154                 if (typeof(i) != "number") {
155                     continue;
156                 }
157                 
158             }
159             
160             v = t[i];
161             //} else {
162               //  v = i;
163             //}
164             
165             
166             
167             var def = defs[i];
168             //if ((typeof(defs[i]) != 'undefined')  && (v.toSource() == defs[i]).toSource()) {
169             //    continue;
170             //}
171             
172             
173             
174             
175             switch(typeof(v)) {
176                 case "function":
177                     continue;
178               
179                     
180            
181                 case 'string':
182                     if (def == v) {
183                         continue;
184                     }
185                 
186                     if (!v.length) { // ?? skip empty!!
187                         continue;
188                     }
189                     
190                    if (qret.length) {
191                         qret+=",";
192                     }
193
194                     qret += k + v.toSource();
195                     continue;
196                 case 'boolean':    
197               
198                 case 'number':
199                     if (def == v) {
200                         continue;
201                     }
202                     if (qret.length) {
203                         qret+=",";
204                     }
205
206                     qret += k + v;
207                     
208                     continue;
209                 
210                 // undefined?
211                 case "object":
212                     
213                     //if (i == 'tags') {
214                     //    println(k +"?:" + (v.constructor == Array ? "ARRAY" : "OBJECT"));
215                     //}
216                   
217                     // what about raw objects...
218                     if (v.constructor == Array)  {
219                         //println("ARRAYLEN:" + v.length);
220                         var toadd = JSDOC.toQDump(v, '[', ']');
221                         if (k == 'tags') {
222                             println("Array: " + toadd);
223                         }
224                         
225                         if (toadd == "[]") {
226                           continue;
227                         }
228                         
229                         if (qret.length) {
230                             qret+=",";
231                         }
232                         qret += k + toadd;
233                         //println("AFT AR:" + qret);
234                         continue;
235                     }
236                     if (v.constructor == Object)  {
237                         var toadd = JSDOC.toQDump(v, '{', '}');
238                        if (toadd == "{}") {
239                             continue;
240                         }
241                         
242                         if (qret.length) {
243                             qret+=",";
244                         }
245                         qret += k + toadd;
246                         //println("AFT AR:" + qret);
247                         continue;
248                     }
249                     //println("v:toQdump" + typeof(v['toQDump']));
250                     if (typeof(v['toQDump']) != "undefined") {
251                         if (qret.length) {
252                             qret+=",";
253                         }
254
255                         qret += k + v.toQDump(v);
256                         continue;
257                     }
258                     println("SKIP   " + i + " : " +typeof(t[i]) + ":" + t[i].toSource());
259                     continue;
260                 
261                 default:
262                     println("SKIP   " + i + " : " +typeof(t[i]) );
263                 
264                     continue;
265                 
266             }
267         }
268        // println(qret);
269         //throw "done";
270         return pref + qret + suf;
271     },
272     /**
273      * 
274      * Depreciated - use Script.prettyDump() - cant remember real name..
275      * 
276      * 
277      */
278     
279     prettyDump : function(src)
280     {
281        // println("tidy SRC");
282        return Script.prettyDump(src);
283        /*
284         var ar = Script.tokenize(src);
285        println("tidy" + ar.length);
286         var eret = '';
287         var indent = "";
288         var lbr = 0;
289         
290         // this is reallllllllly sloooooowwwwww!!! = perhaps we should just dump it straight to the file!!!
291         
292         for( var i =0 ;i< ar.length; i++) {
293             
294             //println(ar[i].toSource());
295             var tok = ar[i];
296             //println("tidy" + i + ":" + tok.val);
297             if ( (tok.val == '{') ||  (tok.val == '[') || (tok.val == '(') ) {
298                 indent += "  ";
299                 eret += tok.val;
300                 lbr = true;
301                 continue;
302             }
303             if ( (tok.val == '}') ||  (tok.val == ']') || (tok.val == ')') ) {
304                 
305                 indent = indent.substring(2); // strip spaces..
306                 if (i < (ar.length-1) && ar[i+1].val == ',') {
307                     ar[i].val +=",";
308                     i++;
309                     
310                 }
311                 eret += (lbr ? "" : "\n" +  indent ) + tok.val  ;
312                 lbr = true;
313                 continue;
314             }
315             if ( (tok.val == ',')) {
316                 eret += tok.val;
317                 lbr = true;
318                 continue;
319             }
320             if (lbr) {
321                 eret += "\n" + indent;
322             }
323             lbr = false;
324             eret += tok.val;
325             
326             
327        }
328        return eret;
329         */
330     }
331
332     
333 };
334   
335
336
337
338
339
340  
341
342
343
344