Skip to content

Commit 181ed67

Browse files
committed
feat(api): Add enum template
1 parent 5213c59 commit 181ed67

14 files changed

+148
-31
lines changed

compiler/api/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const nestjs = new Package('nestjs', [
2323
.processor(require('./processors/processClassLikeMembers'))
2424
.processor(require('./processors/filterContainedDocs'))
2525
.processor(require('./processors/markPrivateDocs'))
26+
.processor(require('./processors/shortDescription'))
2627
.processor(require('./processors/test'))
2728

2829
.config(function(readTypeScriptModules, tsParser) {
@@ -67,10 +68,7 @@ const nestjs = new Package('nestjs', [
6768
templateEngine.filters.concat(getInjectables(requireFolder(__dirname, './rendering')));
6869

6970
// helpers are made available to the nunjucks templates
70-
renderDocsProcessor.helpers.relativePath = function(from, to) {
71-
return relative(from, to);
72-
};
73-
71+
renderDocsProcessor.helpers.relativePath = (from: string, to: string) => relative(from, to);
7472
});
7573

7674
new Dgeni([nestjs]).generate();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Split the description (of selected docs) into:
3+
*`shortDescription`: the first paragraph
4+
*`description`: the rest of the paragraphs
5+
*/
6+
module.exports = function splitDescription() {
7+
return {
8+
$runAfter: ['tags-extracted'],
9+
$runBefore: ['processing-docs'],
10+
$process(docs) {
11+
docs.forEach(doc => {
12+
if (
13+
doc.description !== undefined
14+
) {
15+
const description = doc.description.trim();
16+
const endOfParagraph = description.search(/\n\s*\n/);
17+
if (endOfParagraph === -1) {
18+
doc.shortDescription = description;
19+
doc.description = '';
20+
} else {
21+
doc.shortDescription = description.substr(0, endOfParagraph).trim();
22+
doc.description = description.substr(endOfParagraph).trim();
23+
}
24+
}
25+
});
26+
}
27+
};
28+
};

compiler/api/processors/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function test() {
44
$runAfter: ['processClassLikeMembers'],
55
$runBefore: ['renderDocsProcessor'],
66
$process(docs: any[]) {
7-
console.log(docs.find(doc => doc.docType === 'class').methods[0]);
7+
// console.log(docs.find(doc => doc.docType === 'class').methods[0]);
88
}
99
};
1010
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>{$ doc.name $}</h1>
2+
<label class="api-type-label {$ doc.docType $}">{$ doc.docType $}</label>
3+
{% block body %}{% endblock %}
+9-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
{% import "lib/memberHelpers.html" as memberHelper -%}
2-
3-
<h1>{$ doc.name $}</h1>
4-
<p>{$ doc.tags.description $} </p>
5-
6-
<pre class="language-typescript">
7-
<code class="language-typescript">
8-
{% if doc.isAbstract %}abstract {% endif%}class {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHeritage(doc) $} {{$ memberHelper.renderMembers(doc) $}
9-
}
10-
</code>
11-
</pre>
12-
13-
{$ memberHelper.renderProperties(doc.properties, 'instance-properties', 'instance-property', 'Properties') $}
14-
15-
{$ memberHelper.renderMethodDetails(versionInfo, doc.methods, 'instance-methods', 'instance-method', 'Methods') $}
1+
{% extends 'export-base.template.html' -%}
2+
3+
{% block overview %}
4+
{% include "includes/class-overview.html" %}
5+
{% endblock %}
6+
{% block details %}
7+
{% include "includes/description.html" %}
8+
{% include "includes/class-members.html" %}
9+
{% endblock %}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% import "lib/memberHelpers.html" as memberHelpers -%}
2+
{% extends 'export-base.template.html' -%}
3+
4+
{% block details %}
5+
<pre class="language-typescript">
6+
<code class="language-typescript">
7+
enum {$ doc.name $} {{$ memberHelpers.renderMembers(doc) $}
8+
}
9+
</code>
10+
</pre>
11+
12+
{% include "includes/description.html" %}
13+
{$ memberHelpers.renderProperties(doc.properties, 'members', 'member', 'Members', ['Member']) $}
14+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends 'base.template.html' -%}
2+
3+
{% block body %}
4+
<section class="short-description">
5+
{$ doc.shortDescription | marked $}
6+
{% if doc.description %}<p><a href="#description">See more...</a></p>{% endif %}
7+
</section>
8+
{% block overview %}{% endblock %}
9+
{% block details %}{% endblock %}
10+
{% block endNotes %}{% include "includes/usageNotes.html" %}{% endblock %}
11+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% import "lib/memberHelpers.html" as memberHelper -%}
2+
{% import "lib/descendants.html" as descendants -%}
3+
4+
5+
<pre class="language-typescript">
6+
<code class="language-typescript">
7+
{% if doc.isAbstract %}abstract {% endif%}class {$ doc.name $}{$ doc.typeParams | escape $}{$ memberHelper.renderHeritage(doc) $} {{$ memberHelper.renderMembers(doc) $}
8+
}
9+
</code>
10+
</pre>
11+
12+
{$ descendants.renderDescendants(doc, 'class', 'Subclasses', true, r/class|directive|pipe|decorator/) $}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% if doc.description %}
2+
<section class="description">
3+
<h2>Description</h2>
4+
{$ doc.description | trimBlankLines | marked $}
5+
</section>
6+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{%- if doc.see AND doc.see.length %}
2+
<section class="see-also">
3+
<h2>See also</h2>
4+
<ul>
5+
{% for see in doc.see %}
6+
<li>{$ see | marked $}</li>{% endfor %}
7+
</ul>
8+
</section>
9+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% if doc.usageNotes %}
2+
<section class="usage-notes">
3+
<h2>Usage notes</h2>
4+
{$ doc.usageNotes | marked $}
5+
</section>
6+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% macro renderDescendantList(descendants, descendantType, recursed, docTypeMatcher) %}
2+
{% if descendants.length %}
3+
<ul>
4+
{% for descendant in descendants %}
5+
<li>
6+
<code>{$ descendant.name $}</code>
7+
{$ renderDescendantList(descendant.descendants | filterByPropertyValue('docType', docTypeMatcher), docType, recursed, docTypeMatcher) $}
8+
</li>
9+
{% endfor %}
10+
</ul>
11+
{% endif %}
12+
{% endmacro -%}
13+
14+
{%- macro renderDescendants(doc, descendantType, title='', recursed=true, docTypeMatcher=descendantType) %}
15+
{% set descendants = doc.descendants | filterByPropertyValue('docType', docTypeMatcher) | filterByPropertyValue('privateExport', undefined) %}
16+
{% if descendants.length %}
17+
<div class="descendants {$ descendantType $}">
18+
{% if title %}<h2>{$ title $}</h2>{% endif %}
19+
{$ renderDescendantList(descendants, descendantType, recursed, docTypeMatcher) $}
20+
</div>
21+
{% endif %}
22+
{% endmacro %}

