params.tmpl 3.2 KB

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