PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.4.0/app/Doclet.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 65 lines | 27 code | 7 blank | 31 comment | 9 complexity | 09af617fc1cbb89efaf8f58b4c9210b1 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/tags/jsdoc_toolkit-1.4.0/app/Doclet.js $
 6 * @revision $Id: Doclet.js 389 2007-12-26 17:26:27Z 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/**
12 * @class Represents a collection of DocTags.
13 * @constructor
14 * @author Michael Mathews <a href="mailto:micmath@gmail.com">micmath@gmail.com</a>
15 * @param {string} comment The entire documentation comment. The openening slash-star-star and
16 * closing star-slash are optional. An untagged string at the start automatically gets a "desc" tag.
17 */
18function Doclet(comment) {
19	var src = Doclet.unwrapComment(comment);
20	var tagTexts = src.split(/(^|[\r\f\n])\s*@/);
21	
22	this.tags =
23		tagTexts.filter(function(el){return el.match(/^\w/)})
24		.map(function(el){return new DocTag(el)});
25	
26	var paramParent = "config"; // default
27	for(var i = 0; i < this.tags.length; i++) {
28		if (this.tags[i].title == "param") paramParent = this.tags[i].name;
29		if (this.tags[i].title == "config") {
30			this.tags[i].name = paramParent+"."+this.tags[i].name;
31			this.tags[i].title = "param"
32		}
33	}
34}
35
36/**
37 * Remove the slashes and stars from a doc comment.
38 * @static
39 * @memberOf Doclet
40 */
41Doclet.unwrapComment = function(comment) {
42	if (!comment) comment = "/** @desc undocumented */";
43
44	var unwrapped = comment.replace(/(^\/\*\*|\*\/$)/g, "").replace(/^\s*\* ?/gm, "");
45	if (unwrapped.match(/^\s*[^@\s]/)) unwrapped = "@desc "+unwrapped;
46	return unwrapped;
47}
48
49/**
50 * Get every DocTag with the given title.
51 * @param {string} tagTitle
52 * @return {DocTag[]}
53 */
54Doclet.prototype.getTag = function(tagTitle) {
55	return this.tags.filter(function(el){return el.title == tagTitle});
56}
57
58/**
59 * Remove from this Doclet every DocTag with the given title.
60 * @private
61 * @param {string} tagTitle
62 */
63Doclet.prototype._dropTag = function(tagTitle) {
64	this.tags = this.tags.filter(function(el){return el.title != tagTitle});
65}