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         
43         //for (var o in JSDOC.opt) {
44         //        JSDOC.opt.LOG.inform("    "+o+": "+JSDOC.opt[o]);
45         //    }
46             
47           
48             
49              
50         var template = Options.template; // || System.getProperty("jsdoc.template.dir");
51         println("Template: " + Options.template);
52                 
53         
54          
55         
56         
57     },
58     
59     
60     
61     
62     
63     
64     apply : function(o, c, defaults){
65         if(defaults){
66             // no "this" reference for friendly out of scope calls
67             JSDOC.apply(o, defaults);
68         }
69         if(o && c && typeof c == 'object'){
70             for(var p in c){
71                 o[p] = c[p];
72             }
73         }
74         return o;
75     },
76         
77     
78     /**
79      * Qdump is used to generated cache dumps of objects
80      * @arg mixed t - object/array to dump
81      * @arg string prefix output with
82      * @arg string suffix output with
83      * @arg mixed defaults for the object - so they are not dumped..
84      */
85     
86     toQDump : function(t, pref, suf, defs)
87     {
88         //println("got ToDump: " + pref +" ??? " + suf);
89         //var ret = "JSDOC.Symbol.fromDump(";
90         var qret   = "";
91         defs = (typeof(defs) == "undefined") ? {} : defs;
92            
93         var isAr = t.constructor == Array;
94         var k = '';
95         var v = '';
96         for (var i in t) {
97            // println("dump: " + i + " : " +typeof(t[i]));
98             
99             if (!isAr) {
100                 k = typeof(i) == "number" ? i +":" : i.toSource()+":" ;
101             } else {
102                 if (typeof(i) != "number") {
103                     continue;
104                 }
105                 
106             }
107             
108             v = t[i];
109             //} else {
110               //  v = i;
111             //}
112             
113             
114             
115             var def = defs[i];
116             //if ((typeof(defs[i]) != 'undefined')  && (v.toSource() == defs[i]).toSource()) {
117             //    continue;
118             //}
119             
120             
121             
122             
123             switch(typeof(v)) {
124                 case "function":
125                     continue;
126               
127                     
128            
129                 case 'string':
130                     if (def == v) {
131                         continue;
132                     }
133                 
134                     if (!v.length) { // ?? skip empty!!
135                         continue;
136                     }
137                     
138                    if (qret.length) {
139                         qret+=",";
140                     }
141
142                     qret += k + v.toSource();
143                     continue;
144                 case 'boolean':    
145               
146                 case 'number':
147                     if (def == v) {
148                         continue;
149                     }
150                     if (qret.length) {
151                         qret+=",";
152                     }
153
154                     qret += k + v;
155                     
156                     continue;
157                 
158                 // undefined?
159                 case "object":
160                     
161                     //if (i == 'tags') {
162                     //    println(k +"?:" + (v.constructor == Array ? "ARRAY" : "OBJECT"));
163                     //}
164                   
165                     // what about raw objects...
166                     if (v.constructor == Array)  {
167                         //println("ARRAYLEN:" + v.length);
168                         var toadd = JSDOC.toQDump(v, '[', ']');
169                         if (k == 'tags') {
170                             println("Array: " + toadd);
171                         }
172                         
173                         if (toadd == "[]") {
174                           continue;
175                         }
176                         
177                         if (qret.length) {
178                             qret+=",";
179                         }
180                         qret += k + toadd;
181                         //println("AFT AR:" + qret);
182                         continue;
183                     }
184                     if (v.constructor == Object)  {
185                         var toadd = JSDOC.toQDump(v, '{', '}');
186                        if (toadd == "{}") {
187                             continue;
188                         }
189                         
190                         if (qret.length) {
191                             qret+=",";
192                         }
193                         qret += k + toadd;
194                         //println("AFT AR:" + qret);
195                         continue;
196                     }
197                     //println("v:toQdump" + typeof(v['toQDump']));
198                     if (typeof(v['toQDump']) != "undefined") {
199                         if (qret.length) {
200                             qret+=",";
201                         }
202
203                         qret += k + v.toQDump(v);
204                         continue;
205                     }
206                     println("SKIP   " + i + " : " +typeof(t[i]) + ":" + t[i].toSource());
207                     continue;
208                 
209                 default:
210                     println("SKIP   " + i + " : " +typeof(t[i]) );
211                 
212                     continue;
213                 
214             }
215         }
216        // println(qret);
217         //throw "done";
218         return pref + qret + suf;
219     },
220     /**
221      * 
222      * Depreciated - use Script.prettyDump() - cant remember real name..
223      * 
224      * 
225      */
226     
227     prettyDump : function(src)
228     {
229        // println("tidy SRC");
230        return Script.prettyDump(src);
231        /*
232         var ar = Script.tokenize(src);
233        println("tidy" + ar.length);
234         var eret = '';
235         var indent = "";
236         var lbr = 0;
237         
238         // this is reallllllllly sloooooowwwwww!!! = perhaps we should just dump it straight to the file!!!
239         
240         for( var i =0 ;i< ar.length; i++) {
241             
242             //println(ar[i].toSource());
243             var tok = ar[i];
244             //println("tidy" + i + ":" + tok.val);
245             if ( (tok.val == '{') ||  (tok.val == '[') || (tok.val == '(') ) {
246                 indent += "  ";
247                 eret += tok.val;
248                 lbr = true;
249                 continue;
250             }
251             if ( (tok.val == '}') ||  (tok.val == ']') || (tok.val == ')') ) {
252                 
253                 indent = indent.substring(2); // strip spaces..
254                 if (i < (ar.length-1) && ar[i+1].val == ',') {
255                     ar[i].val +=",";
256                     i++;
257                     
258                 }
259                 eret += (lbr ? "" : "\n" +  indent ) + tok.val  ;
260                 lbr = true;
261                 continue;
262             }
263             if ( (tok.val == ',')) {
264                 eret += tok.val;
265                 lbr = true;
266                 continue;
267             }
268             if (lbr) {
269                 eret += "\n" + indent;
270             }
271             lbr = false;
272             eret += tok.val;
273             
274             
275        }
276        return eret;
277         */
278     }
279
280     
281 };
282   
283
284
285
286
287
288  
289
290
291
292