src/app/homepage/api/api.component.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1-
import { Component, ElementRef, ViewChild, OnInit } from '@angular/core';
1+
import {
2+
Component,
3+
ElementRef,
4+
ViewChild,
5+
OnInit,
6+
ViewEncapsulation,
7+
ApplicationRef
8+
} from '@angular/core';
29
import { Location } from '@angular/common';
310
import { ApiService } from './api.service';
4-
import { tap } from 'rxjs/operators';
11+
import { BasePageComponent } from '../pages/page/page.component';
512

613
@Component({
714
templateUrl: './api.component.html',
8-
styleUrls: ['./api.component.scss']
15+
styleUrls: ['./api.component.scss'],
16+
encapsulation: ViewEncapsulation.None
917
})
10-
export class ApiComponent implements OnInit {
18+
export class ApiComponent extends BasePageComponent implements OnInit {
1119
@ViewChild('content') contentRef: ElementRef<HTMLDivElement>;
1220
isDetailPage = false;
1321

14-
constructor(private location: Location, private api: ApiService) {}
22+
constructor(
23+
private location: Location,
24+
private api: ApiService,
25+
applicationRef: ApplicationRef,
26+
el: ElementRef
27+
) {
28+
super(applicationRef, el);
29+
}
1530

1631
private loadContent(path) {
1732
if (path === '/api' || path === '/api/') {
1833
this.isDetailPage = false;
1934
} else {
2035
this.isDetailPage = true;
21-
this.api
22-
.getDocument(path)
23-
.subscribe(
24-
content => (this.contentRef.nativeElement.innerHTML = content)
25-
);
36+
this.api.getDocument(path).subscribe(content => {
37+
this.contentRef.nativeElement.innerHTML = content;
38+
super.initHljs();
39+
});
2640
}
2741
}
2842
ngOnInit() {

src/app/homepage/pages/page/page.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class BasePageComponent implements AfterViewChecked {
3030
this.initHljs();
3131
}
3232

33-
private initHljs() {
33+
protected initHljs() {
3434
if (this.isHljsInitialized) {
3535
return;
3636
}

0 commit comments

Comments
 (0)