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