Added support for @property tags in doclets that have kinds, no template output yet.

This commit is contained in:
Michael Mathews 2011-09-24 21:26:09 +01:00
parent dbc9c428a6
commit f37bd95c6c
4 changed files with 78 additions and 11 deletions

View File

@ -179,3 +179,45 @@ exports.shorten = function(longname) {
return {longname: longname, memberof: memberof, scope: scope, name: name, variation: variation};
}
/**
Split a string that starts with a name and ends with a description, into its parts.
@param {string} nameDesc
@returns {object} Hash with "name" and "description" properties.
*/
exports.splitName = function(nameDesc) {
var name = '',
desc = '',
thisChar = '',
inQuote = false;
for (var i = 0, len = nameDesc.length; i < len; i++) {
thisChar = nameDesc.charAt(i);
if (thisChar === '\\') {
name += thisChar + nameDesc.charAt(++i);
continue;
}
if (thisChar === '"') {
inQuote = !inQuote;
}
if (inQuote) {
name += thisChar;
continue;
}
if (!inQuote) {
if ( /\s/.test(thisChar) ) {
desc = nameDesc.substr(i);
desc = desc.replace(/^[\s-\s]+/, '').trim();
break;
}
else {
name += thisChar;
}
}
}
return { name: name, description: desc };
}

View File

@ -10,7 +10,7 @@ var currentModule = null;
@param parser
*/
exports.attachTo = function(parser) {
var jsdoc = {doclet: require('jsdoc/doclet')};
var jsdoc = {doclet: require('jsdoc/doclet'), name: require('jsdoc/name')};
// handles JSDoc comments that include a @name tag -- the code is ignored in such a case
parser.on('jsdocCommentFound', function(e) {
@ -40,11 +40,11 @@ exports.attachTo = function(parser) {
var newDoclet = new jsdoc.doclet.Doclet(docletSrc, e);
// an undocumented symbol right after a virtual comment? rhino mistakenly connected the two
if (newDoclet.name) { // there was a @name in comment
// try again, without the comment
e.comment = '@undocumented';
newDoclet = new jsdoc.doclet.Doclet(e.comment, e);
}
if (newDoclet.name) { // there was a @name in comment
// try again, without the comment
e.comment = '@undocumented';
newDoclet = new jsdoc.doclet.Doclet(e.comment, e);
}
if (newDoclet.alias) {
if (newDoclet.alias === '{@thisClass}') {
@ -117,6 +117,17 @@ exports.attachTo = function(parser) {
return false;
}
// find name and description from each property tag text
if (newDoclet.properties) {
for (var i = 0, len = newDoclet.properties.length; i < len; i++) {
var property = newDoclet.properties[i];
var parts = jsdoc.name.splitName(property.description);
property.name = parts.name;
property.description = parts.description;
}
}
addDoclet.call(this, newDoclet);
e.doclet = newDoclet;
}

View File

@ -352,10 +352,16 @@ exports.defineTags = function(dictionary) {
dictionary.defineTag('property', {
canHaveType: true,
onTagged: function(doclet, tag) {
setDocletKindToTitle(doclet, tag);
setDocletNameToValue(doclet, tag);
if (tag.value && tag.value.type) {
doclet.type = tag.value.type;
if (doclet.kind) {
if (!doclet.properties) { doclet.properties = []; }
doclet.properties.push(tag.value);
}
else {
setDocletKindToTitle(doclet, tag);
setDocletNameToValue(doclet, tag);
if (tag.value && tag.value.type) {
doclet.type = tag.value.type;
}
}
}
})
@ -400,7 +406,7 @@ exports.defineTags = function(dictionary) {
mustHaveValue: true,
canHaveType: true,
onTagged: function(doclet, tag) {
if (!doclet.returns) { doclet.returns = []; }
if (!doclet.returns) { doclet.returns = []; }
doclet.returns.push(tag.value);
}
})

View File

@ -117,3 +117,11 @@ test('The module:jsdoc/name.shorten function finds the variation.', function() {
assert.equal(parts.name, 'fadein');
assert.equal(parts.longname, 'anim.fadein(2)');
});
test('The module:jsdoc/name.splitName function finds the name and description.', function() {
var startName = 'ns.Page#"last \\"sentence\\"".words~sort(2) - This is a description. ',
parts = jsdoc.name.splitName(startName);
assert.equal(parts.name, 'ns.Page#"last \\"sentence\\"".words~sort(2)');
assert.equal(parts.description, 'This is a description.');
});