Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

optional description of @param and @returns #167

Merged
merged 1 commit into from
Jun 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Doc.prototype = {
this.shortName = this.name.split(".").pop().trim();
}
}

this.id = this.id || // if we have an id just use it
(this.ngdoc === 'error' ? this.name : '') ||
(((this.file||'').match(/.*(\/|\\)([^(\/|\\)]*)\.ngdoc/)||{})[2]) || // try to extract it from file name
Expand All @@ -409,16 +409,16 @@ Doc.prototype = {
self.moduleName = match[1];
}
} else if (atName == 'param') {
match = text.match(/^\{([^}]+)\}\s+(([^\s=]+)|\[(\S+)=([^\]]+)\])\s+(.*)/);
// 1 1 23 3 4 4 5 5 2 6 6
match = text.match(/^\{([^}]+)}\s+(([^\s=]+)|\[(\S+)=([^\]]+)])(?:\s+(.*)|$)/);
// 1 1 23 3 4 4 5 5 2 6 6
if (!match) {
throw new Error("Not a valid 'param' format: " + text + ' (found in: ' + self.file + ':' + self.line + ')');
}

var optional = (match[1].slice(-1) === '=');
var param = {
name: match[4] || match[3],
description:self.markdown(text.replace(match[0], match[6])),
description: match[6] ? self.markdown(text.replace(match[0], match[6])) : '',
type: optional ? match[1].substring(0, match[1].length-1) : match[1],
optional: optional,
default: match[5]
Expand All @@ -440,13 +440,13 @@ Doc.prototype = {
self.param.push(param);
}
} else if (atName == 'returns' || atName == 'return') {
match = text.match(/^\{([^}]+)\}\s+(.*)/);
match = text.match(/^\{([^}]+)}(?:\s+(.*)|$)/);
if (!match) {
throw new Error("Not a valid 'returns' format: " + text + ' (found in: ' + self.file + ':' + self.line + ')');
}
self.returns = {
type: match[1],
description: self.markdown(text.replace(match[0], match[2]))
description: match[2] ? self.markdown(text.replace(match[0], match[2])) : ''
};
} else if(atName == 'requires') {
match = text.match(/^([^\s]*)\s*([\S\s]*)/);
Expand Down Expand Up @@ -609,6 +609,7 @@ Doc.prototype = {

dom.html('</td>');
dom.html('<td>');

dom.html(param.description);
if (param.default) {
dom.html(' <p><em>(default: ' + param.default + ')</em></p>');
Expand Down