/branches/version1.x/app/Doclet.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 65 lines · 27 code · 7 blank · 31 comment · 9 complexity · 1a3a3c8097ee15af10ddb4fcac8e75be MD5 · raw file

  1. /**
  2. * @fileOverview
  3. * @name Doclet
  4. * @author Michael Mathews micmath@gmail.com
  5. * @url $HeadURL: http://jsdoc-toolkit.googlecode.com/svn/branches/version1.x/app/Doclet.js $
  6. * @revision $Id: Doclet.js 405 2007-12-28 23:39:50Z micmath $
  7. * @license <a href="http://en.wikipedia.org/wiki/MIT_License">X11/MIT License</a>
  8. * (See the accompanying README file for full details.)
  9. */
  10. /**
  11. * @class Represents a collection of DocTags.
  12. * @constructor
  13. * @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
  14. * @param {string} comment The entire documentation comment. The openening slash-star-star and
  15. * closing star-slash are optional. An untagged string at the start automatically gets a "desc" tag.
  16. */
  17. function Doclet(comment) {
  18. var src = Doclet.unwrapComment(comment);
  19. var tagTexts = src.split(/(^|[\r\f\n])\s*@/);
  20. this.tags =
  21. tagTexts.filter(function(el){return el.match(/^\w/)})
  22. .map(function(el){return new DocTag(el)});
  23. var paramParent = "config"; // default
  24. for(var i = 0; i < this.tags.length; i++) {
  25. if (this.tags[i].title == "param") paramParent = this.tags[i].name;
  26. if (this.tags[i].title == "config") {
  27. this.tags[i].name = paramParent+"."+this.tags[i].name;
  28. this.tags[i].title = "param"
  29. }
  30. }
  31. }
  32. /**
  33. * Remove the slashes and stars from a doc comment.
  34. * @static
  35. * @memberOf Doclet
  36. */
  37. Doclet.unwrapComment = function(comment) {
  38. if (!comment) comment = "/** @desc undocumented */";
  39. var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
  40. if (unwrapped.match(/^\s*[^@#\s]/)) unwrapped = "@desc "+unwrapped;
  41. return unwrapped;
  42. }
  43. /**
  44. * Get every DocTag with the given title.
  45. * @param {string} tagTitle
  46. * @return {DocTag[]}
  47. */
  48. Doclet.prototype.getTag = function(tagTitle) {
  49. return this.tags.filter(function(el){return el.title == tagTitle});
  50. }
  51. /**
  52. * Remove from this Doclet every DocTag with the given title.
  53. * @private
  54. * @param {string} tagTitle
  55. */
  56. Doclet.prototype._dropTag = function(tagTitle) {
  57. this.tags = this.tags.filter(function(el){return el.title != tagTitle});
  58. }