Skip to content

Instantly share code, notes, and snippets.

@micmath
Created August 7, 2012 21:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save micmath/61faa72a8793d15605ee to your computer and use it in GitHub Desktop.
Save micmath/61faa72a8793d15605ee to your computer and use it in GitHub Desktop.
Possible implementation of a "local" tag.
/**
@overview Make references to local things local.
@module plugins/local
@author Michael Mathews <micmath@gmail.com>
*/
var thisModule = '',
registry = {};
function reset() {
thisModule = '';
registry = {};
}
exports.defineTags = function(dictionary) {
dictionary.defineTag('local', {
onTagged: function(doclet, tag) {
registry[tag.text] = true;
}
});
}
exports.handlers = {
jsdocCommentFound: function(e) {
if (thisModule) for (var local in registry) {
e.comment = e.comment.replace('{'+local, '{'+thisModule+'~'+local);
}
},
newDoclet: function(e) {
if (e.doclet.kind === 'module') {
thisModule = e.doclet.longname;
}
else {
if (thisModule) for (var local in registry) {
var augment;
if (e.doclet.augments) {
for (var i = 0, len = e.doclet.augments.length; i < len; i++) {
augment = e.doclet.augments[i];
if (augment && augment.indexOf(local) === 0) {
e.doclet.augments[i] = thisModule+'~'+e.doclet.augments[i];
}
}
}
if (e.doclet.longname.indexOf(local) === 0) {
e.doclet.longname = thisModule+'~'+e.doclet.longname;
}
}
}
},
fileComplete: function(e) {
reset();
}
};
/**
* @fileoverview This is a test case.
* @module test
* @local BaseClass
* @local ChildClass
*/
/**
* This is a base class.
* @constructor
*/
function BaseClass(x) {
/** document me */
this.x = x;
}
/**
* Gets X.
* @return {number} The value of X.
*/
BaseClass.prototype.getX = function() {
return this.x;
};
/**
* This is a class that inherits from the base class.
* @constructor
* @extends {BaseClass}
*/
function ChildClass(x, y) {
BaseClass.call(this, x);
this.y = y;
}
ChildClass.prototype = Object.create(BaseClass.prototype);
ChildClass.prototype.constructor = ChildClass;
/**
* Returns a copy of this ChildClass.
* @return {ChildClass} The copy.
*/
ChildClass.prototype.copy = function() {
return new ChildClass(this.x, this.y);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment