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']);
147 XObject.extend(ret, v);
152 //print("Add sybmols " + cacheFile);
153 for (var sy in syms._index) {
154 // print("ADD:" + sy );
155 Parser.symbols.addSymbol(syms._index[sy]);
163 Options.LOG.inform("reading : " + srcFile);
164 src = File.read(srcFile);
167 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
171 var txs = new TextStream(src);
173 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
175 var ts = new TokenStream(tr.tokenize(txs));
177 Parser.parse(ts, srcFile);
180 File.write(cacheFile,
182 Parser.symbolsToObject(srcFile),
188 //var outstr = JSON.stringify(
189 // Parser.filesSymbols[srcFile]._index
191 //File.write(cacheFile, outstr);
204 publish : function() {
205 Options.LOG.inform("Publishing");
210 Options.LOG.inform("Making directories");
211 if (!File.isDirectory(Options.target))
212 File.mkdir(Options.target);
213 if (!File.isDirectory(Options.target+"/symbols"))
214 File.mkdir(Options.target+"/symbols");
215 if (!File.isDirectory(Options.target+"/symbols/src"))
216 File.mkdir(Options.target+"/symbols/src");
218 if (!File.isDirectory(Options.target +"/json")) {
219 File.mkdir(Options.target +"/json");
222 Options.LOG.inform("Copying files from static: " +Options.templateDir);
223 // copy everything in 'static' into
224 File.list(Options.templateDir + '/static').forEach(function (f) {
225 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
226 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
230 Options.LOG.inform("Setting up templates");
231 // used to check the details of things being linked to
232 Link.symbolSet = this.symbolSet;
235 Link.srcFileFlatName = this.srcFileFlatName;
236 Link.srcFileRelName = this.srcFileRelName;
238 var classTemplate = new Template({
239 templateFile : Options.templateDir + "/class.html",
242 var classesTemplate = new Template({
243 templateFile : Options.templateDir +"/allclasses.html",
246 var classesindexTemplate = new Template({
247 templateFile : Options.templateDir +"/index.html",
250 var fileindexTemplate = new Template({
251 templateFile : Options.templateDir +"/allfiles.html",
256 classTemplate.symbolSet = this.symbolSet;
259 function hasNoParent($) {
260 return ($.memberOf == "")
262 function isaFile($) {
263 return ($.is("FILE"))
265 function isaClass($) {
266 return ($.is("CONSTRUCTOR") || $.isNamespace);
278 var symbols = this.symbolSet.toArray();
280 var files = Options.srcFiles;
282 for (var i = 0, l = files.length; i < l; i++) {
284 var targetDir = Options.target + "/symbols/src/";
285 this.makeSrcFile(file, targetDir);
288 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
290 //Options.LOG.inform("classTemplate Process : all classes");
292 // var classesIndex = classesTemplate.process(classes); // kept in memory
294 Options.LOG.inform("iterate classes");
298 for (var i = 0, l = classes.length; i < l; i++) {
299 var symbol = classes[i];
302 Options.LOG.inform("classTemplate Process : " + symbol.alias);
307 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
308 classTemplate.process(symbol));
310 jsonAll[symbol.alias] = this.publishJSON(symbol);
316 File.write(Options.target+"/json/roodata.json",
324 // regenrate the index with different relative links
326 //var classesIndex = classesTemplate.process(classes);
328 Options.LOG.inform("build index");
330 File.write(Options.target + "/index."+ Options.publishExt,
331 classesindexTemplate.process(classes)
334 // blank everything???? classesindexTemplate = classesIndex = classes = null;
338 var documentedFiles = symbols.filter(function ($) {
339 return ($.is("FILE"))
344 for (var i = 0; i < files.length; i++) {
345 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
348 for (var i = 0; i < documentedFiles.length; i++) {
349 var offset = files.indexOf(documentedFiles[i].alias);
350 allFiles[offset] = documentedFiles[i];
353 allFiles = allFiles.sort(makeSortby("name"));
354 Options.LOG.inform("write files index");
356 File.write(Options.target + "/files."+Options.publishExt,
357 fileindexTemplate.process(allFiles)
365 * JSON files are lookup files for the documentation
366 * - can be used by IDE's or AJAX based doc tools
370 publishJSON : function(data)
372 // what we need to output to be usefull...
374 var cfgProperties = [];
375 if (!data.comment.getTag('singleton').length) {
376 cfgProperties = data.configToArray();
377 cfgProperties = cfgProperties.sort(makeSortby("alias"));
381 //println(cfgProperties.toSource());
383 for(var i =0; i < cfgProperties.length;i++) {
384 p = cfgProperties[i];
389 memberOf : p.memberOf == data.alias ? '' : p.memberOf
394 var ownEvents = data.methods.filter( function(e){
395 return e.isEvent && !e.comment.getTag('hide').length;
396 }).sort(makeSortby("name"));
401 for(var i =0; i < ownEvents.length;i++) {
404 name : m.name.substring(1),
405 sig : this.makeFuncSkel(m.params),
410 //println(props.toSource());
411 // we need to output:
431 srcFileRelName : function(sourceFile)
433 return sourceFile.substring(Options.baseDir.length+1);
435 srcFileFlatName: function(sourceFile)
437 var name = this.srcFileRelName(sourceFile);
438 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
439 return name.replace(/\:/g, "_") + '.html'; //??;
443 makeSrcFile: function(sourceFile)
445 // this stuff works...
448 var name = this.srcFileFlatName(sourceFile);
450 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
451 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
452 File.write(Options.target+"/symbols/src/" + name,
454 '<title>' + sourceFile + '</title>' +
455 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
456 '</head><body class="highlightpage">' +
461 * used by JSON output to generate a function skeleton
463 makeFuncSkel :function(params) {
464 if (!params) return "function ()\n{\n\n}";
465 return "function (" +
468 return $.name.indexOf(".") == -1; // don't show config params in signature
470 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +