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 var syms = JSON.parse(File.read(cacheFile), function(k, v) {
135 if (typeof(v) != 'object') {
138 if (typeof(v._object) == 'undefined') {
141 var cls = imports[v._object][v._object];
145 XObject.extend(ret, v);
149 for (var sy in syms) {
150 //println("ADD:" + sy );
151 Parser.symbols.addSymbol(syms[sy]);
159 Options.LOG.inform("reading : " + srcFile);
160 src = File.read(srcFile);
163 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
167 var txs = new TextStream(src);
169 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
171 var ts = new TokenStream(tr.tokenize(txs));
173 Parser.parse(ts, srcFile);
176 File.write(cacheFile,
178 Parser.symbolsToObject(srcFile),
184 //var outstr = JSON.stringify(
185 // Parser.filesSymbols[srcFile]._index
187 //File.write(cacheFile, outstr);
200 publish : function() {
201 Options.LOG.inform("Publishing");
206 Options.LOG.inform("Making directories");
207 if (!File.isDirectory(Options.target))
208 File.mkdir(Options.target);
209 if (!File.isDirectory(Options.target+"/symbols"))
210 File.mkdir(Options.target+"/symbols");
211 if (!File.isDirectory(Options.target+"/symbols/src"))
212 File.mkdir(Options.target+"/symbols/src");
214 if (!File.isDirectory(Options.target +"/json")) {
215 File.mkdir(Options.target +"/json");
218 Options.LOG.inform("Copying files from static: " +Options.templateDir);
219 // copy everything in 'static' into
220 File.list(Options.templateDir + '/static').forEach(function (f) {
221 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
222 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
226 Options.LOG.inform("Setting up templates");
227 // used to check the details of things being linked to
228 Link.symbolSet = this.symbolSet;
231 Link.srcFileFlatName = this.srcFileFlatName;
232 Link.srcFileRelName = this.srcFileRelName;
234 var classTemplate = new Template({
235 templateFile : Options.templateDir + "/class.html",
238 var classesTemplate = new Template({
239 templateFile : Options.templateDir +"/allclasses.html",
242 var classesindexTemplate = new Template({
243 templateFile : Options.templateDir +"/index.html",
246 var fileindexTemplate = new Template({
247 templateFile : Options.templateDir +"/allfiles.html",
252 classTemplate.symbolSet = this.symbolSet;
255 function hasNoParent($) {
256 return ($.memberOf == "")
258 function isaFile($) {
259 return ($.is("FILE"))
261 function isaClass($) {
262 return ($.is("CONSTRUCTOR") || $.isNamespace);
274 var symbols = this.symbolSet.toArray();
276 var files = Options.srcFiles;
278 for (var i = 0, l = files.length; i < l; i++) {
280 var targetDir = Options.target + "/symbols/src/";
281 this.makeSrcFile(file, targetDir);
284 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
286 //Options.LOG.inform("classTemplate Process : all classes");
288 // var classesIndex = classesTemplate.process(classes); // kept in memory
290 Options.LOG.inform("iterate classes");
294 for (var i = 0, l = classes.length; i < l; i++) {
295 var symbol = classes[i];
298 Options.LOG.inform("classTemplate Process : " + symbol.alias);
303 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
304 classTemplate.process(symbol));
306 jsonAll[symbol.alias] = this.publishJSON(symbol);
312 File.write(Options.target+"/json/roodata.json",
320 // regenrate the index with different relative links
322 //var classesIndex = classesTemplate.process(classes);
324 Options.LOG.inform("build index");
326 File.write(Options.target + "/index."+ Options.publishExt,
327 classesindexTemplate.process(classes)
330 // blank everything???? classesindexTemplate = classesIndex = classes = null;
334 var documentedFiles = symbols.filter(function ($) {
335 return ($.is("FILE"))
340 for (var i = 0; i < files.length; i++) {
341 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
344 for (var i = 0; i < documentedFiles.length; i++) {
345 var offset = files.indexOf(documentedFiles[i].alias);
346 allFiles[offset] = documentedFiles[i];
349 allFiles = allFiles.sort(makeSortby("name"));
350 Options.LOG.inform("write files index");
352 File.write(Options.target + "/files."+Options.publishExt,
353 fileindexTemplate.process(allFiles)
361 * JSON files are lookup files for the documentation
362 * - can be used by IDE's or AJAX based doc tools
366 publishJSON : function(data)
368 // what we need to output to be usefull...
370 var cfgProperties = [];
371 if (!data.comment.getTag('singleton').length) {
372 cfgProperties = data.configToArray();
373 cfgProperties = cfgProperties.sort(makeSortby("alias"));
377 //println(cfgProperties.toSource());
379 for(var i =0; i < cfgProperties.length;i++) {
380 p = cfgProperties[i];
385 memberOf : p.memberOf == data.alias ? '' : p.memberOf
390 var ownEvents = data.methods.filter( function(e){
391 return e.isEvent && !e.comment.getTag('hide').length;
392 }).sort(makeSortby("name"));
397 for(var i =0; i < ownEvents.length;i++) {
400 name : m.name.substring(1),
401 sig : this.makeFuncSkel(m.params),
406 //println(props.toSource());
407 // we need to output:
427 srcFileRelName : function(sourceFile)
429 return sourceFile.substring(Options.baseDir.length+1);
431 srcFileFlatName: function(sourceFile)
433 var name = this.srcFileRelName(sourceFile);
434 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
435 return name.replace(/\:/g, "_") + '.html'; //??;
439 makeSrcFile: function(sourceFile)
441 // this stuff works...
444 var name = this.srcFileFlatName(sourceFile);
446 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
447 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
448 File.write(Options.target+"/symbols/src/" + name,
450 '<title>' + sourceFile + '</title>' +
451 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
452 '</head><body class="highlightpage">' +
457 * used by JSON output to generate a function skeleton
459 makeFuncSkel :function(params) {
460 if (!params) return "function ()\n{\n\n}";
461 return "function (" +
464 return $.name.indexOf(".") == -1; // don't show config params in signature
466 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +