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!??
34 // should not realy be here -- or anywhere...??
36 function makeSortby(attribute) {
37 return function(a, b) {
38 if (a[attribute] != undefined && b[attribute] != undefined) {
39 a = a[attribute]; //.toLowerCase();
40 b = b[attribute];//.toLowerCase();
56 * @class JSDOC/BuildDocs
58 * Main class used to build documentation
60 BuildDocs = XObject.define(
62 XObject.extend(this, opts); // overlay cfg..
65 this.LOG = imports.JSDOC.Log.Log;
68 this.parser = new imports.JSDOC.Parser.Parser({
70 docPrivate : this.docPrivate
84 * @cfg {Object} LOG an implementation of the log interface..
89 * @cfg {String} baseDir root directory (for relative publishing?)
95 * @cfg {String} cacheDirectory where to store the cached parse.
97 cacheDirectory: false,
100 * @cfg {String} ext comma-delimited list of extensions to handle..
106 * @cfg {Array} src base source files/directories.
111 * @cfg {Array} excludeSrc base source files/directories.
115 * @cfg {String} target where to write the output to.
123 * @cfg {String} templateDir where get the templates from.
127 * @cfg {String} publishExt output extenstion.
134 * @cfg {Boolean} docPrivate document private variables.
140 * @cfg {String} roojs Path to roojs installation.
142 roojs : 'http://roojs.com/roojs1/',
146 * @cfg {Boolean} ignoreNamespace should the memberOf be stripped for seed classes
148 ignoreNamespace : false,
155 * Full list of source files.
162 * the JSDOC.parser instance.
182 * start the build process
188 this.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
191 if (this.cacheDirectory.length && !File.isDirectory(this.cacheDirectory)) {
192 File.mkdir(this.cacheDirectory)
195 this.srcFiles = this._getSrcFiles();
196 this._parseSrcFiles();
197 this.symbolSet = this.parser.symbols;
199 // this currently uses the concept of publish.js...
207 * create a list of files in this.srcFiles using list of directories / files in Options.src
211 _getSrcFiles : function()
216 var ext = this.ext.split(",").map(function($) {return $.toLowerCase()});
218 this.src.forEach(function(src_in) {
219 // add to sourcefiles..
220 var src = File.join(_this.baseDir , src_in);
223 if (!File.isDirectory(src)) {
228 File.list(src ).forEach(function($) {
229 if (_this.excludeSrc.indexOf($) > -1) {
232 var thisExt = $.split(".").pop().toLowerCase();
233 if (ext.indexOf(thisExt) < 0) {
236 ret.push( File.join(src, $));
240 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
244 * Parse the source files.
248 _parseSrcFiles : function()
252 this.srcFiles.forEach(function(srcFile) {
255 var cacheFile = !_this.cacheDirectory.length ? false :
256 _this.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
259 // disabled at present!@!!
261 if (cacheFile && File.exists(cacheFile)) {
264 var c_mt = File.mtime(cacheFile);
265 var o_mt = File.mtime(srcFile);
266 //println(c_mt.toSource());
267 // println(o_mt.toSource());
269 // this check does not appear to work according to the doc's - need to check it out.
271 if (c_mt > o_mt) { // cached time > original time!
272 // use the cached mtimes..
273 print("Read " + cacheFile);
275 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
277 if (typeof(v) != 'object') {
280 if (typeof(v['*object']) == 'undefined') {
284 var cls = imports[v['*object']][v['*object']];
285 //print(v['*object']);
288 XObject.extend(ret, v);
292 //print("Add sybmols " + cacheFile);
293 for (var sy in syms._index) {
294 // print("ADD:" + sy );
295 _this.parser.symbols.addSymbol(syms._index[sy]);
303 _this.LOG.inform("reading : " + srcFile);
304 src = File.read(srcFile);
307 _this.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
311 var txs = new imports.TextStream.TextStream(src);
313 var tr = new imports.TokenReader.TokenReader({
321 var col = new imports.Collapse.Collapse(tr.tokenize(txs), srcFile);
322 print(JSON.stringify(col, null,4));
323 new imports.ScopeNamer.ScopeNamer(col.tokens);
330 var ts = new imports.TokenStream.TokenStream(tr.tokenize(txs), srcFile);
332 _this.parser.parse(ts, srcFile);
335 File.write(cacheFile,
337 _this.parser.symbolsToObject(srcFile),
350 this.parser.finish();
354 * publish the parsed data into html, js etc.
357 publish : function() {
358 this.LOG.inform("Publishing");
363 this.LOG.inform("Making directories");
364 if (!File.isDirectory(this.target))
365 File.mkdir(this.target);
366 if (!File.isDirectory(this.target+"/symbols"))
367 File.mkdir(this.target+"/symbols");
368 if (!File.isDirectory(this.target+"/symbols/src"))
369 File.mkdir(this.target+"/symbols/src");
371 if (!File.isDirectory(this.target +"/json")) {
372 File.mkdir(this.target +"/json");
375 this.LOG.inform("Copying files from static: " +this.templateDir);
376 // copy everything in 'static' into
377 File.list(this.templateDir + '/static').forEach(function (f) {
378 _this.LOG.inform("Copy " + _this.templateDir + '/static/' + f + ' to ' + _this.target + '/' + f);
379 File.copyFile(_this.templateDir + '/static/' + f, _this.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
383 this.LOG.inform("Setting up templates");
386 // used to check the details of things being linked to
387 Link.symbolSet = this.symbolSet;
390 Link.srcFileFlatName = XObject.createDelegate(this.srcFileFlatName, this);
391 Link.srcFileRelName = XObject.createDelegate(this.srcFileRelName, this);
393 var classTemplate = new Template({
394 templateFile : this.templateDir + "/class.html",
397 var classesTemplate = new Template({
398 templateFile : this.templateDir +"/allclasses.html",
401 var classesindexTemplate = new Template({
402 templateFile : this.templateDir +"/index.html",
405 var fileindexTemplate = new Template({
406 templateFile : this.templateDir +"/allfiles.html",
411 classTemplate.symbolSet = this.symbolSet;
414 function hasNoParent($) {
415 return ($.memberOf == "")
417 function isaFile($) {
418 return ($.is("FILE"))
420 function isaClass($) {
421 return ($.is("CONSTRUCTOR") || $.isNamespace);
433 var symbols = this.symbolSet.toArray();
435 var files = this.srcFiles;
437 for (var i = 0, l = files.length; i < l; i++) {
439 var targetDir = _this.target + "/symbols/src/";
440 this.makeSrcFile(file, targetDir);
442 //print(JSON.stringify(symbols,null, 4));
443 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
446 this.LOG.inform("iterate classes");
450 for (var i = 0, l = classes.length; i < l; i++) {
451 var symbol = classes[i];
454 this.LOG.inform("classTemplate Process : " + this.target+"/symbols/" +symbol.alias+'.' + this.publishExt);
457 symbol.ignoreNamespace = this.ignoreNamespace;
459 File.write(this.target+"/symbols/" +symbol.alias+'.' + this.publishExt ,
460 classTemplate.process(symbol));
462 jsonAll[symbol.alias] = this.publishJSON(symbol);
468 File.write(this.target+"/json/roodata.json",
476 // regenrate the index with different relative links
479 this.LOG.inform("build index");
481 File.write(this.target + "/index."+ this.publishExt,
482 classesindexTemplate.process(classes)
485 // blank everything???? classesindexTemplate = classesIndex = classes = null;
489 var documentedFiles = symbols.filter(function ($) {
490 return ($.is("FILE"))
495 for (var i = 0; i < files.length; i++) {
496 allFiles.push(new imports.Symbol.Symbol(files[i], [], "FILE", new imports.DocComment.DocComment("/** */")));
499 for (var i = 0; i < documentedFiles.length; i++) {
500 var offset = files.indexOf(documentedFiles[i].alias);
501 allFiles[offset] = documentedFiles[i];
504 allFiles = allFiles.sort(makeSortby("name"));
505 this.LOG.inform("write files index");
507 File.write(this.target + "/files."+this.publishExt,
508 fileindexTemplate.process(allFiles)
516 * JSON files are lookup files for the documentation
517 * - can be used by IDE's or AJAX based doc tools
521 publishJSON : function(data)
523 // what we need to output to be usefull...
525 var cfgProperties = [];
526 if (!data.comment.getTag('singleton').length) {
527 cfgProperties = data.configToArray();
528 cfgProperties = cfgProperties.sort(makeSortby("alias"));
532 //println(cfgProperties.toSource());
534 for(var i =0; i < cfgProperties.length;i++) {
535 p = cfgProperties[i];
540 memberOf : p.memberOf == data.alias ? '' : p.memberOf
545 var ownEvents = data.methods.filter( function(e){
546 return e.isEvent && !e.comment.getTag('hide').length;
547 }).sort(makeSortby("name"));
552 for(var i =0; i < ownEvents.length;i++) {
555 name : m.name.substring(1),
556 sig : this.makeFuncSkel(m.params),
561 //println(props.toSource());
562 // we need to output:
582 srcFileRelName : function(sourceFile)
584 // print(JSON.stringify([ sourceFile, this.baseDir ] ));
585 return sourceFile.substring(this.baseDir.length+1);
587 srcFileFlatName: function(sourceFile)
589 var name = this.srcFileRelName(sourceFile);
590 // print("NAME: " + name);
591 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
592 return name.replace(/\:/g, "_") + '.html'; //??;
596 makeSrcFile: function(sourceFile)
598 // this stuff works...
601 var name = this.srcFileFlatName(sourceFile);
603 this.LOG.inform("Write Source file : " + this.target+"/symbols/src/" + name + " FROM: " + sourceFile);
605 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
607 File.write(this.target+"/symbols/src/" + name,
609 '<title>' + sourceFile + '</title>' +
610 '<link rel="stylesheet" type="text/css" href="' + this.roojs + '/css/highlight-js.css"/>' +
611 '</head><body class="highlightpage">' +
616 * used by JSON output to generate a function skeleton
618 makeFuncSkel :function(params) {
619 if (!params) return "function ()\n{\n\n}";
620 return "function (" +
623 return $.name.indexOf(".") == -1; // don't show config params in signature
625 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +