Skip to content

Commit 3e11986

Browse files
authored
Feature: Add property table for members (#165)
1 parent 1e5c4dd commit 3e11986

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

packages/webdoc-default-template/tmpl/components/member/index.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const source = doc.loc && doc.loc.file && doc.loc.file.path
1212
const sourceName = source && require("path").basename(doc.loc.file.path);
1313
const sourceStart = source && doc.loc.start ? ":" + doc.loc.start.line : "";
1414
const sourceLinkFragment = source && doc.loc.start ? "#" + doc.loc.start.line : "";
15+
const properties = doc.members.filter(child => child.type === "PropertyDoc");
1516

1617
const modifiers = [
1718
doc.deprecated ? "member__title_deprecated" : ""
@@ -54,6 +55,10 @@ const modifiers = [
5455
<div class="member__brief"><?js= doc.brief ?></div>
5556
<div class="member__description"><?js= doc.description ?></div>
5657

58+
<?js if (properties.length) { ?>
59+
<?js= this.partial("components/member/properties.tmpl", properties) ?>
60+
<?js } ?>
61+
5762
<?js if (doc.params && doc.params.length) { ?>
5863
<?js= this.partial("components/member/params.tmpl", doc.params) ?>
5964
<?js } ?>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?js
2+
const properties = obj;
3+
4+
let hasAttributes = false;
5+
let hasType = false;
6+
let hasDefaultValue = false;
7+
let hasDataValue = false;
8+
9+
for (const property of properties) {
10+
if (!property) continue;
11+
12+
hasAttributes = hasAttributes
13+
|| property.constant
14+
|| property.optional
15+
|| property.readonly;
16+
hasDefaultValue = hasDefaultValue || !!property.defaultValue;
17+
hasDataValue = hasDataValue || !!property.dataValue;
18+
}
19+
?>
20+
<div class="table-wrapper">
21+
<table class="member-properties">
22+
<caption class="member-properties__caption">Properties:</caption>
23+
<thead class="member-properties__head">
24+
<th class="member-property-header__name">Name</th>
25+
<th class="member-property-header__type">Type</th>
26+
<?js if (hasAttributes) {?><th class="member-property-header__name">Attributes</th><?js } ?>
27+
<?js if (hasDefaultValue) {?><th class="member-property-header__default">Default</th><?js } ?>
28+
<?js if (hasDataValue) {?><th class="member-property-header__default">Value</th><?js } ?>
29+
<th class="member-property-header__description">Description</th>
30+
</thead>
31+
<tbody class="member-properties__body">
32+
<?js properties.forEach((property) => { if (!property) { return; } ?><tr class="member-property">
33+
<td class="member-property__name">
34+
<?js= property.name ?>
35+
</td>
36+
<td class="member-property__type">
37+
<?js if (property.dataType) {?><?js= this.linkTo(property.dataType) ?><?js } ?>
38+
</td>
39+
<?js if (hasAttributes) {?><td class="member-property__attributes">
40+
<?js if (property.optional) { ?><p>&lt;optional&gt;</p><?js } ?>
41+
<?js if (property.constant) { ?><p>&lt;constant&gt;</p><?js } ?>
42+
<?js if (property.readonly) { ?><p>&lt;readonly&gt;</p><?js } ?>
43+
</td><?js } ?>
44+
<?js if (hasDefaultValue) {?><td class="member-property__default">
45+
<?js if (typeof property.defaultValue !== 'undefined') { ?><?js= this.htmlText(property.defaultValue) ?><?js } ?>
46+
</td><?js } ?>
47+
<td class="member-property__description"><?js= property.description ?></td>
48+
</tr><?js }); ?>
49+
</tbody>
50+
</table>
51+
</div>

0 commit comments

Comments
 (0)