1 //<script type="text/javascript">
4 * This is the main container for the JSDOC application.
8 BuildDocs = imports.JSDOC.BuildDocs.BuildDocs
16 new ArgsParser(argv, imports.BuildDocs.BuildDocs )
24 XObject = imports.XObject.XObject;
25 File = imports.File.File;
29 Template = imports.JsTemplate.Template.Template;
30 Link = imports.JsTemplate.Link.Link; // ?? fixme!??
38 * Main class used to build documentation
40 BuildDocs = XObject.define(
42 XObject.extend(this, opts); // overlay cfg..
43 //print(JSON.stringify(this, null,4));
45 this.LOG = imports.JSDOC.Log.Log;
48 imports.SymbolSet.SymbolSet.LOG = this.LOG
49 /*this.parser = new imports.JSDOC.Parser.Parser({
51 docPrivate : this.docPrivate
65 * @cfg {Object} LOG an implementation of the log interface..
70 * @cfg {String} baseDir root directory (for relative publishing?)
76 * @cfg {String} cacheDirectory where to store the cached parse.
78 cacheDirectory: false,
81 * @cfg {String} ext comma-delimited list of extensions to handle..
86 * @cfg {String} lang Language to parse (eg. js / php ...)
91 * @cfg {Array} src base source files/directories.
96 * @cfg {Array} excludeSrc base source files/directories.
100 * @cfg {String} target where to write the output to.
108 * @cfg {String} templateDir where get the templates from.
112 * @cfg {String} publishExt output extenstion.
119 * @cfg {Boolean} docPrivate document private variables.
125 * @cfg {String} roojs Path to roojs installation.
127 roojs : 'http://roojs.com/roojs1/',
131 * @cfg {Boolean} ignoreNamespace should the memberOf be stripped for seed classes
133 ignoreNamespace : false,
140 * Full list of source files.
162 * start the build process
168 this.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
171 if (this.cacheDirectory.length && !File.isDirectory(this.cacheDirectory)) {
172 File.mkdir(this.cacheDirectory)
175 this.srcFiles = this._getSrcFiles();
176 this._parseSrcFiles();
177 this.symbolSet = imports.ScopeNamer.ScopeNamer.symbols;
178 //this.symbolSet = this.parser.symbols;
180 // this currently uses the concept of publish.js...
188 * create a list of files in this.srcFiles using list of directories / files in Options.src
192 _getSrcFiles : function()
197 var ext = this.ext.split(",").map(function($) {return $.toLowerCase()});
199 this.src.forEach(function(src_in) {
200 // add to sourcefiles..
201 var src = File.join(_this.baseDir , src_in);
204 if (!File.isDirectory(src)) {
209 File.list(src ).forEach(function($) {
210 if (_this.excludeSrc.indexOf($) > -1) {
213 var thisExt = $.split(".").pop().toLowerCase();
214 if (ext.indexOf(thisExt) < 0) {
217 ret.push( File.join(src, $));
221 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
225 * Parse the source files.
229 _parseSrcFiles : function()
233 this.srcFiles.forEach(function(srcFile) {
236 var cacheFile = !_this.cacheDirectory.length ? false :
237 _this.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
240 // disabled at present!@!!
242 if (cacheFile && File.exists(cacheFile)) {
245 var c_mt = File.mtime(cacheFile);
246 var o_mt = File.mtime(srcFile);
247 //println(c_mt.toSource());
248 // println(o_mt.toSource());
250 // this check does not appear to work according to the doc's - need to check it out.
252 if (c_mt > o_mt) { // cached time > original time!
253 // use the cached mtimes..
254 print("Read " + cacheFile);
256 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
258 if (typeof(v) != 'object') {
261 if (typeof(v['*object']) == 'undefined') {
265 var cls = imports[v['*object']][v['*object']];
266 //print(v['*object']);
269 XObject.extend(ret, v);
273 //print("Add sybmols " + cacheFile);
274 for (var sy in syms._index) {
275 // print("ADD:" + sy );
276 imports.ScopeNamer.ScopeNamer.symbols.addSymbol(syms._index[sy]);
284 _this.LOG.inform("reading : " + srcFile);
285 src = File.read(srcFile);
288 _this.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
292 var txs = new imports.TextStream.TextStream(src);
294 var tr = new imports.TokenReader.TokenReader({
299 filename : _this.srcFileRelName(srcFile)
301 //print(JSON.stringify(tr.tokenize(txs), null, 4));
304 var sn = new imports.ScopeNamer.ScopeNamer({
305 tokens : tr.tokenize(txs),
306 filename : _this.srcFileRelName(srcFile)
317 File.write(cacheFile,
319 _this.parser.symbolsToObject(srcFile),
328 print(JSON.stringify(
329 XObject.keys(imports.ScopeNamer.ScopeNamer.symbols._index),
332 imports.ScopeNamer.ScopeNamer.symbols.relate();
334 //print(JSON.stringify(
335 // XObject.keys(imports.ScopeNamer.ScopeNamer.symbols._index),
339 //print(JSON.stringify(imports.ScopeNamer.ScopeNamer.symbols._index, null,4));
340 //this.parser.finish();
344 * publish the parsed data into html, js etc.
347 publish : function() {
348 this.LOG.inform("Publishing");
353 this.LOG.inform("Making directories:" + this.target);
354 if (!File.isDirectory(this.target))
355 File.mkdir(this.target);
357 if (!File.isDirectory(this.target+"/symbols"))
358 File.mkdir(this.target+"/symbols");
359 if (!File.isDirectory(this.target+"/symbols/src"))
360 File.mkdir(this.target+"/symbols/src");
362 if (!File.isDirectory(this.target +"/json")) {
363 File.mkdir(this.target +"/json");
366 this.LOG.inform("Copying files from static: " +this.templateDir);
367 // copy everything in 'static' into
368 File.list(this.templateDir + '/static').forEach(function (f) {
369 _this.LOG.inform("Copy " + _this.templateDir + '/static/' + f + ' to ' + _this.target + '/' + f);
370 File.copyFile(_this.templateDir + '/static/' + f, _this.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
374 this.LOG.inform("Setting up templates");
377 // used to check the details of things being linked to
378 Link.symbolSet = this.symbolSet;
381 Link.srcFileFlatName = XObject.createDelegate(this.srcFileFlatName, this);
382 Link.srcFileRelName = XObject.createDelegate(this.srcFileRelName, this);
384 var classTemplate = new Template({
385 templateFile : this.templateDir + "/class.html",
388 var classesTemplate = new Template({
389 templateFile : this.templateDir +"/allclasses.html",
392 var classesindexTemplate = new Template({
393 templateFile : this.templateDir +"/index.html",
396 var fileindexTemplate = new Template({
397 templateFile : this.templateDir +"/allfiles.html",
402 classTemplate.symbolSet = this.symbolSet;
405 function hasNoParent($) {
406 return ($.memberOf == "")
408 function isaFile($) {
409 return ($.is("FILE"))
411 function isaClass($) {
412 //return ($.is("CONSTRUCTOR") || $.isNamespace);
413 return ($.is("CONSTRUCTOR") || $.is("OBJECT"));
425 var symbols = this.symbolSet.toArray();
427 var files = this.srcFiles;
429 for (var i = 0, l = files.length; i < l; i++) {
431 var targetDir = _this.target + "/symbols/src/";
432 this.makeSrcFile(file, targetDir);
434 var makeSortby = imports.JsTemplate.Template.Template.prototype.makeSortby;
435 //print(JSON.stringify(symbols,null, 4));
436 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
439 this.LOG.inform("iterate classes");
443 for (var i = 0, l = classes.length; i < l; i++) {
444 var symbol = classes[i];
449 //symbol.ignoreNamespace = this.ignoreNamespace;
451 var ns = File.dirname(symbol.srcFile).replace(/\//g,'.');
452 if (symbol.alias.substring(0, ns.length) == ns) {
455 ns += ns.length ? '.' : '';
458 this.LOG.inform("classTemplate Process : " +
459 this.target+"/symbols/" + ns + symbol.alias+'.' + this.publishExt);
461 File.write(this.target+"/symbols/" + ns + symbol.alias+'.' + this.publishExt ,
462 classTemplate.process(symbol));
464 jsonAll[symbol.alias] = this.publishJSON(symbol);
470 File.write(this.target+"/json/roodata.json",
478 // regenrate the index with different relative links
481 this.LOG.inform("build index");
483 File.write(this.target + "/index."+ this.publishExt,
484 classesindexTemplate.process(classes)
487 // blank everything???? classesindexTemplate = classesIndex = classes = null;
491 var documentedFiles = symbols.filter(function ($) {
492 return ($.is("FILE"))
497 for (var i = 0; i < files.length; i++) {
498 allFiles.push(new imports.Symbol.Symbol(files[i], [], "FILE", new imports.DocComment.DocComment("/** */")));
501 for (var i = 0; i < documentedFiles.length; i++) {
502 var offset = files.indexOf(documentedFiles[i].alias);
503 allFiles[offset] = documentedFiles[i];
506 allFiles = allFiles.sort(makeSortby("name"));
507 this.LOG.inform("write files index");
509 File.write(this.target + "/files."+this.publishExt,
510 fileindexTemplate.process(allFiles)
518 * JSON files are lookup files for the documentation
519 * - can be used by IDE's or AJAX based doc tools
520 * @param {Symbol} data The symbol to publish
523 publishJSON : function(data)
525 // what we need to output to be usefull...
527 var makeSortby = imports.JsTemplate.Template.Template.prototype.makeSortby;
529 var cfgProperties = [];
530 if (!data.comment.getTag('singleton').length) {
531 cfgProperties = data.configToArray();
532 cfgProperties = cfgProperties.sort(makeSortby("alias"));
536 //println(cfgProperties.toSource());
538 for(var i =0; i < cfgProperties.length;i++) {
539 p = cfgProperties[i];
544 memberOf : p.memberOf == data.alias ? '' : p.memberOf
549 var ownEvents = data.methods.filter( function(e){
550 return e.isEvent && !e.comment.getTag('hide').length;
551 }).sort(makeSortby("name"));
556 for(var i =0; i < ownEvents.length;i++) {
559 name : m.name.substring(1),
560 sig : this.makeFuncSkel(m.params),
565 //println(props.toSource());
566 // we need to output:
586 srcFileRelName : function(sourceFile)
588 // print(JSON.stringify([ sourceFile, this.baseDir ] ));
589 return sourceFile.substring(this.baseDir.length+1);
591 srcFileFlatName: function(sourceFile)
593 var name = sourceFile; //this.srcFileRelName(sourceFile);
594 // print("NAME: " + name);
595 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
596 return name.replace(/\:/g, "_") + '.html'; //??;
600 makeSrcFile: function(sourceFile)
602 // this stuff works...
605 var name = this.srcFileFlatName(this.srcFileRelName(sourceFile)) ;
607 this.LOG.inform("Write Source file : " + this.target+"/symbols/src/" + name + " FROM: " + sourceFile);
609 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
611 File.write(this.target+"/symbols/src/" + name,
613 '<title>' + sourceFile + '</title>' +
614 '<link rel="stylesheet" type="text/css" href="' + this.roojs + '/css/highlight-js.css"/>' +
615 '</head><body class="highlightpage">' +
620 * used by JSON output to generate a function skeleton
622 makeFuncSkel :function(params) {
623 if (!params) return "function ()\n{\n\n}";
624 return "function (" +
627 return $.name.indexOf(".") == -1; // don't show config params in signature
629 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +