forked from lit/lit-element-starter-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.11ty.cjs
85 lines (82 loc) · 2.21 KB
/
api.11ty.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* This page generates its content from the custom-element.json file as read by
* the _data/api.11tydata.js script.
*/
module.exports = class Docs {
data() {
return {
layout: 'page.11ty.cjs',
title: '<my-element> ⌲ Docs',
};
}
render(data) {
const customElements = data.api['11tydata'].customElements;
const tags = customElements.tags;
return `
<h1>API</h1>
${tags.map((tag) => `
<h2><${tag.name}></h2>
<div>
${tag.description}
</div>
${renderTable(
'Attributes',
['name', 'description', 'type', 'default'],
tag.attributes)}
${renderTable(
'Properties',
['name', 'attribute', 'description', 'type', 'default'],
tag.properties)}
${/*
* Methods are not output by web-component-analyzer yet (a bug), so
* this is a placeholder so that at least _something_ will be output
* when that is fixed, and element maintainers will hopefully have a
* signal to update this file to add the neccessary columns.
*/
renderTable(
'Methods',
['name', 'description'],
tag.methods)}
${renderTable(
'Events',
['name', 'description'],
tag.events)}
${renderTable(
'Slots',
['name', 'description'],
tag.slots)}
${renderTable(
'CSS Shadow Parts',
['name', 'description'],
tag.cssParts)}
${renderTable(
'CSS Custom Properties',
['name', 'description'],
tag.cssProperties)}
`).join('')}
`;
}
}
/**
* Renders a table of data, plucking the given properties from each item in
* `data`.
*/
const renderTable = (name, properties, data) => {
if (data === undefined) {
return ''
}
return `
<h3>${name}</h3>
<table>
<tr>
${properties.map((p) => `<th>${capitalize(p)}</th>`).join('')}
</tr>
${data.map((i) => `
<tr>
${properties.map((p) => `<td>${i[p]}</td>`).join('')}
</tr>
`).join('')}
</table>
`
};
const capitalize = (s) => s[0].toUpperCase() + s.substring(1);