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