JsTemplate/Link.js
[gnome.introspection-doc-generator] / JsTemplate / Link.js
index 9904dfd..913d72d 100644 (file)
@@ -1,5 +1,7 @@
 //<script type="text/javascript">
 
+XObject  = imports.XObject.XObject;
+
 /**
  * Generic Template Link handler..
  * 
 /** Handle the creation of HTML links to documented symbols.
        @constructor
 */
-function Link() {
-       this.alias = "";
-       this.src = "";
-       this.file = "";
-       this.text = "";
-       this.innerName = "";
-       this.classLink = false;
-       this.targetName = "";
-       
-       this.target = function(targetName) {
-               if (typeof(targetName) != 'undefined') this.targetName = targetName;
-               return this;
-       }
-       this.inner = function(inner) {
-               if (typeof(inner) != 'undefined') this.innerName = inner;
-               return this;
-       }
-       this.withText = function(text) {
-               if (typeof(text) != 'undefined') this.text = text;
-               return this;
-       }
-       this.toSrc = function(filename) {
-               if (typeof(filename) != 'undefined') this.src = filename;
-               return this;
-       }
-       this.toSymbol = function(alias) {
-               if (typeof(alias) != 'undefined') {
-            this.alias = new String(alias);
+Link = XObject.define(
+    /*
+    * constructor
+    */ 
+    function () {
+        
+    }, 
+    Object,
+    {
+        
+        alias : "",
+        src : "",
+        file : "",
+        text : "",
+        innerName : "",
+        classLink : false,
+        targetName : "",
+        srcReplace : false, 
+        
+        
+        
+        target : function(targetName) {
+            if (typeof(targetName) != 'undefined') this.targetName = targetName;
+            return this;
+        },
+        inner : function(inner) {
+            if (typeof(inner) != 'undefined') this.innerName = inner;
+            return this;
+        },
+        withText : function(text) {
+            if (typeof(text) != 'undefined') this.text = text;
+            return this;
+        },
+        toSrc : function(filename) {
+            if (typeof(filename) != 'undefined') this.src = filename;
+            if (this.srcReplace(
+            
+            
+            return this;
+        },
+        toSymbol : function(alias) {
+            if (typeof(alias) != 'undefined') {
+                this.alias = new String(alias);
+            }
+            return this;
+        },
+        toClass : function(alias) {
+            this.classLink = true;
+            return this.toSymbol(alias);
+        },
+        toFile : function(file) {
+            if (typeof(file) != 'undefined') this.file = file;
+            return this;
+        },
+        
+        toString : function() {
+            var linkString;
+            var thisLink = this;
+
+            if (this.alias) {
+                linkString = this.alias.replace(/(^|[^a-z$0-9_#.:-])([|a-z$0-9_#.:-]+)($|[^a-z$0-9_#.:-])/i,
+                    function(match, prematch, symbolName, postmatch) {
+                        var symbolNames = symbolName.split("|");
+                        var links = [];
+                        for (var i = 0, l = symbolNames.length; i < l; i++) {
+                            thisLink.alias = symbolNames[i];
+                            links.push(thisLink._makeSymbolLink(symbolNames[i]));
+                        }
+                        return prematch+links.join("|")+postmatch;
+                    }
+                );
+            }
+            else if (this.src) {
+                linkString = thisLink._makeSrcLink(this.src);
+            }
+            else if (this.file) {
+                linkString = thisLink._makeFileLink(this.file);
+            }
+
+            return linkString;
+        },
+        
+        
+        
+        
+        
+        
+        
+        /** Create a link to a snother symbol. */
+        _makeSymbolLink : function(alias) {
+            
+            // look for '/' in alias..
+            if (/\//.test(alias)) {
+                var bits = alias.split('/');
+                var ret = "";
+                for(var i=0; i < bits.length; i++) {
+                    if (i > 0) {
+                        ret +="/";
+                    }
+                    ret += this._makeSymbolLink(bits[i]);
+                }
+                return ret;
+                
+            }
+            
+            
+            
+            var linkBase = Link.base+  imports.JSDOC.BuildDocs.BuildDocs.symbolsDir;
+            var linkTo = Link.symbolSet.getSymbol(alias);
+            var linkPath;
+            var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
+            
+            // is it an internal link?
+            if (alias.charAt(0) == "#") {
+                linkPath = alias;
+                fullLinkPath = alias;
+            
+            // if there is no symbol by that name just return the name unaltered
+            } else if (!linkTo) {
+                
+                if (typeof(Link.builtins[alias]) != 'undefined') {
+                    return "<a href=\""+ Link.builtins[alias]+"\""+target+">"+alias+"</a>";
+                 }
+                
+                return this.text || alias;
+            
+            
+            // it's a symbol in another file
+            } else {
+
+                if (!linkTo.is("CONSTRUCTOR") && !linkTo.isNamespace) { // it's a method or property
+                    linkPath = escape(linkTo.memberOf) || "_global_";
+                    linkPath += imports.JSDOC.Options.Options.ext + "#" + Link.symbolNameToLinkName(linkTo);
+                }
+                else {
+                    linkPath = escape(linkTo.alias);
+                    linkPath += imports.JSDOC.Options.Options.ext + (this.classLink? "":"#" + Link.hashPrefix + "constructor");
+                }
+                //linkPath = linkBase + linkPath;
+                fullLinkPath = linkBase + linkPath;
+            }
+            
+            var linkText = this.text || alias;
+            
+            var link = {linkPath: linkPath, linkText: linkText, fullLinkPath: fullLinkPath};
+            
+            //if (typeof JSDOC.PluginManager != "undefined") {
+            //    JSDOC.PluginManager.run("onSymbolLink", link);
+            //}
+            
+            return "<a href=\""+link.fullLinkPath+"\""+target+" roo:cls=\""+link.linkPath+"\">"+link.linkText+"</a>";
+        },
+
+
+        /** Create a link to a source file. */
+        _makeSrcLink : function(srcFilePath) {
+            var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
+                
+            // transform filepath into a filename
+            var srcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "."); // was _
+            var lsrcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, ".");
+            var outFilePath = Link.base + '/symbols/' +  srcFile.replace(/.js$/, '') + 
+                imports.JSDOC.Options.Options.publishExt;
+            
+            if (!this.text) this.text = srcFilePath; //FilePath.fileName(srcFilePath);
+            return "<a href=\""+outFilePath+"\""+target+" roo:cls=\"src/"+lsrcFile+"\">"+this.text+"</a>";
+        },
+
+        /** Create a link to a source file. */
+        _makeFileLink : function(filePath) {
+            var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
+                
+            var outFilePath =  Link.base + filePath;
+
+            if (!this.text) this.text = filePath;
+            return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
         }
-               return this;
-       }
-       this.toClass = function(alias) {
-               this.classLink = true;
-               return this.toSymbol(alias);
-       }
-       this.toFile = function(file) {
-               if (typeof(file) != 'undefined') this.file = file;
-               return this;
-       }
-       
-       this.toString = function() {
-               var linkString;
-               var thisLink = this;
-
-               if (this.alias) {
-                       linkString = this.alias.replace(/(^|[^a-z$0-9_#.:-])([|a-z$0-9_#.:-]+)($|[^a-z$0-9_#.:-])/i,
-                               function(match, prematch, symbolName, postmatch) {
-                                       var symbolNames = symbolName.split("|");
-                                       var links = [];
-                                       for (var i = 0, l = symbolNames.length; i < l; i++) {
-                                               thisLink.alias = symbolNames[i];
-                                               links.push(thisLink._makeSymbolLink(symbolNames[i]));
-                                       }
-                                       return prematch+links.join("|")+postmatch;
-                               }
-                       );
-               }
-               else if (this.src) {
-                       linkString = thisLink._makeSrcLink(this.src);
-               }
-               else if (this.file) {
-                       linkString = thisLink._makeFileLink(this.file);
-               }
-
-               return linkString;
-       }
-}
+});
+
+
+
 
 /** prefixed for hashes */
 Link.hashPrefix = "";
@@ -104,92 +220,3 @@ Link.builtins = {
 }
     
 
-
-/** Create a link to a snother symbol. */
-Link.prototype._makeSymbolLink = function(alias) {
-    
-    // look for '/' in alias..
-    if (/\//.test(alias)) {
-        var bits = alias.split('/');
-        var ret = "";
-        for(var i=0; i < bits.length; i++) {
-            if (i > 0) {
-                ret +="/";
-            }
-            ret += this._makeSymbolLink(bits[i]);
-        }
-        return ret;
-        
-    }
-    
-    
-    
-       var linkBase = Link.base+JSDOC.publish.conf.symbolsDir;
-       var linkTo = Link.symbolSet.getSymbol(alias);
-       var linkPath;
-       var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
-    
-       // is it an internal link?
-       if (alias.charAt(0) == "#") {
-        linkPath = alias;
-        fullLinkPath = alias;
-       
-       // if there is no symbol by that name just return the name unaltered
-       } else if (!linkTo) {
-        
-        if (typeof(Link.builtins[alias]) != 'undefined') {
-            return "<a href=\""+ Link.builtins[alias]+"\""+target+">"+alias+"</a>";
-         }
-        
-        return this.text || alias;
-    
-       
-       // it's a symbol in another file
-       } else {
-
-               if (!linkTo.is("CONSTRUCTOR") && !linkTo.isNamespace) { // it's a method or property
-                       linkPath = escape(linkTo.memberOf) || "_global_";
-                       linkPath += JSDOC.publish.conf.ext + "#" + Link.symbolNameToLinkName(linkTo);
-               }
-               else {
-                       linkPath = escape(linkTo.alias);
-                       linkPath += JSDOC.publish.conf.ext + (this.classLink? "":"#" + Link.hashPrefix + "constructor");
-               }
-               //linkPath = linkBase + linkPath;
-        fullLinkPath = linkBase + linkPath;
-       }
-       
-       var linkText = this.text || alias;
-       
-       var link = {linkPath: linkPath, linkText: linkText, fullLinkPath: fullLinkPath};
-       
-       if (typeof JSDOC.PluginManager != "undefined") {
-               JSDOC.PluginManager.run("onSymbolLink", link);
-       }
-       
-       return "<a href=\""+link.fullLinkPath+"\""+target+" roo:cls=\""+link.linkPath+"\">"+link.linkText+"</a>";
-}
-
-
-/** Create a link to a source file. */
-Link.prototype._makeSrcLink = function(srcFilePath) {
-       var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
-               
-       // transform filepath into a filename
-       var srcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "."); // was _
-    var lsrcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, ".");
-       var outFilePath = Link.base + JSDOC.publish.conf.srcDir + srcFile.replace(/.js$/, '') + JSDOC.publish.conf.ext;
-    
-       if (!this.text) this.text = FilePath.fileName(srcFilePath);
-       return "<a href=\""+outFilePath+"\""+target+" roo:cls=\"src/"+lsrcFile+"\">"+this.text+"</a>";
-}
-
-/** Create a link to a source file. */
-Link.prototype._makeFileLink = function(filePath) {
-       var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
-               
-       var outFilePath =  Link.base + filePath;
-
-       if (!this.text) this.text = filePath;
-       return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
-}
\ No newline at end of file