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 = imports.ScopeNamer.ScopeNamer.symbols;
198 //this.symbolSet = this.parser.symbols;
200 // this currently uses the concept of publish.js...
208 * create a list of files in this.srcFiles using list of directories / files in Options.src
212 _getSrcFiles : function()
217 var ext = this.ext.split(",").map(function($) {return $.toLowerCase()});
219 this.src.forEach(function(src_in) {
220 // add to sourcefiles..
221 var src = File.join(_this.baseDir , src_in);
224 if (!File.isDirectory(src)) {
229 File.list(src ).forEach(function($) {
230 if (_this.excludeSrc.indexOf($) > -1) {
233 var thisExt = $.split(".").pop().toLowerCase();
234 if (ext.indexOf(thisExt) < 0) {
237 ret.push( File.join(src, $));
241 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
245 * Parse the source files.
249 _parseSrcFiles : function()
253 this.srcFiles.forEach(function(srcFile) {
256 var cacheFile = !_this.cacheDirectory.length ? false :
257 _this.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
260 // disabled at present!@!!
262 if (cacheFile && File.exists(cacheFile)) {
265 var c_mt = File.mtime(cacheFile);
266 var o_mt = File.mtime(srcFile);
267 //println(c_mt.toSource());
268 // println(o_mt.toSource());
270 // this check does not appear to work according to the doc's - need to check it out.
272 if (c_mt > o_mt) { // cached time > original time!
273 // use the cached mtimes..
274 print("Read " + cacheFile);
276 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
278 if (typeof(v) != 'object') {
281 if (typeof(v['*object']) == 'undefined') {
285 var cls = imports[v['*object']][v['*object']];
286 //print(v['*object']);
289 XObject.extend(ret, v);
293 //print("Add sybmols " + cacheFile);
294 for (var sy in syms._index) {
295 // print("ADD:" + sy );
296 _this.parser.symbols.addSymbol(syms._index[sy]);
304 _this.LOG.inform("reading : " + srcFile);
305 src = File.read(srcFile);
308 _this.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
312 var txs = new imports.TextStream.TextStream(src);
314 var tr = new imports.TokenReader.TokenReader({
322 var col = new imports.Collapse.Collapse(tr.tokenize(txs), srcFile);
323 // print(JSON.stringify(col, null,4));
324 new imports.ScopeNamer.ScopeNamer(col.tokens, srcFile);
332 var ts = new imports.TokenStream.TokenStream(tr.tokenize(txs), srcFile);
334 _this.parser.parse(ts, srcFile);
337 File.write(cacheFile,
339 _this.parser.symbolsToObject(srcFile),
350 imports.ScopeNamer.ScopeNamer.symbols.relate();
352 //this.parser.finish();
356 * publish the parsed data into html, js etc.
359 publish : function() {
360 this.LOG.inform("Publishing");
365 this.LOG.inform("Making directories");
366 if (!File.isDirectory(this.target))
367 File.mkdir(this.target);
368 if (!File.isDirectory(this.target+"/symbols"))
369 File.mkdir(this.target+"/symbols");
370 if (!File.isDirectory(this.target+"/symbols/src"))
371 File.mkdir(this.target+"/symbols/src");
373 if (!File.isDirectory(this.target +"/json")) {
374 File.mkdir(this.target +"/json");
377 this.LOG.inform("Copying files from static: " +this.templateDir);
378 // copy everything in 'static' into
379 File.list(this.templateDir + '/static').forEach(function (f) {
380 _this.LOG.inform("Copy " + _this.templateDir + '/static/' + f + ' to ' + _this.target + '/' + f);
381 File.copyFile(_this.templateDir + '/static/' + f, _this.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
385 this.LOG.inform("Setting up templates");
388 // used to check the details of things being linked to
389 Link.symbolSet = this.symbolSet;
392 Link.srcFileFlatName = XObject.createDelegate(this.srcFileFlatName, this);
393 Link.srcFileRelName = XObject.createDelegate(this.srcFileRelName, this);
395 var classTemplate = new Template({
396 templateFile : this.templateDir + "/class.html",
399 var classesTemplate = new Template({
400 templateFile : this.templateDir +"/allclasses.html",
403 var classesindexTemplate = new Template({
404 templateFile : this.templateDir +"/index.html",
407 var fileindexTemplate = new Template({
408 templateFile : this.templateDir +"/allfiles.html",
413 classTemplate.symbolSet = this.symbolSet;
416 function hasNoParent($) {
417 return ($.memberOf == "")
419 function isaFile($) {
420 return ($.is("FILE"))
422 function isaClass($) {
423 return ($.is("CONSTRUCTOR") || $.isNamespace);
435 var symbols = this.symbolSet.toArray();
437 var files = this.srcFiles;
439 for (var i = 0, l = files.length; i < l; i++) {
441 var targetDir = _this.target + "/symbols/src/";
442 this.makeSrcFile(file, targetDir);
444 //print(JSON.stringify(symbols,null, 4));
445 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
448 this.LOG.inform("iterate classes");
452 for (var i = 0, l = classes.length; i < l; i++) {
453 var symbol = classes[i];
456 this.LOG.inform("classTemplate Process : " + this.target+"/symbols/" +symbol.alias+'.' + this.publishExt);
459 symbol.ignoreNamespace = this.ignoreNamespace;
461 File.write(this.target+"/symbols/" +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
523 publishJSON : function(data)
525 // what we need to output to be usefull...
527 var cfgProperties = [];
528 if (!data.comment.getTag('singleton').length) {
529 cfgProperties = data.configToArray();
530 cfgProperties = cfgProperties.sort(makeSortby("alias"));
534 //println(cfgProperties.toSource());
536 for(var i =0; i < cfgProperties.length;i++) {
537 p = cfgProperties[i];
542 memberOf : p.memberOf == data.alias ? '' : p.memberOf
547 var ownEvents = data.methods.filter( function(e){
548 return e.isEvent && !e.comment.getTag('hide').length;
549 }).sort(makeSortby("name"));
554 for(var i =0; i < ownEvents.length;i++) {
557 name : m.name.substring(1),
558 sig : this.makeFuncSkel(m.params),
563 //println(props.toSource());
564 // we need to output:
584 srcFileRelName : function(sourceFile)
586 // print(JSON.stringify([ sourceFile, this.baseDir ] ));
587 return sourceFile.substring(this.baseDir.length+1);
589 srcFileFlatName: function(sourceFile)
591 var name = this.srcFileRelName(sourceFile);
592 // print("NAME: " + name);
593 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
594 return name.replace(/\:/g, "_") + '.html'; //??;
598 makeSrcFile: function(sourceFile)
600 // this stuff works...
603 var name = this.srcFileFlatName(sourceFile);
605 this.LOG.inform("Write Source file : " + this.target+"/symbols/src/" + name + " FROM: " + sourceFile);
607 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
609 File.write(this.target+"/symbols/src/" + name,
611 '<title>' + sourceFile + '</title>' +
612 '<link rel="stylesheet" type="text/css" href="' + this.roojs + '/css/highlight-js.css"/>' +
613 '</head><body class="highlightpage">' +
618 * used by JSON output to generate a function skeleton
620 makeFuncSkel :function(params) {
621 if (!params) return "function ()\n{\n\n}";
622 return "function (" +
625 return $.name.indexOf(".") == -1; // don't show config params in signature
627 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +