JSDOC/Introspect/Link.js
[gnome.introspection-doc-generator] / JSDOC / Introspect / Link.js
1 //<script type="text/javascript">
2
3 console = imports.console.console;
4
5 XObject = imports.XObject.XObject
6
7
8 /** Handle the creation of HTML links to documented symbols.
9         @constructor
10     * 
11     *  
12     * 
13 */
14
15  
16 Link = XObject.define({
17     function() {
18         this.alias = "";
19         this.src = "";
20         this.file = "";
21         this.text = "";
22         this.innerName = "";
23         this.classLink = false;
24         this.targetName = "";
25         
26         Link.symbolsDir = Link.symbolsDir || '';
27         Link.base = Link.base || '';
28         Link.ext= Link.ext || '';
29         Link.srcDir= Link.srcDir || '';
30             
31         
32     },
33     Object,  {
34         
35         alias : "",
36         src : "",
37         file : "",
38         text : "",
39         innerName : "",
40         classLink : false,
41         targetName : "",
42         
43         
44         
45         toString : function() {
46             var linkString;
47             var thisLink = this;
48             
49             if (this.none) {
50                 return 'none';
51             }
52             if (this.alias) {
53                 
54                 if (typeof(this.builtins[this.alias]) != 'undefined') {
55                     this.text = this.alias;
56                     return thisLink._makeExternLink(this.builtins[this.alias]);
57                 }
58                 
59                 
60                 return thisLink._makeSymbolLink(this.alias);
61                 
62                 /*
63                 
64                 linkString = this.alias.replace(/(^|[^a-z$0-9_#.:-])([|a-z$0-9_#.:-]+)($|[^a-z$0-9_#.:-])/i,
65                     function(match, prematch, symbolName, postmatch) {
66                         var symbolNames = symbolName.split("|");
67                         var links = [];
68                         for (var i = 0, l = symbolNames.length; i < l; i++) {
69                             thisLink.alias = symbolNames[i];
70                             links.push(thisLink._makeSymbolLink(symbolNames[i]));
71                         }
72                         return prematch+links.join("|")+postmatch;
73                     }
74                 );
75                 */
76             }
77             else if (this.extern) {
78                 linkString = thisLink._makeExternLink(this.extern);
79             }
80             else if (this.src) {
81                 linkString = thisLink._makeSrcLink(this.src);
82             }
83             else if (this.file) {
84                 linkString = thisLink._makeFileLink(this.file);
85             }
86
87             return linkString;
88         },
89         
90         builtins : {
91             'Object' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object',
92             //'Object...' : 'http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object',
93             'Array' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array',
94             'Function' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Function',
95             'String' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String',
96             'Number' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Number',
97             'Boolean' : 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Boolean',
98             'HTMLElement' : 'http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037'
99         },
100         
101         
102         toGnome: function(alias) 
103         {
104             this.file = "#";
105             var pr = alias.split('.');
106             var aa = alias;
107             var site = 'library.gnome.org';
108             var extra = '';
109             switch(pr[0]) {
110                 case 'GIRepository':
111                    this.extern = 'http://live.gnome.org/GObjectIntrospection';
112                    aa = pr[0];
113                    break;
114                 case 'Gio':   
115                 case 'GLib':   
116                 case 'GObject':   
117                     aa = pr.length > 1 ? 'G' + pr[1] : pr[0];
118                     break;
119                 case 'GdkPixbuf':   
120                     aa = pr.length > 1 ? 'Gdk' + pr[1] : pr[0];
121                     break;
122                 case 'GtkSource':   
123                     aa = pr.length > 1 ? pr[0] + pr[1] : 'GtkSourceView';
124                     break;
125                     
126                 case 'Gst': 
127                     aa = pr.length > 1 ? pr[0] + pr[1] : 'GStreamer';
128                     break;
129                 
130                 case 'Pango':
131                     extra = ' GTK-Doc';
132                     break;
133                 case 'GstController': 
134                 case 'GstApp': 
135                 case 'GstAudio': 
136                 case 'GstBase': 
137                 case 'GstCheck': 
138                 case 'GstFft': 
139                 case 'GstInterfaces': 
140                 case 'GstNet': 
141                 case 'GstNetbuffer': 
142                 case 'GstPbutils': 
143                 case 'GstRiff': 
144                 case 'GstRtp': 
145                 case 'GstRtsp': 
146                 case 'GstSdp': 
147                 case 'GstTag': 
148                 case 'GstVideo': 
149                 
150                     aa = pr.length > 1 ? 'Gst' + pr[1] : pr[0];
151                     break;
152                     
153                 case 'Epiphany':     
154                     aa = pr.length > 1 ?  pr[1] : pr[0];
155                     break;
156                 case 'WebKit':
157                     site = 'webkitgtk.org';
158                 
159                 default:
160                     
161                     aa = alias.replace('.', '');
162                     
163                     break;
164              
165             }
166             if (!this.extern) {
167                 this.extern = 'http://www.google.com/search?hl=en&amp;' + 
168                         'q=site%3A' + site  + '+' + aa + extra +
169                         '&amp;btnI=I%27m+Feeling+Lucky&amp;meta=&amp;aq=f&amp;oq=';
170             }
171             
172             this.text =  aa;
173             return this;
174         },
175         
176         target : function(targetName) {
177             if (typeof(targetName) != 'undefined') this.targetName = targetName;
178             return this;
179         },
180         inner : function(inner) {
181             if (typeof(inner) != 'undefined') this.innerName = inner;
182             return this;
183         },
184         withText:  function(text) {
185             if (typeof(text) != 'undefined') this.text = text;
186             return this;
187         },
188         toSrc :function(filename) {
189             if (typeof(filename) != 'undefined') this.src = filename;
190             return this;
191         },
192         
193         toSymbolLong : function(alias)
194         {
195             this.show_full = true;
196             return this.toSymbol(alias)
197         },
198         toSymbol : function(alias) {
199             
200             
201             switch(alias) {
202                 case 'boolean' : this.alias = 'Boolean'; return this;
203                 case 'int' : this.alias = 'Number'; return this;
204                 case 'uint' : this.alias = 'Number'; return this;
205                 
206                 case 'long' : this.alias = 'Number'; return this;
207                 case 'ulong' : this.alias = 'Number'; return this;
208                 
209                 
210                 case 'uint8' : this.alias = 'Number'; return this;
211                 case 'int8' : this.alias = 'Number'; return this;
212                 
213                 case 'uint16' : this.alias = 'Number'; return this;
214                 case 'uint16' : this.alias = 'Number'; return this;
215                 
216                 case 'int32' : this.alias = 'Number'; return this;
217                 case 'uint32' : this.alias = 'Number'; return this;
218                 
219                 case 'uint64' : this.alias = 'Number'; return this;
220                 case 'int64' : this.alias = 'Number'; return this;
221                 
222                 
223                 case 'GType' : this.alias = 'Number'; return this;
224                 case 'size' : this.alias = 'Number'; return this;
225                 case 'ssize' : this.alias = 'Number'; return this;
226                 
227                 case 'float' : this.alias = 'Number'; return this;
228                 case 'double' : this.alias = 'Number'; return this;
229                 case 'time_t' : this.alias = 'Number'; return this;
230                 // fixme - should find out more details..
231                 case 'array' : this.alias = 'Array'; return this;
232                 case 'gslist' : this.alias = 'Array'; return this;
233                 case 'glist' : this.alias = 'Array'; return this; // homefully.
234                 case 'ghash' : this.alias = 'Object'; return this; // homefully.
235                 
236                 
237                 case 'error' : this.alias = 'Object'; return this; // homefully.
238                 case 'filename' : this.alias = 'String'; return this; // hopefully..
239                 case 'utf8' : this.alias = 'String'; return this;
240                 
241                 case 'void' : this.none = true; return this;
242                 
243                 
244             }
245             
246             
247             if (typeof(alias) != 'undefined') {
248                 this.alias = new String(alias);
249             }
250             return this;
251         },
252         toClass : function(alias) {
253             this.classLink = true;
254             return this.toSymbol(alias);
255         },
256         toFile : function(file) {
257             if (typeof(file) != 'undefined') this.file = file;
258             return this;
259         },
260         
261         
262       
263
264         /** prefixed for hashes */
265
266
267         /** Appended to the front of relative link paths. */
268
269
270         symbolNameToLinkName : function(symbol) {
271             var linker = "";
272             if (symbol.isStatic) linker = ".";
273             else if (symbol.isInner) linker = "-";
274             
275             return linker+symbol.name;
276         },
277
278         
279
280
281         /** Create a link to a snother symbol. */
282         _makeSymbolLink :  function(alias) 
283         {
284             var target = '';
285             var txt = this.show_full ? alias : alias.split('.').pop();
286              return "<a href=\"./"+alias+".html\""+target+">"+txt+"</a>";    
287             
288             /*
289             // look for '/' in alias..
290             if (/\//.test(alias)) {
291                 var bits = alias.split('/');
292                 var ret = "";
293                 for(var i=0; i < bits.length; i++) {
294                     if (i > 0) {
295                         ret +="/";
296                     }
297                     ret += this._makeSymbolLink(bits[i]);
298                 }
299                 return ret;
300                 
301             }
302             
303             
304             */
305             
306             var linkBase = Link.base + Link.symbolsDir;
307             //var linkTo = Link.symbolSet.getSymbol(alias);
308             linkTo = "FIXME";
309             var linkPath;
310             var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
311             
312             // is it an internal link?
313             if (alias.charAt(0) == "#") {
314                 linkPath = alias;
315                 fullLinkPath = alias;
316             
317             // if there is no symbol by that name just return the name unaltered
318             } else if (!linkTo) {
319                 
320                 if (typeof(this.builtins[alias]) != 'undefined') {
321                     return "<a href=\""+ this.builtins[alias]+"\""+target+">"+alias+"</a>";
322                  }
323                 
324                 return this.text || alias;
325             
326             
327             // it's a symbol in another file
328             } else {
329
330                 if (!linkTo.isConstructor && !linkTo.isNamespace) { // it's a method or property
331                     linkPath = escape(linkTo.memberOf) || "_global_";
332                     linkPath += Link.ext + "#" + this.symbolNameToLinkName(linkTo);
333                 }
334                 else {
335                     linkPath = escape(linkTo.alias);
336                     linkPath += Link.ext + (this.classLink? "":"#" +  "constructor");
337                 }
338                 //linkPath = linkBase + linkPath;
339                 fullLinkPath = linkBase + linkPath;
340             }
341             
342             var linkText = this.text || alias;
343             
344             var link = {linkPath: linkPath, linkText: linkText, fullLinkPath: fullLinkPath};
345             
346             //if (typeof PluginManager != "undefined") {
347             //    JSDOC.PluginManager.run("onSymbolLink", link);
348             //}
349             
350             return "<a href=\""+link.fullLinkPath+"\""+target+">"+link.linkText+"</a>";
351         },
352
353
354         /** Create a link to a source file. */
355          _makeSrcLink : function(srcFilePath) {
356             var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
357                 
358             // transform filepath into a filename
359             var srcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "."); // was _
360             var lsrcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, ".");
361             var outFilePath = Link.base + Link.srcDir + srcFile.replace(/.js$/, '') + Link.ext;
362             
363             if (!this.text) this.text = FilePath.fileName(srcFilePath);
364             return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
365         },
366
367         /** Create a link to a source file. */
368          _makeFileLink : function(filePath) {
369             var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
370                 
371             var outFilePath =  Link.base + filePath;
372
373             if (!this.text) this.text = filePath;
374             return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
375         },
376         
377         /** Create a link to a source file. */
378          _makeExternLink : function(filePath) {
379             var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
380                 
381             if (!this.text) this.text = filePath;
382             return "<a href=\""+filePath+"\""+target+">"+this.text+"</a>";
383         }
384         
385 });