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;
21 /****************** INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
23 // should not realy be here -- or anywhere...??
25 function makeSortby(attribute) {
26 return function(a, b) {
27 if (a[attribute] != undefined && b[attribute] != undefined) {
28 a = a[attribute]; //.toLowerCase();
29 b = b[attribute];//.toLowerCase();
37 Options = false; // refer to this everywhere!
48 build : function (opts)
53 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
54 //Options.LOG.inform("With options: ");
56 if (Options.cacheDirectory.length && !File.isDirectory(Options.cacheDirectory)) {
57 File.mkdir(Options.cacheDirectory)
60 Options.srcFiles = this._getSrcFiles();
61 this._parseSrcFiles();
62 this.symbolSet = Parser.symbols;
64 // this currently uses the concept of publish.js...
73 _getSrcFiles : function()
79 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
82 for (var i = 0; i < Options.src.length; i++) {
83 // add to sourcefiles..
85 File.list(Options.src[i] ).forEach(function($) {
86 if (Options['exclude-src'].indexOf($) > -1) {
89 var thisExt = $.split(".").pop().toLowerCase();
90 if (ext.indexOf(thisExt) < 0) {
93 _this.srcFiles.push(Options.src[i] + '/' + $);
97 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
101 _parseSrcFiles : function()
105 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
107 var srcFile = this.srcFiles[i];
110 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
112 //println(cacheFile);
113 // disabled at present!@!!
115 if (false && !Options.disablecache && File.exists(cacheFile)) {
118 var c_mt = File.getTimes(cacheFile);
119 var o_mt = File.getTimes(srcFile);
120 //println(c_mt.toSource());
121 // println(o_mt.toSource());
123 // this check does not appear to work according to the doc's - need to check it out.
125 if (c_mt[0] > o_mt[0]) { // cached time > original time!
126 // use the cached mtimes..
127 var syms = JSON.parse(File.read(cacheFile));
129 throw "Conversion of cache not done yet!";
131 for (var sy in syms) {
132 //println("ADD:" + sy );
133 Parser.symbols.addSymbol(syms[sy]);
141 Options.LOG.inform("reading : " + srcFile);
142 src = File.read(srcFile);
145 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
149 var txs = new TextStream(src);
151 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
153 var ts = new TokenStream(tr.tokenize(txs));
155 Parser.parse(ts, srcFile);
157 //var outstr = JSON.stringify(
158 // Parser.filesSymbols[srcFile]._index
160 //File.write(cacheFile, outstr);
173 publish : function() {
174 Options.LOG.inform("Publishing");
179 Options.LOG.inform("Making directories");
180 if (!File.isDirectory(Options.target))
181 File.mkdir(Options.target);
182 if (!File.isDirectory(Options.target+"/symbols"))
183 File.mkdir(Options.target+"/symbols");
184 if (!File.isDirectory(Options.target+"/symbols/src"))
185 File.mkdir(Options.target+"/symbols/src");
187 if (!File.isDirectory(Options.target +"/json")) {
188 File.mkdir(Options.target +"/json");
191 Options.LOG.inform("Copying files from static: " +Options.templateDir);
192 // copy everything in 'static' into
193 File.list(Options.templateDir + '/static').forEach(function (f) {
194 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
195 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
199 Options.LOG.inform("Setting up templates");
200 // used to check the details of things being linked to
201 Link.symbolSet = this.symbolSet;
204 Link.srcFileFlatName = this.srcFileFlatName;
205 Link.srcFileRelName = this.srcFileRelName;
207 var classTemplate = new Template({
208 templateFile : Options.templateDir + "/class.html",
211 var classesTemplate = new Template({
212 templateFile : Options.templateDir +"/allclasses.html",
215 var classesindexTemplate = new Template({
216 templateFile : Options.templateDir +"/index.html",
219 var fileindexTemplate = new Template({
220 templateFile : Options.templateDir +"/allfiles.html",
225 classTemplate.symbolSet = this.symbolSet;
228 function hasNoParent($) {
229 return ($.memberOf == "")
231 function isaFile($) {
232 return ($.is("FILE"))
234 function isaClass($) {
235 return ($.is("CONSTRUCTOR") || $.isNamespace);
247 var symbols = this.symbolSet.toArray();
249 var files = Options.srcFiles;
251 for (var i = 0, l = files.length; i < l; i++) {
253 var targetDir = Options.target + "/symbols/src/";
254 this.makeSrcFile(file, targetDir);
257 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
259 //Options.LOG.inform("classTemplate Process : all classes");
261 // var classesIndex = classesTemplate.process(classes); // kept in memory
263 Options.LOG.inform("iterate classes");
267 for (var i = 0, l = classes.length; i < l; i++) {
268 var symbol = classes[i];
271 Options.LOG.inform("classTemplate Process : " + symbol.alias);
276 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
277 classTemplate.process(symbol));
279 jsonAll[symbol.alias] = this.publishJSON(symbol);
285 File.write(Options.target+"/json/roodata.json",
293 // regenrate the index with different relative links
295 //var classesIndex = classesTemplate.process(classes);
297 Options.LOG.inform("build index");
299 File.write(Options.target + "/index."+ Options.publishExt,
300 classesindexTemplate.process(classes)
303 // blank everything???? classesindexTemplate = classesIndex = classes = null;
307 var documentedFiles = symbols.filter(function ($) {
308 return ($.is("FILE"))
313 for (var i = 0; i < files.length; i++) {
314 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
317 for (var i = 0; i < documentedFiles.length; i++) {
318 var offset = files.indexOf(documentedFiles[i].alias);
319 allFiles[offset] = documentedFiles[i];
322 allFiles = allFiles.sort(makeSortby("name"));
323 Options.LOG.inform("write files index");
325 File.write(Options.target + "/files."+Options.publishExt,
326 fileindexTemplate.process(allFiles)
334 * JSON files are lookup files for the documentation
335 * - can be used by IDE's or AJAX based doc tools
339 publishJSON : function(data)
341 // what we need to output to be usefull...
343 var cfgProperties = [];
344 if (!data.comment.getTag('singleton').length) {
345 cfgProperties = data.configToArray();
346 cfgProperties = cfgProperties.sort(makeSortby("name"));
350 //println(cfgProperties.toSource());
352 for(var i =0; i < cfgProperties.length;i++) {
353 p = cfgProperties[i];
358 memberOf : p.memberOf == data.alias ? '' : p.memberOf
363 var ownEvents = data.methods.filter( function(e){
364 return e.isEvent && !e.comment.getTag('hide').length;
365 }).sort(makeSortby("name"));
370 for(var i =0; i < ownEvents.length;i++) {
373 name : m.name.substring(1),
374 sig : this.makeFuncSkel(m.params),
379 //println(props.toSource());
380 // we need to output:
400 srcFileRelName : function(sourceFile)
402 return sourceFile.substring(Options.baseDir.length+1);
404 srcFileFlatName: function(sourceFile)
406 var name = this.srcFileRelName(sourceFile);
407 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
408 return name.replace(/\:/g, "_") + '.html'; //??;
412 makeSrcFile: function(sourceFile)
414 // this stuff works...
417 var name = this.srcFileFlatName(sourceFile);
419 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
420 var pretty = imports.PrettyPrint.toPretty(File.read( sourceFile));
421 File.write(Options.target+"/symbols/src/" + name,
423 '<title>' + sourceFile + '</title>' +
424 '<link rel="stylesheet" type="text/css" href="../../../css/highlight-js.css"/>' +
425 '</head><body class="highlightpage">' +
430 * used by JSON output to generate a function skeleton
432 makeFuncSkel :function(params) {
433 if (!params) return "function ()\n{\n\n}";
434 return "function (" +
437 return $.name.indexOf(".") == -1; // don't show config params in signature
439 ).map( function($) { return $.name == 'this' ? '_self' : $.name; } ).join(", ") +