PageRenderTime 44ms CodeModel.GetById 22ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/jsdoc_toolkit-2.0.1/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 162 lines | 97 code | 20 blank | 45 comment | 33 complexity | 7bb624fa615f5d1e2f387140ca788285 MD5 | raw file
  1/**
  2	@constructor
  3	@param [opt] Used to override the commandline options. Useful for testing.
  4	@version $Id: JsDoc.js 592 2008-05-09 07:43:33Z micmath $
  5*/
  6JSDOC.JsDoc = function(/**object*/ opt) {
  7	if (opt) {
  8		JSDOC.opt = opt;
  9	}
 10	
 11	// the -c option: use a configuration file
 12	if (JSDOC.opt.c) {
 13		eval("JSDOC.conf = " + IO.readFile(JSDOC.opt.c));
 14		
 15		LOG.inform("Using configuration file at '"+JSDOC.opt.c+"'.");
 16		
 17		for (var c in JSDOC.conf) {
 18			if (c !== "D" && !defined(JSDOC.opt[c])) { // commandline overrules config file
 19				JSDOC.opt[c] = JSDOC.conf[c];
 20			}
 21		}
 22		
 23		if (typeof JSDOC.conf["_"] != "undefined") {
 24			JSDOC.opt["_"] = JSDOC.opt["_"].concat(JSDOC.conf["_"]);
 25		}
 26		
 27		LOG.inform("With configuration: ");
 28		for (var o in JSDOC.opt) {
 29			LOG.inform("    "+o+": "+JSDOC.opt[o]);
 30		}
 31	}
 32	
 33	if (JSDOC.opt.h) {
 34		JSDOC.usage();
 35		quit();
 36	}
 37	
 38	// defend against options that are not sane 
 39	if (JSDOC.opt._.length == 0) {
 40		LOG.warn("No source files to work on. Nothing to do.");
 41		quit();
 42	}
 43	if (JSDOC.opt.t === true || JSDOC.opt.d === true) {
 44		JSDOC.usage();
 45	}
 46	
 47	if (typeof JSDOC.opt.d == "string") {
 48		if (!JSDOC.opt.d.charAt(JSDOC.opt.d.length-1).match(/[\\\/]/)) {
 49			JSDOC.opt.d = JSDOC.opt.d+"/";
 50		}
 51		LOG.inform("Output directory set to '"+JSDOC.opt.d+"'.");
 52		IO.mkPath(JSDOC.opt.d);
 53	}
 54	if (JSDOC.opt.e) IO.setEncoding(JSDOC.opt.e);
 55	
 56	// the -r option: scan source directories recursively
 57	if (typeof JSDOC.opt.r == "boolean") JSDOC.opt.r = 10;
 58	else if (!isNaN(parseInt(JSDOC.opt.r))) JSDOC.opt.r = parseInt(JSDOC.opt.r);
 59	else JSDOC.opt.r = 1;
 60	
 61	// the -D option: define user variables
 62	var D = {};
 63	if (JSDOC.opt.D) {
 64		for (var i = 0; i < JSDOC.opt.D.length; i++) {
 65			var defineParts = JSDOC.opt.D[i].split(":", 2);
 66			if (defineParts) D[defineParts[0]] = defineParts[1];
 67		}
 68	}
 69	JSDOC.opt.D = D;
 70	// combine any conf file D options with the commandline D options
 71	if (defined(JSDOC.conf)) for (var c in JSDOC.conf.D) {
 72 		if (!defined(JSDOC.opt.D[c])) {
 73 			JSDOC.opt.D[c] = JSDOC.conf.D[c];
 74 		}
 75 	}
 76
 77	// Load additional file handlers
 78	// the -H option: filetype handlers
 79	JSDOC.handlers = {};
 80/*	
 81	if (JSDOC.opt.H) {
 82		for (var i = 0; i < JSDOC.opt.H.length; i++) {
 83			var handlerDef = JSDOC.opt.H[i].split(":");
 84			LOG.inform("Adding '." + handlerDef[0] + "' content handler from handlers/" + handlerDef[1] + ".js");
 85			IO.include("handlers/" + handlerDef[1] + ".js");
 86			if (!eval("typeof "+handlerDef[1])) {
 87				LOG.warn(handlerDef[1] + "is not defined in "+handlerDef[1] + ".js");
 88			}
 89			else {
 90				JSDOC.handlers[handlerDef[0]] = eval(handlerDef[1]);
 91			}
 92		}
 93	}
 94*/	
 95	// Give plugins a chance to initialize
 96	if (defined(JSDOC.PluginManager)) {
 97		JSDOC.PluginManager.run("onInit", this);
 98	}
 99
100	JSDOC.opt.srcFiles = this._getSrcFiles();
101	this._parseSrcFiles();
102	//var handler = symbols.handler;
103	this.symbolSet = JSDOC.Parser.symbols;
104	//this.symbolGroup.handler = handler;
105}
106
107/**
108	Retrieve source file list.
109	@returns {String[]} The pathnames of the files to be parsed.
110 */
111JSDOC.JsDoc.prototype._getSrcFiles = function() {
112	this.srcFiles = [];
113	
114	var ext = ["js"];
115	if (JSDOC.opt.x) {
116		ext = JSDOC.opt.x.split(",").map(function($) {return $.toLowerCase()});
117	}
118	
119	for (var i = 0; i < JSDOC.opt._.length; i++) {
120		this.srcFiles = this.srcFiles.concat(
121			IO.ls(JSDOC.opt._[i], JSDOC.opt.r).filter(
122				function($) {
123					var thisExt = $.split(".").pop().toLowerCase();
124					return (ext.indexOf(thisExt) > -1 || thisExt in JSDOC.handlers); // we're only interested in files with certain extensions
125				}
126			)
127		);
128	}
129	
130	return this.srcFiles;
131}
132
133JSDOC.JsDoc.prototype._parseSrcFiles = function() {
134	JSDOC.Parser.init();
135	for (var i = 0, l = this.srcFiles.length; i < l; i++) {
136		var srcFile = this.srcFiles[i];
137		
138		try {
139			var src = IO.readFile(srcFile);
140		}
141		catch(e) {
142			LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
143		}
144
145		// Check to see if there is a handler for this file type
146//		var ext = FilePath.fileExtension(srcFile);
147// 		if (JSDOC.handlers[ext]) {
148// 			LOG.inform(" Using external handler for '" + ext + "'");
149// 
150// 			symbols = symbols.concat(JSDOC.handlers[ext].handle(srcFile, src));
151// 			symbols.handler = JSDOC.handlers[ext];
152// 		}
153// 		else {
154			// The default (JSDOC) handler
155			var tr = new JSDOC.TokenReader();
156			var ts = new JSDOC.TokenStream(tr.tokenize(new JSDOC.TextStream(src)));
157	
158			JSDOC.Parser.parse(ts, srcFile);
159//		}
160	}
161	JSDOC.Parser.finish();
162}