jsdoc: Add asCode parameter to Link() constructor, to define if it should be wrapped in <tt> or not.

This commit is contained in:
Jürg Lehni 2011-06-08 13:36:46 +01:00
parent 16f184a9a1
commit 4f5415b1e5
5 changed files with 16 additions and 10 deletions

View file

@ -1,7 +1,7 @@
/** Handle the creation of HTML links to documented symbols. /** Handle the creation of HTML links to documented symbols.
@constructor @constructor
*/ */
function Link() { function Link(asCode) {
this.alias = ""; this.alias = "";
this.src = ""; this.src = "";
this.file = ""; this.file = "";
@ -9,6 +9,7 @@ function Link() {
this.innerName = ""; this.innerName = "";
this.classLink = false; this.classLink = false;
this.targetName = ""; this.targetName = "";
this.asCode = asCode;
this.target = function(targetName) { this.target = function(targetName) {
if (defined(targetName)) this.targetName = targetName; if (defined(targetName)) this.targetName = targetName;
@ -172,7 +173,12 @@ Link.prototype._makeSymbolLink = function(alias, parameters) {
var linkName = link.linkPath.replace(/^[^#]+#/, ''); var linkName = link.linkPath.replace(/^[^#]+#/, '');
onClick = " onclick=\"return toggleMember('" + linkName + "', true);\""; onClick = " onclick=\"return toggleMember('" + linkName + "', true);\"";
} }
var html = "<a href=\""+link.linkPath+link.linkInner+"\""+target+onClick+"><tt>"+link.linkText+"</tt></a>"; var text = link.linkText;
// TODO: tt is gone in HTML5. Instead we should give these links and code
// elements a special class so they can be styled through CSS.
if (this.asCode)
text = "<tt>" + text + "</tt>";
var html = "<a href=\""+link.linkPath+link.linkInner+"\""+target+onClick+">" + text + "</a>";
if (this.prefix || this.suffix) if (this.prefix || this.suffix)
html = (this.prefix || '') + html + (this.suffix || ''); html = (this.prefix || '') + html + (this.suffix || '');
return html; return html;

View file

@ -35,7 +35,7 @@ var Render = new function() {
// {@link ...} -> html links // {@link ...} -> html links
str = str.replace(/\{@link ([^} ]+) ?\}/gi, str = str.replace(/\{@link ([^} ]+) ?\}/gi,
function(match, symbolName) { function(match, symbolName) {
return new Link().toSymbol(symbolName.replace(/[\^]/g, '-')); return new Link(true).toSymbol(symbolName.replace(/[\^]/g, '-'));
} }
); );
// {@code ...} -> code blocks // {@code ...} -> code blocks
@ -142,7 +142,7 @@ var Render = new function() {
}; };
param.inheritedLinks = []; param.inheritedLinks = [];
for (var i in param.inheritedClasses) { for (var i in param.inheritedClasses) {
param.inheritedLinks.push('<b>' + new Link().toSymbol(i) + '</b>'); param.inheritedLinks.push('<b>' + new Link(true).toSymbol(i) + '</b>');
} }
param.inheritedLinks = param.inheritedLinks.join(', '); param.inheritedLinks = param.inheritedLinks.join(', ');
// Add the grouped operators to param: // Add the grouped operators to param:
@ -234,7 +234,7 @@ var Render = new function() {
name: symbol.name, name: symbol.name,
description: processInlineTags(symbol.desc, description: processInlineTags(symbol.desc,
{stripParagraphs: true}), {stripParagraphs: true}),
typeLink: new Link().toSymbol(symbol.type), typeLink: new Link(true).toSymbol(symbol.type),
symbol: symbol symbol: symbol
}); });
}, },
@ -271,7 +271,7 @@ var Render = new function() {
name: symbol.name, name: symbol.name,
description: processInlineTags(symbol.desc, description: processInlineTags(symbol.desc,
{stripParagraphs: true}), {stripParagraphs: true}),
typeLink: new Link().toSymbol(symbol.type), typeLink: new Link(true).toSymbol(symbol.type),
symbol: symbol symbol: symbol
}); });
}, },

View file

@ -49,7 +49,7 @@
<for each="inheritedClass" in="data.inheritedClasses"> <for each="inheritedClass" in="data.inheritedClasses">
<if test="inheritedClass.properties.length"> <if test="inheritedClass.properties.length">
<!-- =========================== inherited properties ====================== --> <!-- =========================== inherited properties ====================== -->
<div class="reference-members"><h2>Properties inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2> <div class="reference-members"><h2>Properties inherited from {+ new Link(true).toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.properties"> <for each="member" in="inheritedClass.properties">
{+ Render.property(member, true) +} {+ Render.property(member, true) +}
</for> </for>
@ -57,7 +57,7 @@
</if> </if>
<if test="inheritedClass.methods.length"> <if test="inheritedClass.methods.length">
<!-- =========================== inherited methods ========================= --> <!-- =========================== inherited methods ========================= -->
<div class="reference-members"><h2>Functions inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2> <div class="reference-members"><h2>Functions inherited from {+ new Link(true).toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.methods"> <for each="member" in="inheritedClass.methods">
{+ Render.method(member, true) +} {+ Render.method(member, true) +}
</for> </for>

View file

@ -30,7 +30,7 @@
</if> </if>
<ul><b>Type:</b> <ul><b>Type:</b>
<li> <li>
{+new Link().toSymbol(data.symbol.type)+} {+new Link(true).toSymbol(data.symbol.type)+}
</li> </li>
</ul> </ul>
{+ Render.seeAlsos(data.symbol) +} {+ Render.seeAlsos(data.symbol) +}

View file

@ -1,5 +1,5 @@
<if test="data.see.length"> <if test="data.see.length">
<p><b>See also:</b> <p><b>See also:</b>
<for each="item" in="data.see"><if test="$item_i > 0">, </if><tt>{+ new Link().toSymbol(item) +}</tt></for> <for each="item" in="data.see"><if test="$item_i > 0">, </if><tt>{+ new Link(true).toSymbol(item) +}</tt></for>
</p> </p>
</if> </if>