params.tmpl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. var paramRegExp;
  7. if (!param) {
  8. return;
  9. }
  10. if (parentParam && parentParam.name && param.name) {
  11. try {
  12. paramRegExp = new RegExp('^(?:' + parentParam.name + '(?:\\[\\])*)\\.(.+)$');
  13. }
  14. catch (e) {
  15. // there's probably a typo in the JSDoc comment that resulted in a weird
  16. // parameter name
  17. return;
  18. }
  19. if ( paramRegExp.test(param.name) ) {
  20. param.name = RegExp.$1;
  21. parentParam.subparams = parentParam.subparams || [];
  22. parentParam.subparams.push(param);
  23. params[i] = null;
  24. }
  25. else {
  26. parentParam = param;
  27. }
  28. }
  29. else {
  30. parentParam = param;
  31. }
  32. });
  33. /* determine if we need extra columns, "attributes" and "default" */
  34. params.hasAttributes = false;
  35. params.hasDefault = false;
  36. params.hasName = false;
  37. params.forEach(function(param) {
  38. if (!param) { return; }
  39. if (param.optional || param.nullable || param.variable) {
  40. params.hasAttributes = true;
  41. }
  42. if (param.name) {
  43. params.hasName = true;
  44. }
  45. if (typeof param.defaultvalue !== 'undefined') {
  46. params.hasDefault = true;
  47. }
  48. });
  49. ?>
  50. <table class="params">
  51. <thead>
  52. <tr>
  53. <?js if (params.hasName) {?>
  54. <th>Name</th>
  55. <?js } ?>
  56. <th>Type</th>
  57. <?js if (params.hasAttributes) {?>
  58. <th>Attributes</th>
  59. <?js } ?>
  60. <?js if (params.hasDefault) {?>
  61. <th>Default</th>
  62. <?js } ?>
  63. <th class="last">Description</th>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. <?js
  68. var self = this;
  69. params.forEach(function(param) {
  70. if (!param) { return; }
  71. ?>
  72. <tr>
  73. <?js if (params.hasName) {?>
  74. <td class="name"><code><?js= param.name ?></code></td>
  75. <?js } ?>
  76. <td class="type">
  77. <?js if (param.type && param.type.names) {?>
  78. <?js= self.partial('type.tmpl', param.type.names) ?>
  79. <?js } ?>
  80. </td>
  81. <?js if (params.hasAttributes) {?>
  82. <td class="attributes">
  83. <?js if (param.optional) { ?>
  84. &lt;optional><br>
  85. <?js } ?>
  86. <?js if (param.nullable) { ?>
  87. &lt;nullable><br>
  88. <?js } ?>
  89. <?js if (param.variable) { ?>
  90. &lt;repeatable><br>
  91. <?js } ?>
  92. </td>
  93. <?js } ?>
  94. <?js if (params.hasDefault) {?>
  95. <td class="default">
  96. <?js if (typeof param.defaultvalue !== 'undefined') { ?>
  97. <?js= self.htmlsafe(param.defaultvalue) ?>
  98. <?js } ?>
  99. </td>
  100. <?js } ?>
  101. <td class="description last"><?js= param.description ?><?js if (param.subparams) { ?>
  102. <h6>Properties</h6>
  103. <?js= self.partial('params.tmpl', param.subparams) ?>
  104. <?js } ?></td>
  105. </tr>
  106. <?js }); ?>
  107. </tbody>
  108. </table>