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