template.md.ejs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?
  2. function anchorify(str)
  3. {
  4. // how github creates the name attribute for anchors from headlines
  5. str = str.replace(/[()<>.]/g, "");
  6. str = str.replace(/[^a-z0-9_-]+/gi, "-");
  7. str = str.toLowerCase();
  8. return str;
  9. }
  10. docfiles.forEach(function(doc)
  11. {
  12. doc.javadoc.forEach(function(comment)
  13. {
  14. var tags = comment.raw.tags;
  15. comment.tagsByType = comment.raw.tags.reduce(function(result, tag)
  16. {
  17. result[tag.type] = tag;
  18. return result;
  19. }, {});
  20. comment.ignore = "ignore" in comment.tagsByType;
  21. if(comment.name && !comment.ignore)
  22. {
  23. if(comment.isMethod || comment.isFunction)
  24. {
  25. var args = comment.paramTags.map(function(c)
  26. {
  27. return c.joinedTypes + " " + c.name;
  28. }).join(", ");
  29. var returnVal = "";
  30. if(comment.returnTags[0])
  31. {
  32. returnVal = " -> " + comment.returnTags[0].joinedTypes;
  33. }
  34. comment.args = args;
  35. comment.returnVal = returnVal;
  36. comment.longName = comment.name + "(" + comment.args + ")" + comment.returnVal;
  37. ?><?= "- [`" + comment.longName + "`](#" + anchorify(comment.longName) + ")\n" ?><?
  38. } else {
  39. ?># <?= comment.name + "\n" ?><?
  40. }
  41. }
  42. });
  43. doc.javadoc.forEach(function(comment)
  44. {
  45. if(!comment.ignore)
  46. {
  47. ?><?= "\n***\n" ?><?
  48. if(comment.name)
  49. {
  50. if(comment.isMethod || comment.isFunction)
  51. {
  52. ?><?= "#### `" + comment.longName + "`\n" ?><?
  53. }
  54. else
  55. {
  56. ?><?= "## `" + comment.name + "`\n" ?><?
  57. }
  58. }
  59. if(comment.deprecated)
  60. {
  61. ?><?= "\n\n**Deprecated - Might be removed in a later release.**\n\n" ?><?
  62. }
  63. ?><?= comment.description + "\n" ?><?
  64. if(comment.paramTags.length)
  65. {
  66. ?><?= "**Parameters:**\n\n" ?><?
  67. comment.paramTags.forEach(function(paramTag, i)
  68. {
  69. ?><?= (i + 1) + ". **`" + paramTag.joinedTypes + "`** " + (paramTag.optional ? "(optional) " : "") + paramTag.name + " " + (paramTag.description ? "– " + paramTag.description : "") + "\n" ?><?
  70. });
  71. }
  72. if(comment.returnTags.length)
  73. {
  74. ?><?= "**Returns:**\n\n" ?><?
  75. comment.returnTags.forEach(function(returnTag)
  76. {
  77. ?><?= "* **`" + returnTag.joinedTypes + "`** " + returnTag.description + "\n" ?><?
  78. });
  79. }
  80. }
  81. });
  82. ?><?= "\n<!-- " + doc.filename + "-->\n" ?><?
  83. });
  84. ?>
  85. <!-- vim: set tabstop=2 shiftwidth=2 softtabstop=2: -->