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!??
39 * Main class used to build documentation
41 BuildDocs = XObject.define(
43 XObject.extend(this, opts); // overlay cfg..
44 //print(JSON.stringify(this, null,4));
46 this.LOG = imports.JSDOC.Log.Log;
49 imports.SymbolSet.SymbolSet.LOG = this.LOG
50 /*this.parser = new imports.JSDOC.Parser.Parser({
52 docPrivate : this.docPrivate
66 * @cfg {Object} LOG an implementation of the log interface..
71 * @cfg {String} baseDir root directory (for relative publishing?)
77 * @cfg {String} cacheDirectory where to store the cached parse.
79 cacheDirectory: false,
82 * @cfg {String} ext comma-delimited list of extensions to handle..
87 * @cfg {String} lang Language to parse (eg. js / php ...)
92 * @cfg {Array} src base source files/directories.
97 * @cfg {Array} excludeSrc base source files/directories.
101 * @cfg {String} target where to write the output to.
109 * @cfg {String} templateDir where get the templates from.
113 * @cfg {String} publishExt output extenstion.
120 * @cfg {Boolean} docPrivate document private variables.
126 * @cfg {String} roojs Path to roojs installation.
128 roojs : 'http://roojs.com/roojs1/',
132 * @cfg {Boolean} ignoreNamespace should the memberOf be stripped for seed classes
134 ignoreNamespace : false,
141 * Full list of source files.
163 * start the build process
169 this.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
172 if (this.cacheDirectory.length && !File.isDirectory(this.cacheDirectory)) {
173 File.mkdir(this.cacheDirectory)
176 this.srcFiles = this._getSrcFiles();
177 this._parseSrcFiles();
178 this.symbolSet = imports.ScopeNamer.ScopeNamer.symbols;
179 //this.symbolSet = this.parser.symbols;
181 // this currently uses the concept of publish.js...
189 * create a list of files in this.srcFiles using list of directories / files in Options.src
193 _getSrcFiles : function()
198 var ext = this.ext.split(",").map(function($) {return $.toLowerCase()});
200 this.src.forEach(function(src_in) {
201 // add to sourcefiles..
202 var src = File.join(_this.baseDir , src_in);
205 if (!File.isDirectory(src)) {
210 File.list(src ).forEach(function($) {
211 if (_this.excludeSrc.indexOf($) > -1) {
214 var thisExt = $.split(".").pop().toLowerCase();
215 if (ext.indexOf(thisExt) < 0) {
218 ret.push( File.join(src, $));
222 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
226 * Parse the source files.
230 _parseSrcFiles : function()
234 this.srcFiles.forEach(function(srcFile) {
237 var cacheFile = !_this.cacheDirectory.length ? false :
238 _this.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
241 // disabled at present!@!!
243 if (cacheFile && File.exists(cacheFile)) {
246 var c_mt = File.mtime(cacheFile);
247 var o_mt = File.mtime(srcFile);
248 //println(c_mt.toSource());
249 // println(o_mt.toSource());
251 // this check does not appear to work according to the doc's - need to check it out.
253 if (c_mt > o_mt) { // cached time > original time!
254 // use the cached mtimes..
255 print("Read " + cacheFile);
257 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
259 if (typeof(v) != 'object') {
262 if (typeof(v['*object']) == 'undefined') {
266 var cls = imports[v['*object']][v['*object']];
267 //print(v['*object']);
270 XObject.extend(ret, v);
274 //print("Add sybmols " + cacheFile);
275 for (var sy in syms._index) {
276 // print("ADD:" + sy );
277 imports.ScopeNamer.ScopeNamer.symbols.addSymbol(syms._index[sy]);
285 _this.LOG.inform("reading : " + srcFile);
286 src = File.read(srcFile);
289 _this.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
293 var txs = new imports.TextStream.TextStream(src);
295 var tr = new imports.TokenReader.TokenReader({
300 filename : _this.srcFileRelName(srcFile)
302 //print(JSON.stringify(tr.tokenize(txs), null, 4));
305 var sn = new imports.ScopeNamer.ScopeNamer({
306 tokens : tr.tokenize(txs),
307 filename : _this.srcFileRelName(srcFile)
318 File.write(cacheFile,
320 _this.parser.symbolsToObject(srcFile),
329 print(JSON.stringify(
330 XObject.keys(imports.ScopeNamer.ScopeNamer.symbols._index),
333 imports.ScopeNamer.ScopeNamer.symbols.relate();
335 //print(JSON.stringify(
336 // XObject.keys(imports.ScopeNamer.ScopeNamer.symbols._index),
340 //print(JSON.stringify(imports.ScopeNamer.ScopeNamer.symbols._index, null,4));
341 //this.parser.finish();
345 * publish the parsed data into html, js etc.
348 publish : function() {
349 this.LOG.inform("Publishing");
354 this.LOG.inform("Making directories:" + this.target);
355 if (!File.isDirectory(this.target))
356 File.mkdir(this.target);
358 if (!File.isDirectory(this.target+"/symbols"))
359 File.mkdir(this.target+"/symbols");
360 if (!File.isDirectory(this.target+"/symbols/src"))
361 File.mkdir(this.target+"/symbols/src");
363 if (!File.isDirectory(this.target +"/json")) {
364 File.mkdir(this.target +"/json");
367 this.LOG.inform("Copying files from static: " +this.templateDir);
368 // copy everything in 'static' into
369 File.list(this.templateDir + '/static').forEach(function (f) {
370 _this.LOG.inform("Copy " + _this.templateDir + '/static/' + f + ' to ' + _this.target + '/' + f);
371 File.copyFile(_this.templateDir + '/static/' + f, _this.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
375 this.LOG.inform("Setting up templates");
378 // used to check the details of things being linked to
379 Link.symbolSet = this.symbolSet;
382 Link.srcFileFlatName = XObject.createDelegate(this.srcFileFlatName, this);
383 Link.srcFileRelName = XObject.createDelegate(this.srcFileRelName, this);
385 var classTemplate = new Template({
386 templateFile : this.templateDir + "/class.html",
389 var classesTemplate = new Template({
390 templateFile : this.templateDir +"/allclasses.html",
393 var classesindexTemplate = new Template({
394 templateFile : this.templateDir +"/index.html",
397 var fileindexTemplate = new Template({
398 templateFile : this.templateDir +"/allfiles.html",
403 classTemplate.symbolSet = this.symbolSet;
406 function hasNoParent($) {
407 return ($.memberOf == "")
409 function isaFile($) {
410 return ($.is("FILE"))
412 function isaClass($) {
413 //return ($.is("CONSTRUCTOR") || $.isNamespace);
414 return ($.is("CONSTRUCTOR") || $.is("OBJECT"));
426 var symbols = this.symbolSet.toArray();
428 var files = this.srcFiles;
430 for (var i = 0, l = files.length; i < l; i++) {
432 var targetDir = _this.target + "/symbols/src/";
433 this.makeSrcFile(file, targetDir);
435 var makeSortby = imports.JsTemplate.Template.Template.prototype.makeSortby;
436 //print(JSON.stringify(symbols,null, 4));
437 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
440 this.LOG.inform("iterate classes");
444 for (var i = 0, l = classes.length; i < l; i++) {
445 var symbol = classes[i];
450 //symbol.ignoreNamespace = this.ignoreNamespace;
452 var ns = File.dirname(symbol.srcFile).replace(/\//g,'.');
453 if (symbol.alias.substring(0, ns.length) == ns) {
456 ns += ns.length ? '.' : '';
459 this.LOG.inform("classTemplate Process : " +
460 this.target+"/symbols/" + ns + symbol.alias+'.' + this.publishExt);
462 File.write(this.target+"/symbols/" + ns + symbol.alias+'.' + this.publishExt ,
463 classTemplate.process(symbol));
465 jsonAll[symbol.alias] = this.publishJSON(symbol);
471 File.write(this.target+"/json/roodata.json",
479 // regenrate the index with different relative links
482 this.LOG.inform("build index");
484 File.write(this.target + "/index."+ this.publishExt,
485 classesindexTemplate.process(classes)
488 // blank everything???? classesindexTemplate = classesIndex = classes = null;
492 var documentedFiles = symbols.filter(function ($) {
493 return ($.is("FILE"))
498 for (var i = 0; i < files.length; i++) {
499 allFiles.push(new imports.Symbol.Symbol(files[i], [], "FILE", new imports.DocComment.DocComment("/** */")));
502 for (var i = 0; i < documentedFiles.length; i++) {
503 var offset = files.indexOf(documentedFiles[i].alias);
504 allFiles[offset] = documentedFiles[i];
507 allFiles = allFiles.sort(makeSortby("name"));
508 this.LOG.inform("write files index");
510 File.write(this.target + "/files."+this.publishExt,
511 fileindexTemplate.process(allFiles)
519 * JSON files are lookup files for the documentation
520 * - can be used by IDE's or AJAX based doc tools
521 * @param {Symbol} data The symbol to publish
524 publishJSON : function(data)
526 // what we need to output to be usefull...
528 var makeSortby = imports.JsTemplate.Template.Template.prototype.makeSortby;
530 var cfgProperties = [];
531 if (!data.comment.getTag('singleton').length) {
532 cfgProperties = data.configToArray();
533 cfgProperties = cfgProperties.sort(makeSortby("alias"));
537 //println(cfgProperties.toSource());
539 for(var i =0; i < cfgProperties.length;i++) {
540 p = cfgProperties[i];
545 memberOf : p.memberOf == data.alias ? '' : p.memberOf
550 var ownEvents = data.methods.filter( function(e){
551 return e.isEvent && !e.comment.getTag('hide').length;
552 }).sort(makeSortby("name"));
557 for(var i =0; i < ownEvents.length;i++) {
560 name : m.name.substring(1),
561 sig : this.makeFuncSkel(m.params),
566 //println(props.toSource());
567 // we need to output:
587 srcFileRelName : function(sourceFile)
589 // print(JSON.stringify([ sourceFile, this.baseDir ] ));
590 return sourceFile.substring(this.baseDir.length+1);
592 srcFileFlatName: function(sourceFile)
594 var name = sourceFile; //this.srcFileRelName(sourceFile);
595 // print("NAME: " + name);
596 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
597 return name.replace(/\:/g, "_") + '.html'; //??;
601 makeSrcFile: function(sourceFile)
603 // this stuff works...
606 var name = this.srcFileFlatName(this.srcFileRelName(sourceFile)) ;
608 this.LOG.inform("Write Source file : " + this.target+"/symbols/src/" + name + " FROM: " + sourceFile);
610 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
612 File.write(this.target+"/symbols/src/" + name,
614 '<title>' + sourceFile + '</title>' +
615 '<link rel="stylesheet" type="text/css" href="' + this.roojs + '/css/highlight-js.css"/>' +
616 '</head><body class="highlightpage">' +
621 * used by JSON output to generate a function skeleton
623 makeFuncSkel :function(params) {
624 if (!params) return "function ()\n{\n\n}";
625 return "function (" +
628 return $.name.indexOf(".") == -1; // don't show config params in signature
630 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +