Skip to content

Commit

Permalink
Added initial support for @alias tag. Added test for @module tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
micmath committed Jan 13, 2011
1 parent 0624faf commit 70d9bb2
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function main() {
require('jsdoc/src/handlers').attachTo(app.jsdoc.parser);

docs = app.jsdoc.parser.parse(sourceFiles, env.opts.encoding);

//dump(docs); exit(0);
if (env.opts.expel) {
dump(docs);
exit(0);
Expand Down
7 changes: 5 additions & 2 deletions modules/jsdoc/src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
newDoclet = new jsdoc.doclet.Doclet(e.comment, e);
}

// we need to get the symbol name from code
if (e.code && e.code.name) {
if (newDoclet.alias) {
newDoclet.addTag('name', newDoclet.alias);
newDoclet.postProcess();
}
else if (e.code && e.code.name) { // we need to get the symbol name from code
newDoclet.addTag('name', e.code.name);

if (!newDoclet.memberof && e.astnode) {
Expand Down
24 changes: 24 additions & 0 deletions modules/jsdoc/tag/dictionary/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
mustHaveValue: true
});

dictionary.defineTag('alias', {
mustHaveValue: true,
onTagged: function(doclet, tag) {
doclet.alias = tag.value;

return true;
}
});

dictionary.defineTag('memberof', {
mustHaveValue: true,
onTagged: function(doclet, tag) {
Expand All @@ -151,6 +160,8 @@
onTagged: function(doclet, tag) {
setDocletKindToTitle(doclet, tag);
setDocletNameToValue(doclet, tag);
doclet.name || setDocletNameToFilename(doclet, tag);

applyNamespace(doclet, tag);

return false;
Expand Down Expand Up @@ -291,6 +302,19 @@
doclet.name = app.jsdoc.name.applyNamespace(doclet.name, tag.title)
}

function setDocletNameToFilename(doclet, tag) {
var name = doclet.meta.filename;
name = name.replace(/\.js$/i, '');

for (var i = 0, len = env.opts._.length; i < len; i++) {
if (name.indexOf(env.opts._[i]) === 0) {
name = name.replace(env.opts._[0], '');
break
}
}
doclet.name = name;
}

function parseBorrows(doclet, tag) {
var m = /^(\S+)(?:\s+as\s+(\S+))?$/.exec(tag.text);
if (m) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jsdoc",
"version": "3.0.0alpha1",
"revision": "2011-01-08-2149",
"revision": "2011-01-13-0045",
"description": "An automatic documentation generator for javascript.",
"keywords": [ "documentation", "javascript" ],
"licenses": [
Expand Down
13 changes: 13 additions & 0 deletions test/cases/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var myObject = (function() {

/** Give x another name.
@alias myObject
@namespace
*/
var x = {
/** document me */
myProperty: 'foo'
}

return x;
})();
5 changes: 5 additions & 0 deletions test/cases/modules/data/mod-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @module */
define({
property: "foo",
method: function() {}
});
5 changes: 5 additions & 0 deletions test/cases/modules/data/mod-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @module my/module/name */
define({
property: "foo",
method: function() {}
});
21 changes: 21 additions & 0 deletions test/cases/modules/data/mod-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
My test module.
@module my/module
*/
define(function() {

/**
@undocumented
@alias module:my/module
*/
var mod = {

/** Document a property. */
myProperty: "foo",

/** Document a method. */
myMethod: function() {}
};

return mod;
});
5 changes: 5 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,10 @@ testFile('test/t/cases/var.js');

testFile('test/t/cases/inner.js');

testFile('test/t/cases/modules/data/mod-1.js');
testFile('test/t/cases/modules/data/mod-2.js');

testFile('test/t/cases/alias.js');

report();

20 changes: 20 additions & 0 deletions test/t/cases/alias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
var docSet = testhelpers.getDocSetFromFile('test/cases/alias.js'),
found = docSet.getByLongname('myObject').filter(function($) {
return ! $.undocumented;
}),

foundMember = docSet.getByLongname('myObject.myProperty')

//dump(found);

test('When a symbol is given an alias it is documented as if the name is the alias value.', function() {
assert.equal(found[0].longname, 'myObject');
});

test('When a symbol is a member of an alias it is documented as if the memberof is the alias value.', function() {
assert.equal(foundMember[0].longname, 'myObject.myProperty');
assert.equal(foundMember[0].memberof, 'myObject');
});

})();
18 changes: 18 additions & 0 deletions test/t/cases/modules/data/mod-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
var srcParser = require('jsdoc/src/parser'),
doclets;

env.opts._ = [BASEDIR + 'test/cases/modules/'];

app.jsdoc.parser = new srcParser.Parser();

require('jsdoc/src/handlers').attachTo(app.jsdoc.parser);

doclets = app.jsdoc.parser.parse(BASEDIR + 'test/cases/modules/data/mod-1.js')

test('When a module has no name documented, the name comes from the file path.', function() {
assert.ok(doclets.length > 1);
assert.equal(doclets[0].name, 'module:data/mod-1');
});

})();
18 changes: 18 additions & 0 deletions test/t/cases/modules/data/mod-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
var srcParser = require('jsdoc/src/parser'),
doclets;

env.opts._ = [BASEDIR + 'test/cases/modules/'];

app.jsdoc.parser = new srcParser.Parser();

require('jsdoc/src/handlers').attachTo(app.jsdoc.parser);

doclets = app.jsdoc.parser.parse(BASEDIR + 'test/cases/modules/data/mod-2.js')

test('When a module has a name documented, that name is used.', function() {
assert.ok(doclets.length > 1);
assert.equal(doclets[0].name, 'module:my/module/name');
});

})();
18 changes: 18 additions & 0 deletions test/t/cases/modules/data/mod-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
var srcParser = require('jsdoc/src/parser'),
doclets;

env.opts._ = [BASEDIR + 'test/cases/modules/'];

app.jsdoc.parser = new srcParser.Parser();

require('jsdoc/src/handlers').attachTo(app.jsdoc.parser);

doclets = app.jsdoc.parser.parse(BASEDIR + 'test/cases/modules/data/mod-2.js')

test('When a module has a name documented, that name is used.', function() {
assert.ok(doclets.length > 1);
assert.equal(doclets[0].name, 'module:my/module/name');
});

})();

0 comments on commit 70d9bb2

Please sign in to comment.