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];
118 Options.LOG.inform("reading i : " + i + " length : " + this.srcFiles.length);
122 var cacheFile = !Options.cacheDirectory.length ? false :
123 Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
126 // disabled at present!@!!
128 if (cacheFile && File.exists(cacheFile)) {
131 var c_mt = File.mtime(cacheFile);
132 var o_mt = File.mtime(srcFile);
133 //println(c_mt.toSource());
134 // println(o_mt.toSource());
136 // this check does not appear to work according to the doc's - need to check it out.
138 if (c_mt > o_mt) { // cached time > original time!
139 // use the cached mtimes..
140 print("Read " + cacheFile);
141 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
143 if (typeof(v) != 'object') {
146 if (typeof(v['*object']) == 'undefined') {
149 var cls = imports[v['*object']][v['*object']];
150 //print(v['*object']);
153 XObject.extend(ret, v);
158 //print("Add sybmols " + cacheFile);
159 for (var sy in syms._index) {
160 // print("ADD:" + sy );
161 Parser.symbols.addSymbol(syms._index[sy]);
169 Options.LOG.inform("reading : " + srcFile);
170 src = File.read(srcFile);
173 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
177 var txs = new TextStream(src);
179 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
181 var ts = new TokenStream(tr.tokenize(txs));
183 Parser.parse(ts, srcFile);
186 File.write(cacheFile,
188 Parser.symbolsToObject(srcFile),
194 //var outstr = JSON.stringify(
195 // Parser.filesSymbols[srcFile]._index
197 //File.write(cacheFile, outstr);
210 publish : function() {
211 Options.LOG.inform("Publishing");
216 Options.LOG.inform("Making directories");
217 if (!File.isDirectory(Options.target))
218 File.mkdir(Options.target);
219 if (!File.isDirectory(Options.target+"/symbols"))
220 File.mkdir(Options.target+"/symbols");
221 if (!File.isDirectory(Options.target+"/symbols/src"))
222 File.mkdir(Options.target+"/symbols/src");
224 if (!File.isDirectory(Options.target +"/json")) {
225 File.mkdir(Options.target +"/json");
228 Options.LOG.inform("Copying files from static: " +Options.templateDir);
229 // copy everything in 'static' into
230 File.list(Options.templateDir + '/static').forEach(function (f) {
231 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
232 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
236 Options.LOG.inform("Setting up templates");
237 // used to check the details of things being linked to
238 Link.symbolSet = this.symbolSet;
241 Link.srcFileFlatName = this.srcFileFlatName;
242 Link.srcFileRelName = this.srcFileRelName;
244 var classTemplate = new Template({
245 templateFile : Options.templateDir + "/class.html",
248 var classesTemplate = new Template({
249 templateFile : Options.templateDir +"/allclasses.html",
252 var classesindexTemplate = new Template({
253 templateFile : Options.templateDir +"/index.html",
256 var fileindexTemplate = new Template({
257 templateFile : Options.templateDir +"/allfiles.html",
262 classTemplate.symbolSet = this.symbolSet;
265 function hasNoParent($) {
266 return ($.memberOf == "")
268 function isaFile($) {
269 return ($.is("FILE"))
271 function isaClass($) {
272 return ($.is("CONSTRUCTOR") || $.isNamespace);
284 var symbols = this.symbolSet.toArray();
286 var files = Options.srcFiles;
288 for (var i = 0, l = files.length; i < l; i++) {
290 var targetDir = Options.target + "/symbols/src/";
291 this.makeSrcFile(file, targetDir);
294 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
296 //Options.LOG.inform("classTemplate Process : all classes");
298 // var classesIndex = classesTemplate.process(classes); // kept in memory
300 Options.LOG.inform("iterate classes");
304 for (var i = 0, l = classes.length; i < l; i++) {
305 var symbol = classes[i];
308 Options.LOG.inform("classTemplate Process : " + symbol.alias);
313 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
314 classTemplate.process(symbol));
316 jsonAll[symbol.alias] = this.publishJSON(symbol);
322 File.write(Options.target+"/json/roodata.json",
330 // regenrate the index with different relative links
332 //var classesIndex = classesTemplate.process(classes);
334 Options.LOG.inform("build index");
336 File.write(Options.target + "/index."+ Options.publishExt,
337 classesindexTemplate.process(classes)
340 // blank everything???? classesindexTemplate = classesIndex = classes = null;
344 var documentedFiles = symbols.filter(function ($) {
345 return ($.is("FILE"))
350 for (var i = 0; i < files.length; i++) {
351 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
354 for (var i = 0; i < documentedFiles.length; i++) {
355 var offset = files.indexOf(documentedFiles[i].alias);
356 allFiles[offset] = documentedFiles[i];
359 allFiles = allFiles.sort(makeSortby("name"));
360 Options.LOG.inform("write files index");
362 File.write(Options.target + "/files."+Options.publishExt,
363 fileindexTemplate.process(allFiles)
371 * JSON files are lookup files for the documentation
372 * - can be used by IDE's or AJAX based doc tools
376 publishJSON : function(data)
378 // what we need to output to be usefull...
380 var cfgProperties = [];
381 if (!data.comment.getTag('singleton').length) {
382 cfgProperties = data.configToArray();
383 cfgProperties = cfgProperties.sort(makeSortby("alias"));
387 //println(cfgProperties.toSource());
389 for(var i =0; i < cfgProperties.length;i++) {
390 p = cfgProperties[i];
395 memberOf : p.memberOf == data.alias ? '' : p.memberOf
400 var ownEvents = data.methods.filter( function(e){
401 return e.isEvent && !e.comment.getTag('hide').length;
402 }).sort(makeSortby("name"));
407 for(var i =0; i < ownEvents.length;i++) {
410 name : m.name.substring(1),
411 sig : this.makeFuncSkel(m.params),
416 //println(props.toSource());
417 // we need to output:
437 srcFileRelName : function(sourceFile)
439 return sourceFile.substring(Options.baseDir.length+1);
441 srcFileFlatName: function(sourceFile)
443 var name = this.srcFileRelName(sourceFile);
444 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
445 return name.replace(/\:/g, "_") + '.html'; //??;
449 makeSrcFile: function(sourceFile)
451 // this stuff works...
454 var name = this.srcFileFlatName(sourceFile);
456 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
457 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
458 File.write(Options.target+"/symbols/src/" + name,
460 '<title>' + sourceFile + '</title>' +
461 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
462 '</head><body class="highlightpage">' +
467 * used by JSON output to generate a function skeleton
469 makeFuncSkel :function(params) {
470 if (!params) return "function ()\n{\n\n}";
471 return "function (" +
474 return $.name.indexOf(".") == -1; // don't show config params in signature
476 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +