jsdoc-aliases.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*jshint node:true*/
  2. 'use strict';
  3. function createAlias(doclet, alias) {
  4. var clone = {};
  5. Object.keys(doclet).forEach(function(key) {
  6. clone[key] = doclet[key];
  7. });
  8. if (alias.indexOf('#') !== -1) {
  9. clone.longname = alias;
  10. clone.memberof = alias.split('#')[0];
  11. clone.name = alias.split('#')[1];
  12. } else {
  13. clone.longname = clone.memberof + '#' + alias;
  14. clone.name = alias;
  15. }
  16. delete clone.returns;
  17. delete clone.examples;
  18. delete clone.meta;
  19. delete clone.aliases;
  20. clone.isAlias = true;
  21. clone.description = 'Alias for <a href="#' + doclet.name + '">' + doclet.longname + '</a>';
  22. return clone;
  23. }
  24. exports.handlers = {
  25. parseComplete: function(e) {
  26. var doclets = e.doclets.slice();
  27. doclets.forEach(function(doclet) {
  28. // Duplicate doclets with aliases
  29. if (doclet.aliases) {
  30. doclet.aliases.forEach(function(alias) {
  31. e.doclets.push(createAlias(doclet, alias));
  32. });
  33. }
  34. });
  35. }
  36. };
  37. exports.defineTags = function(dict) {
  38. dict.defineTag('aliases', {
  39. onTagged: function(doclet, tag) {
  40. doclet.aliases = tag.text.split(',');
  41. }
  42. });
  43. dict.defineTag('category', {
  44. onTagged: function(doclet, tag) {
  45. doclet.category = tag.text;
  46. }
  47. });
  48. };