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