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..
87 File.list(Options.src[i] ).forEach(function($) {
88 if (Options['exclude-src'].indexOf($) > -1) {
91 var thisExt = $.split(".").pop().toLowerCase();
92 if (ext.indexOf(thisExt) < 0) {
95 _this.srcFiles.push(Options.src[i] + '/' + $);
99 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
100 return this.srcFiles;
103 * Parse the source files.
107 _parseSrcFiles : function()
111 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
113 var srcFile = this.srcFiles[i];
116 var cacheFile = !Options.cacheDirectory.length ? false :
117 Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
120 // disabled at present!@!!
122 if (cacheFile && File.exists(cacheFile)) {
125 var c_mt = File.mtime(cacheFile);
126 var o_mt = File.mtime(srcFile);
127 //println(c_mt.toSource());
128 // println(o_mt.toSource());
130 // this check does not appear to work according to the doc's - need to check it out.
132 if (c_mt > o_mt) { // cached time > original time!
133 // use the cached mtimes..
134 print("Read " + cacheFile);
135 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
137 if (typeof(v) != 'object') {
140 if (typeof(v['*_object']) == 'undefined') {
143 var cls = imports[v['*_object']][v['*_object']];
144 print(v['*_object']);
145 delete v['*_object'];
147 XObject.extend(ret, v);
150 //print("Add sybmols " + cacheFile);
151 for (var sy in syms._index) {
153 Parser.symbols.addSymbol(syms._index[sy]);
161 Options.LOG.inform("reading : " + srcFile);
162 src = File.read(srcFile);
165 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
169 var txs = new TextStream(src);
171 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
173 var ts = new TokenStream(tr.tokenize(txs));
175 Parser.parse(ts, srcFile);
178 File.write(cacheFile,
180 Parser.symbolsToObject(srcFile),
186 //var outstr = JSON.stringify(
187 // Parser.filesSymbols[srcFile]._index
189 //File.write(cacheFile, outstr);
202 publish : function() {
203 Options.LOG.inform("Publishing");
208 Options.LOG.inform("Making directories");
209 if (!File.isDirectory(Options.target))
210 File.mkdir(Options.target);
211 if (!File.isDirectory(Options.target+"/symbols"))
212 File.mkdir(Options.target+"/symbols");
213 if (!File.isDirectory(Options.target+"/symbols/src"))
214 File.mkdir(Options.target+"/symbols/src");
216 if (!File.isDirectory(Options.target +"/json")) {
217 File.mkdir(Options.target +"/json");
220 Options.LOG.inform("Copying files from static: " +Options.templateDir);
221 // copy everything in 'static' into
222 File.list(Options.templateDir + '/static').forEach(function (f) {
223 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
224 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
228 Options.LOG.inform("Setting up templates");
229 // used to check the details of things being linked to
230 Link.symbolSet = this.symbolSet;
233 Link.srcFileFlatName = this.srcFileFlatName;
234 Link.srcFileRelName = this.srcFileRelName;
236 var classTemplate = new Template({
237 templateFile : Options.templateDir + "/class.html",
240 var classesTemplate = new Template({
241 templateFile : Options.templateDir +"/allclasses.html",
244 var classesindexTemplate = new Template({
245 templateFile : Options.templateDir +"/index.html",
248 var fileindexTemplate = new Template({
249 templateFile : Options.templateDir +"/allfiles.html",
254 classTemplate.symbolSet = this.symbolSet;
257 function hasNoParent($) {
258 return ($.memberOf == "")
260 function isaFile($) {
261 return ($.is("FILE"))
263 function isaClass($) {
264 return ($.is("CONSTRUCTOR") || $.isNamespace);
276 var symbols = this.symbolSet.toArray();
278 var files = Options.srcFiles;
280 for (var i = 0, l = files.length; i < l; i++) {
282 var targetDir = Options.target + "/symbols/src/";
283 this.makeSrcFile(file, targetDir);
286 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
288 //Options.LOG.inform("classTemplate Process : all classes");
290 // var classesIndex = classesTemplate.process(classes); // kept in memory
292 Options.LOG.inform("iterate classes");
296 for (var i = 0, l = classes.length; i < l; i++) {
297 var symbol = classes[i];
300 Options.LOG.inform("classTemplate Process : " + symbol.alias);
305 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
306 classTemplate.process(symbol));
308 jsonAll[symbol.alias] = this.publishJSON(symbol);
314 File.write(Options.target+"/json/roodata.json",
322 // regenrate the index with different relative links
324 //var classesIndex = classesTemplate.process(classes);
326 Options.LOG.inform("build index");
328 File.write(Options.target + "/index."+ Options.publishExt,
329 classesindexTemplate.process(classes)
332 // blank everything???? classesindexTemplate = classesIndex = classes = null;
336 var documentedFiles = symbols.filter(function ($) {
337 return ($.is("FILE"))
342 for (var i = 0; i < files.length; i++) {
343 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
346 for (var i = 0; i < documentedFiles.length; i++) {
347 var offset = files.indexOf(documentedFiles[i].alias);
348 allFiles[offset] = documentedFiles[i];
351 allFiles = allFiles.sort(makeSortby("name"));
352 Options.LOG.inform("write files index");
354 File.write(Options.target + "/files."+Options.publishExt,
355 fileindexTemplate.process(allFiles)
363 * JSON files are lookup files for the documentation
364 * - can be used by IDE's or AJAX based doc tools
368 publishJSON : function(data)
370 // what we need to output to be usefull...
372 var cfgProperties = [];
373 if (!data.comment.getTag('singleton').length) {
374 cfgProperties = data.configToArray();
375 cfgProperties = cfgProperties.sort(makeSortby("alias"));
379 //println(cfgProperties.toSource());
381 for(var i =0; i < cfgProperties.length;i++) {
382 p = cfgProperties[i];
387 memberOf : p.memberOf == data.alias ? '' : p.memberOf
392 var ownEvents = data.methods.filter( function(e){
393 return e.isEvent && !e.comment.getTag('hide').length;
394 }).sort(makeSortby("name"));
399 for(var i =0; i < ownEvents.length;i++) {
402 name : m.name.substring(1),
403 sig : this.makeFuncSkel(m.params),
408 //println(props.toSource());
409 // we need to output:
429 srcFileRelName : function(sourceFile)
431 return sourceFile.substring(Options.baseDir.length+1);
433 srcFileFlatName: function(sourceFile)
435 var name = this.srcFileRelName(sourceFile);
436 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
437 return name.replace(/\:/g, "_") + '.html'; //??;
441 makeSrcFile: function(sourceFile)
443 // this stuff works...
446 var name = this.srcFileFlatName(sourceFile);
448 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
449 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
450 File.write(Options.target+"/symbols/src/" + name,
452 '<title>' + sourceFile + '</title>' +
453 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
454 '</head><body class="highlightpage">' +
459 * used by JSON output to generate a function skeleton
461 makeFuncSkel :function(params) {
462 if (!params) return "function ()\n{\n\n}";
463 return "function (" +
466 return $.name.indexOf(".") == -1; // don't show config params in signature
468 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +