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));
136 throw "Conversion of cache not done yet!";
138 for (var sy in syms) {
139 //println("ADD:" + sy );
140 Parser.symbols.addSymbol(syms[sy]);
148 Options.LOG.inform("reading : " + srcFile);
149 src = File.read(srcFile);
152 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
156 var txs = new TextStream(src);
158 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
160 var ts = new TokenStream(tr.tokenize(txs));
162 Parser.parse(ts, srcFile);
165 File.write(cacheFile,
167 Parser.symbolsToObject(srcFile)
172 //var outstr = JSON.stringify(
173 // Parser.filesSymbols[srcFile]._index
175 //File.write(cacheFile, outstr);
188 publish : function() {
189 Options.LOG.inform("Publishing");
194 Options.LOG.inform("Making directories");
195 if (!File.isDirectory(Options.target))
196 File.mkdir(Options.target);
197 if (!File.isDirectory(Options.target+"/symbols"))
198 File.mkdir(Options.target+"/symbols");
199 if (!File.isDirectory(Options.target+"/symbols/src"))
200 File.mkdir(Options.target+"/symbols/src");
202 if (!File.isDirectory(Options.target +"/json")) {
203 File.mkdir(Options.target +"/json");
206 Options.LOG.inform("Copying files from static: " +Options.templateDir);
207 // copy everything in 'static' into
208 File.list(Options.templateDir + '/static').forEach(function (f) {
209 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
210 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
214 Options.LOG.inform("Setting up templates");
215 // used to check the details of things being linked to
216 Link.symbolSet = this.symbolSet;
219 Link.srcFileFlatName = this.srcFileFlatName;
220 Link.srcFileRelName = this.srcFileRelName;
222 var classTemplate = new Template({
223 templateFile : Options.templateDir + "/class.html",
226 var classesTemplate = new Template({
227 templateFile : Options.templateDir +"/allclasses.html",
230 var classesindexTemplate = new Template({
231 templateFile : Options.templateDir +"/index.html",
234 var fileindexTemplate = new Template({
235 templateFile : Options.templateDir +"/allfiles.html",
240 classTemplate.symbolSet = this.symbolSet;
243 function hasNoParent($) {
244 return ($.memberOf == "")
246 function isaFile($) {
247 return ($.is("FILE"))
249 function isaClass($) {
250 return ($.is("CONSTRUCTOR") || $.isNamespace);
262 var symbols = this.symbolSet.toArray();
264 var files = Options.srcFiles;
266 for (var i = 0, l = files.length; i < l; i++) {
268 var targetDir = Options.target + "/symbols/src/";
269 this.makeSrcFile(file, targetDir);
272 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
274 //Options.LOG.inform("classTemplate Process : all classes");
276 // var classesIndex = classesTemplate.process(classes); // kept in memory
278 Options.LOG.inform("iterate classes");
282 for (var i = 0, l = classes.length; i < l; i++) {
283 var symbol = classes[i];
286 Options.LOG.inform("classTemplate Process : " + symbol.alias);
291 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
292 classTemplate.process(symbol));
294 jsonAll[symbol.alias] = this.publishJSON(symbol);
300 File.write(Options.target+"/json/roodata.json",
308 // regenrate the index with different relative links
310 //var classesIndex = classesTemplate.process(classes);
312 Options.LOG.inform("build index");
314 File.write(Options.target + "/index."+ Options.publishExt,
315 classesindexTemplate.process(classes)
318 // blank everything???? classesindexTemplate = classesIndex = classes = null;
322 var documentedFiles = symbols.filter(function ($) {
323 return ($.is("FILE"))
328 for (var i = 0; i < files.length; i++) {
329 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
332 for (var i = 0; i < documentedFiles.length; i++) {
333 var offset = files.indexOf(documentedFiles[i].alias);
334 allFiles[offset] = documentedFiles[i];
337 allFiles = allFiles.sort(makeSortby("name"));
338 Options.LOG.inform("write files index");
340 File.write(Options.target + "/files."+Options.publishExt,
341 fileindexTemplate.process(allFiles)
349 * JSON files are lookup files for the documentation
350 * - can be used by IDE's or AJAX based doc tools
354 publishJSON : function(data)
356 // what we need to output to be usefull...
358 var cfgProperties = [];
359 if (!data.comment.getTag('singleton').length) {
360 cfgProperties = data.configToArray();
361 cfgProperties = cfgProperties.sort(makeSortby("alias"));
365 //println(cfgProperties.toSource());
367 for(var i =0; i < cfgProperties.length;i++) {
368 p = cfgProperties[i];
373 memberOf : p.memberOf == data.alias ? '' : p.memberOf
378 var ownEvents = data.methods.filter( function(e){
379 return e.isEvent && !e.comment.getTag('hide').length;
380 }).sort(makeSortby("name"));
385 for(var i =0; i < ownEvents.length;i++) {
388 name : m.name.substring(1),
389 sig : this.makeFuncSkel(m.params),
394 //println(props.toSource());
395 // we need to output:
415 srcFileRelName : function(sourceFile)
417 return sourceFile.substring(Options.baseDir.length+1);
419 srcFileFlatName: function(sourceFile)
421 var name = this.srcFileRelName(sourceFile);
422 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
423 return name.replace(/\:/g, "_") + '.html'; //??;
427 makeSrcFile: function(sourceFile)
429 // this stuff works...
432 var name = this.srcFileFlatName(sourceFile);
434 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
435 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
436 File.write(Options.target+"/symbols/src/" + name,
438 '<title>' + sourceFile + '</title>' +
439 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
440 '</head><body class="highlightpage">' +
445 * used by JSON output to generate a function skeleton
447 makeFuncSkel :function(params) {
448 if (!params) return "function ()\n{\n\n}";
449 return "function (" +
452 return $.name.indexOf(".") == -1; // don't show config params in signature
454 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +