properties.tmpl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?js
  2. var data = obj;
  3. var props = data.subprops || data.properties;
  4. /* sort subprops under their parent props (like opts.classname) */
  5. var parentProp = null;
  6. props.forEach(function(prop, i) {
  7. if (!prop) { return; }
  8. if ( parentProp && prop.name && prop.name.indexOf(parentProp.name + '.') === 0 ) {
  9. prop.name = prop.name.substr(parentProp.name.length+1);
  10. parentProp.subprops = parentProp.subprops || [];
  11. parentProp.subprops.push(prop);
  12. props[i] = null;
  13. }
  14. else {
  15. parentProp = prop;
  16. }
  17. });
  18. /* determine if we need extra columns, "attributes" and "default" */
  19. props.hasAttributes = false;
  20. props.hasDefault = false;
  21. props.hasName = false;
  22. props.forEach(function(prop) {
  23. if (!prop) { return; }
  24. if (prop.optional || prop.nullable) {
  25. props.hasAttributes = true;
  26. }
  27. if (prop.name) {
  28. props.hasName = true;
  29. }
  30. if (typeof prop.defaultvalue !== 'undefined' && !data.isEnum) {
  31. props.hasDefault = true;
  32. }
  33. });
  34. ?>
  35. <table class="props">
  36. <thead>
  37. <tr>
  38. <?js if (props.hasName) {?>
  39. <th>Name</th>
  40. <?js } ?>
  41. <th>Type</th>
  42. <?js if (props.hasAttributes) {?>
  43. <th>Attributes</th>
  44. <?js } ?>
  45. <?js if (props.hasDefault) {?>
  46. <th>Default</th>
  47. <?js } ?>
  48. <th class="last">Description</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. <?js
  53. var self = this;
  54. props.forEach(function(prop) {
  55. if (!prop) { return; }
  56. ?>
  57. <tr>
  58. <?js if (props.hasName) {?>
  59. <td class="name"><code><?js= prop.name ?></code></td>
  60. <?js } ?>
  61. <td class="type">
  62. <?js if (prop.type && prop.type.names) {?>
  63. <?js= self.partial('type.tmpl', prop.type.names) ?>
  64. <?js } ?>
  65. </td>
  66. <?js if (props.hasAttributes) {?>
  67. <td class="attributes">
  68. <?js if (prop.optional) { ?>
  69. &lt;optional><br>
  70. <?js } ?>
  71. <?js if (prop.nullable) { ?>
  72. &lt;nullable><br>
  73. <?js } ?>
  74. </td>
  75. <?js } ?>
  76. <?js if (props.hasDefault) {?>
  77. <td class="default">
  78. <?js if (typeof prop.defaultvalue !== 'undefined') { ?>
  79. <?js= self.htmlsafe(prop.defaultvalue) ?>
  80. <?js } ?>
  81. </td>
  82. <?js } ?>
  83. <td class="description last"><?js= prop.description ?><?js if (prop.subprops) { ?>
  84. <h6>Properties</h6><?js= self.partial('properties.tmpl', prop) ?>
  85. <?js } ?></td>
  86. </tr>
  87. <?js }); ?>
  88. </tbody>
  89. </table>