api.11ty.cjs 2.3 KB

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