params.tmpl 3.0 KB

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