1 //<script type="text/javascript">
3 This is the main container for the JSDOC application.
8 XObject = imports.XObject.XObject;
9 File = imports.File.File;
11 Template = imports.JsTemplate.Template.Template;
12 Link = imports.JsTemplate.Link.Link; // ?? fixme!??
14 Parser = imports.Parser.Parser;
15 TextStream = imports.TextStream.TextStream;
16 TokenReader = imports.TokenReader.TokenReader;
17 TokenStream = imports.TokenStream.TokenStream;
18 Symbol = imports.Symbol.Symbol;
19 DocComment = imports.DocComment.DocComment;
22 // should not realy be here -- or anywhere...??
24 function makeSortby(attribute) {
25 return function(a, b) {
26 if (a[attribute] != undefined && b[attribute] != undefined) {
27 a = a[attribute]; //.toLowerCase();
28 b = b[attribute];//.toLowerCase();
36 Options = false; // refer to this everywhere!
47 build : function (opts)
52 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
53 //Options.LOG.inform("With options: ");
55 if (Options.cacheDirectory.length && !File.isDirectory(Options.cacheDirectory)) {
56 File.mkdir(Options.cacheDirectory)
59 Options.srcFiles = this._getSrcFiles();
60 this._parseSrcFiles();
61 this.symbolSet = Parser.symbols;
63 // this currently uses the concept of publish.js...
71 * create a list of files in this.srcFiles using list of directories / files in Options.src
75 _getSrcFiles : function()
81 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
84 for (var i = 0; i < Options.src.length; i++) {
85 // add to sourcefiles..
86 if (!File.isDirectory(Options.src[i])) {
87 _this.srcFiles.push(Options.src[i]);
90 File.list(Options.src[i] ).forEach(function($) {
91 if (Options['exclude-src'].indexOf($) > -1) {
94 var thisExt = $.split(".").pop().toLowerCase();
95 if (ext.indexOf(thisExt) < 0) {
98 _this.srcFiles.push(Options.src[i] + '/' + $);
102 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
103 return this.srcFiles;
106 * Parse the source files.
110 _parseSrcFiles : function()
114 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
116 var srcFile = this.srcFiles[i];
119 var cacheFile = !Options.cacheDirectory.length ? false :
120 Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
123 // disabled at present!@!!
125 if (cacheFile && File.exists(cacheFile)) {
128 var c_mt = File.mtime(cacheFile);
129 var o_mt = File.mtime(srcFile);
130 //println(c_mt.toSource());
131 // println(o_mt.toSource());
133 // this check does not appear to work according to the doc's - need to check it out.
135 if (c_mt > o_mt) { // cached time > original time!
136 // use the cached mtimes..
137 print("Read " + cacheFile);
138 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
140 if (typeof(v) != 'object') {
143 if (typeof(v['*object']) == 'undefined') {
146 var cls = imports[v['*object']][v['*object']];
147 //print(v['*object']);
150 XObject.extend(ret, v);
155 //print("Add sybmols " + cacheFile);
156 for (var sy in syms._index) {
157 // print("ADD:" + sy );
158 Parser.symbols.addSymbol(syms._index[sy]);
166 Options.LOG.inform("reading : " + srcFile);
167 src = File.read(srcFile);
170 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
174 var txs = new TextStream(src);
176 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
178 var ts = new TokenStream(tr.tokenize(txs));
180 Parser.parse(ts, srcFile);
183 File.write(cacheFile,
185 Parser.symbolsToObject(srcFile),
191 //var outstr = JSON.stringify(
192 // Parser.filesSymbols[srcFile]._index
194 //File.write(cacheFile, outstr);
207 publish : function() {
208 Options.LOG.inform("Publishing");
213 Options.LOG.inform("Making directories");
214 if (!File.isDirectory(Options.target))
215 File.mkdir(Options.target);
216 if (!File.isDirectory(Options.target+"/symbols"))
217 File.mkdir(Options.target+"/symbols");
218 if (!File.isDirectory(Options.target+"/symbols/src"))
219 File.mkdir(Options.target+"/symbols/src");
221 if (!File.isDirectory(Options.target +"/json")) {
222 File.mkdir(Options.target +"/json");
225 Options.LOG.inform("Copying files from static: " +Options.templateDir);
226 // copy everything in 'static' into
227 File.list(Options.templateDir + '/static').forEach(function (f) {
228 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
229 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
233 Options.LOG.inform("Setting up templates");
234 // used to check the details of things being linked to
235 Link.symbolSet = this.symbolSet;
238 Link.srcFileFlatName = this.srcFileFlatName;
239 Link.srcFileRelName = this.srcFileRelName;
241 var classTemplate = new Template({
242 templateFile : Options.templateDir + "/class.html",
245 var classesTemplate = new Template({
246 templateFile : Options.templateDir +"/allclasses.html",
249 var classesindexTemplate = new Template({
250 templateFile : Options.templateDir +"/index.html",
253 var fileindexTemplate = new Template({
254 templateFile : Options.templateDir +"/allfiles.html",
259 classTemplate.symbolSet = this.symbolSet;
262 function hasNoParent($) {
263 return ($.memberOf == "")
265 function isaFile($) {
266 return ($.is("FILE"))
268 function isaClass($) {
269 return ($.is("CONSTRUCTOR") || $.isNamespace || $.isClass);
281 var symbols = this.symbolSet.toArray();
283 var files = Options.srcFiles;
285 for (var i = 0, l = files.length; i < l; i++) {
287 var targetDir = Options.target + "/symbols/src/";
288 this.makeSrcFile(file, targetDir);
290 //print(JSON.stringify(symbols,null,4));
292 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
294 //Options.LOG.inform("classTemplate Process : all classes");
296 // var classesIndex = classesTemplate.process(classes); // kept in memory
298 Options.LOG.inform("iterate classes");
302 for (var i = 0, l = classes.length; i < l; i++) {
303 var symbol = classes[i];
306 Options.LOG.inform("classTemplate Process : " + symbol.alias);
311 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
312 classTemplate.process(symbol));
314 jsonAll[symbol.alias] = this.publishJSON(symbol);
320 File.write(Options.target+"/json/roodata.json",
328 // regenrate the index with different relative links
330 //var classesIndex = classesTemplate.process(classes);
332 Options.LOG.inform("build index");
334 File.write(Options.target + "/index."+ Options.publishExt,
335 classesindexTemplate.process(classes)
338 // blank everything???? classesindexTemplate = classesIndex = classes = null;
342 var documentedFiles = symbols.filter(function ($) {
343 return ($.is("FILE"))
348 for (var i = 0; i < files.length; i++) {
349 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
352 for (var i = 0; i < documentedFiles.length; i++) {
353 var offset = files.indexOf(documentedFiles[i].alias);
354 allFiles[offset] = documentedFiles[i];
357 allFiles = allFiles.sort(makeSortby("name"));
358 Options.LOG.inform("write files index");
360 File.write(Options.target + "/files."+Options.publishExt,
361 fileindexTemplate.process(allFiles)
369 * JSON files are lookup files for the documentation
370 * - can be used by IDE's or AJAX based doc tools
374 publishJSON : function(data)
376 // what we need to output to be usefull...
378 var cfgProperties = [];
379 if (!data.comment.getTag('singleton').length) {
380 cfgProperties = data.configToArray();
381 cfgProperties = cfgProperties.sort(makeSortby("alias"));
385 //println(cfgProperties.toSource());
387 for(var i =0; i < cfgProperties.length;i++) {
388 p = cfgProperties[i];
394 memberOf : p.memberOf == data.alias ? '' : p.memberOf
397 add.optvals = p.optvalues;
403 var ownEvents = data.methods.filter( function(e){
404 return e.isEvent && !e.comment.getTag('hide').length;
405 }).sort(makeSortby("name"));
410 for(var i =0; i < ownEvents.length;i++) {
413 name : m.name.substring(1),
414 sig : this.makeFuncSkel(m.params),
420 var ownMethods = data.methods.filter( function(e){
421 return !e.isEvent && !e.comment.getTag('hide').length;
422 }).sort(makeSortby("name"));
427 for(var i =0; i < ownMethods.length;i++) {
431 sig : this.makeMethodSkel(m.params),
437 //println(props.toSource());
438 // we need to output:
459 srcFileRelName : function(sourceFile)
461 return sourceFile.substring(Options.baseDir.length+1);
463 srcFileFlatName: function(sourceFile)
465 var name = this.srcFileRelName(sourceFile);
466 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
467 return name.replace(/\:/g, "_") + '.html'; //??;
471 makeSrcFile: function(sourceFile)
473 // this stuff works...
476 var name = this.srcFileFlatName(sourceFile);
478 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
479 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
480 File.write(Options.target+"/symbols/src/" + name,
482 '<title>' + sourceFile + '</title>' +
483 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
484 '</head><body class="highlightpage">' +
489 * used by JSON output to generate a function skeleton
491 makeFuncSkel :function(params) {
492 if (!params) return "function ()\n{\n\n}";
493 return "function (" +
496 return $.name.indexOf(".") == -1; // don't show config params in signature
498 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +
501 makeMethodSkel :function(params) {
502 if (!params) return "()";
506 return $.name.indexOf(".") == -1; // don't show config params in signature
508 ).map( function($) { return $.type + " " +( $.name == 'this' ? '_self' : $.name ); } ).join(", ") +