Skip to content

Commit

Permalink
Update to be on par with JSDoc features
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Feb 20, 2019
1 parent ea3582e commit a12fa91
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 6 deletions.
18 changes: 18 additions & 0 deletions fixtures/generators/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Generate numbers in the Fibonacci sequence.
*
* @generator
* @function fibonacci
* @yields {number} The next number in the Fibonacci sequence.
*/

function *fibonacci(n) {
const infinite = !n && n !== 0;
let current = 0;
let next = 1;

while (infinite || n--) {
yield current;
[current, next] = [next, current + next];
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docdash",
"version": "1.0.2",
"version": "1.0.3",
"description": "A clean, responsive documentation template theme for JSDoc 3 inspired by lodash and minami",
"main": "publish.js",
"scripts": {
Expand Down
15 changes: 11 additions & 4 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ function needsSignature(doclet) {
}
}
}
// and namespaces that are functions get a signature (but finding them is a
// bit messy)
else if (doclet.kind === 'namespace' && doclet.meta && doclet.meta.code &&
doclet.meta.code.type && doclet.meta.code.type.match(/[Ff]unction/)) {
needsSig = true;
}

return needsSig;
}
Expand Down Expand Up @@ -168,12 +174,13 @@ function addSignatureReturns(f) {
var attribsString = '';
var returnTypes = [];
var returnTypesString = '';
var source = f.yields || f.returns;

// jam all the return-type attributes into an array. this could create odd results (for example,
// if there are both nullable and non-nullable return types), but let's assume that most people
// who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
if (f.returns) {
f.returns.forEach(function(item) {
if (source) {
source.forEach(function(item) {
helper.getAttribs(item).forEach(function(attrib) {
if (attribs.indexOf(attrib) === -1) {
attribs.push(attrib);
Expand All @@ -184,8 +191,8 @@ function addSignatureReturns(f) {
attribsString = buildAttribsString(attribs);
}

if (f.returns) {
returnTypes = addNonParamAttributes(f.returns);
if (source) {
returnTypes = addNonParamAttributes(source);
}
if (returnTypes.length) {
returnTypesString = util.format( ' → %s{%s}', attribsString, returnTypes.join('|') );
Expand Down
12 changes: 12 additions & 0 deletions tmpl/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
<dd><?js if (c.summary) { ?><?js= c.summary ?><?js } ?></dd>
<?js }); ?></dl>
<?js } ?>

<?js
var interfaces = self.find({kind: 'interface', memberof: doc.longname});
if (!isGlobalPage && interfaces && interfaces.length) {
?>
<h3 class="subsection-title">Interfaces</h3>

<dl><?js interfaces.forEach(function(i) { ?>
<dt><?js= self.linkto(i.longname, i.name) ?></dt>
<dd><?js if (i.summary) { ?><?js= i.summary ?><?js } ?></dd>
<?js }); ?></dl>
<?js } ?>

<?js
var mixins = self.find({kind: 'mixin', memberof: doc.longname});
Expand Down
5 changes: 5 additions & 0 deletions tmpl/mainpage.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ var data = obj;
var self = this;
?>

<?js if (data.kind === 'package') { ?>
<section class="package">
<h3><?js= data.name ?> <?js= data.version ?></h3>
</section>
<?js } ?>
<?js if (data.readme) { ?>
<section class="readme">
<article><?js= data.readme ?></article>
Expand Down
23 changes: 23 additions & 0 deletions tmpl/method.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ var self = this;
<?js }); ?></ul>
<?js } ?>

<?js if (data.modifies && modifies.length) {?>
<h5>Modifies:</h5>
<?js if (modifies.length > 1) { ?><ul><?js
modifies.forEach(function(m) { ?>
<li><?js= self.partial('modifies.tmpl', m) ?></li>
<?js });
?></ul><?js } else {
modifies.forEach(function(m) { ?>
<?js= self.partial('modifies.tmpl', m) ?>
<?js });
} } ?>

<?js if (data.exceptions && exceptions.length) { ?>
<h5>Throws:</h5>
<?js if (exceptions.length > 1) { ?><ul><?js
Expand All @@ -111,3 +123,14 @@ var self = this;
<?js });
} } ?>

<?js if (data.yields && yields.length) { ?>
<h5>Yields:</h5>
<?js if (yields.length > 1) { ?><ul><?js
yields.forEach(function(r) { ?>
<li><?js= self.partial('returns.tmpl', r) ?></li>
<?js });
?></ul><?js } else {
yields.forEach(function(r) { ?>
<?js= self.partial('returns.tmpl', r) ?>
<?js });
} } ?>
14 changes: 14 additions & 0 deletions tmpl/modifies.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?js
var data = obj || {};
?>

<?js if (data.type && data.type.names) {?>
<dl>
<dt>
Type
</dt>
<dd>
<?js= this.partial('type.tmpl', data.type.names) ?>
</dd>
</dl>
<?js } ?>
9 changes: 8 additions & 1 deletion tmpl/params.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
}

if (parentParam && parentParam.name && param.name) {
paramRegExp = new RegExp('^(?:' + parentParam.name + '(?:\\[\\])*)\\.(.+)$');
try {
paramRegExp = new RegExp('^(?:' + parentParam.name + '(?:\\[\\])*)\\.(.+)$');
}
catch (e) {
// there's probably a typo in the JSDoc comment that resulted in a weird
// parameter name
return;
}

if ( paramRegExp.test(param.name) ) {
param.name = RegExp.$1;
Expand Down

0 comments on commit a12fa91

Please sign in to comment.