Skip to content

Commit

Permalink
feat(app): Support for @link from JSDoc
Browse files Browse the repository at this point in the history
fix #92
  • Loading branch information
vogloblinsky committed Jan 25, 2017
1 parent 8fbb292 commit f05b7e7
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 233 deletions.
15 changes: 13 additions & 2 deletions README.md
Expand Up @@ -31,7 +31,7 @@

* **A local tool** - No server needed, no sources uploaded online

* **JSDoc light support** - Support of @param & @returns tags
* **JSDoc light support** - Support of @param, @returns, @link and @example tags

* **Documentation coverage** - Get the documentation coverage report of your project

Expand Down Expand Up @@ -67,8 +67,9 @@ Because we doesn't find our needs on existing tools. We want to have a single pl
# Who's using Compodoc ?

- [angular-seed](https://github.com/mgechev/angular-seed)
- [angular-calendar](https://github.com/mattlewis92/angular-calendar)

These are some that we know of. Want your project listed here ? Drop us a line.
These are some that [we know of](https://github.com/search?q=compodoc+filename%3Apackage.json+-user%3Acompodoc&ref=searchresults&type=Code&utf8=%E2%9C%93). Want your project listed here ? Drop us a line.

# Table of Contents

Expand Down Expand Up @@ -290,6 +291,16 @@ Currently Compodoc only support these JSDoc tags :
function processTarget(target:string):number;
```

For @link you can use this three syntax like JSDoc:

- for an internal reference

```{@link Todo} or [Todo]{@link Todo} or {@link Todo|TodoClass}```

- for an external link

```[Google]{@link http://www.google.com} & {@link http://www.apple.com|Apple} & {@link https://github.com GitHub}```

## Remark for routes

Follow the style guide and provide a const of type 'Routes' :
Expand Down
5 changes: 5 additions & 0 deletions src/app/engines/dependencies.engine.ts
Expand Up @@ -61,6 +61,11 @@ class DependenciesEngine {
return resultInAngularAPIs
}
}
findInCompodoc(name: string) {
let mergedData = _.concat([], this.modules, this.components, this.directives, this.injectables, this.interfaces, this.pipes, this.classes),
result = _.find(mergedData, {'name': name});
return result || false;
}
getModules() {
return this.modules;
}
Expand Down
65 changes: 65 additions & 0 deletions src/app/engines/html.engine.ts
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import * as Handlebars from 'handlebars';
//import * as helpers from 'handlebars-helpers';
import { $dependenciesEngine } from './dependencies.engine';
import { extractLeadingText, splitLinkText } from '../../utils/link-parser';

export class HtmlEngine {
cache: Object = {};
Expand Down Expand Up @@ -111,6 +112,70 @@ export class HtmlEngine {
}
return _kindText;
});
/**
* Convert {@link MyClass} to [MyClass](http://localhost:8080/classes/MyClass.html)
*/
Handlebars.registerHelper('parseDescription', function(description) {
let tagRegExp = new RegExp('\\{@link\\s+((?:.|\n)+?)\\}', 'i'),
matches,
previousString,
tagInfo = []

var processTheLink = function(string, tagInfo) {
var leading = extractLeadingText(string, tagInfo.completeTag),
split,
result,
newLink,
stringtoReplace;

split = splitLinkText(tagInfo.text);

if (typeof split.linkText !== 'undefined') {
result = $dependenciesEngine.findInCompodoc(split.target);
} else {
result = $dependenciesEngine.findInCompodoc(tagInfo.text);
}

if (result) {
if (leading.leadingText !== null) {
stringtoReplace = '[' + leading.leadingText + ']' + tagInfo.completeTag;
} else if (typeof split.linkText !== 'undefined') {
stringtoReplace = tagInfo.completeTag;
} else {
stringtoReplace = tagInfo.completeTag;
}

if (result.type === 'class') result.type = 'classe';

newLink = `<a href="./${result.type}s/${result.name}.html" >${result.name}</a>`;
return string.replace(stringtoReplace, newLink);
} else {
return string;
}
}

function replaceMatch(replacer, tag, match, text) {
var matchedTag = {
completeTag: match,
tag: tag,
text: text
};
tagInfo.push(matchedTag);

return replacer(description, matchedTag);
}

do {
matches = tagRegExp.exec(description);
if (matches) {
previousString = description;
description = replaceMatch(processTheLink, 'link', matches[0], matches[1]);
}
} while (matches && previousString !== description);

return description;
});

Handlebars.registerHelper('functionSignature', function(method) {
const args = method.args.map(function(arg) {
var _result = $dependenciesEngine.find(arg.type);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/block-method.hbs
Expand Up @@ -22,7 +22,7 @@
<tr>
<td class="col-md-4">
{{#if description}}
<div class="io-description">{{{description}}}</div>
<div class="io-description">{{{parseDescription description}}}</div>
{{/if}}
{{#if jsdoctags}}
<div class="io-description">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/block-property.hbs
Expand Up @@ -23,7 +23,7 @@
{{#if description}}
<tr>
<td class="col-md-4">
<div class="io-description">{{{description}}}</div>
<div class="io-description">{{{parseDescription description}}}</div>
</td>
</tr>
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/class.hbs
Expand Up @@ -28,7 +28,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ class.description}}}
{{{parseDescription class.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/component-detail.hbs
Expand Up @@ -10,7 +10,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ component.description}}}
{{{parseDescription component.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/directive.hbs
Expand Up @@ -28,7 +28,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ directive.description}}}
{{{parseDescription directive.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/injectable.hbs
Expand Up @@ -28,7 +28,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ injectable.description}}}
{{{parseDescription injectable.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/interface.hbs
Expand Up @@ -28,7 +28,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ interface.description}}}
{{{parseDescription interface.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/module.hbs
Expand Up @@ -43,7 +43,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{ module.description}}}
{{{parseDescription module.description}}}
</p>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/partials/pipe.hbs
Expand Up @@ -28,7 +28,7 @@
<h3>Description</h3>
</p>
<p class="comment">
{{{pipe.description}}}
{{{parseDescription pipe.description}}}
</p>
{{/if}}
{{#unless disableSourceCode}}
Expand Down

0 comments on commit f05b7e7

Please sign in to comment.