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 /****************** INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
21 // should not realy be here -- or anywhere...??
24 Options = false; // refer to this everywhere!
35 build : function (opts)
40 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
41 //Options.LOG.inform("With options: ");
43 if (Options.cacheDirectory.length && !File.isDirectory(Options.cacheDirectory)) {
44 File.mkdir(Options.cacheDirectory)
47 Options.srcFiles = this._getSrcFiles();
48 this._parseSrcFiles();
49 this.symbolSet = Parser.symbols;
51 // this currently uses the concept of publish.js...
60 _getSrcFiles : function()
66 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
69 for (var i = 0; i < Options.src.length; i++) {
70 // add to sourcefiles..
72 File.list(Options.src[i] ).forEach(function($) {
73 if (Options['exclude-src'].indexOf($) > -1) {
76 var thisExt = $.split(".").pop().toLowerCase();
77 if (ext.indexOf(thisExt) < 0) {
80 _this.srcFiles.push(Options.src[i] + '/' + $);
84 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
88 _parseSrcFiles : function()
92 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
94 var srcFile = this.srcFiles[i];
97 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
100 // disabled at present!@!!
102 if (false && !Options.disablecache && File.exists(cacheFile)) {
105 var c_mt = File.getTimes(cacheFile);
106 var o_mt = File.getTimes(srcFile);
107 //println(c_mt.toSource());
108 // println(o_mt.toSource());
110 // this check does not appear to work according to the doc's - need to check it out.
112 if (c_mt[0] > o_mt[0]) { // cached time > original time!
113 // use the cached mtimes..
114 var syms = JSON.parse(File.read(cacheFile));
116 throw "Conversion of cache not done yet!";
118 for (var sy in syms) {
119 //println("ADD:" + sy );
120 Parser.symbols.addSymbol(syms[sy]);
128 Options.LOG.inform("reading : " + srcFile);
129 src = File.read(srcFile);
132 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
136 var txs = new TextStream(src);
138 var tr = new TokenReader({ keepComments : true, keepWhite : true });
140 var ts = new TokenStream(tr.tokenize(txs));
142 Parser.parse(ts, srcFile);
144 //var outstr = JSON.stringify(
145 // Parser.filesSymbols[srcFile]._index
147 //File.write(cacheFile, outstr);
160 publish : function() {
161 Options.LOG.inform("Publishing");
166 Options.LOG.inform("Making directories");
167 if (!File.isDirectory(Options.target))
168 File.mkdir(Options.target);
169 if (!File.isDirectory(Options.target+"/symbols"))
170 File.mkdir(Options.target+"/symbols");
171 if (!File.isDirectory(Options.target+"/symbols/src"))
172 File.mkdir(Options.target+"/symbols/src");
174 if (!File.isDirectory(Options.target +"/json")) {
175 File.mkdir(Options.target +"/json");
178 Options.LOG.inform("Copying files from static: " +Options.templateDir);
179 // copy everything in 'static' into
180 File.list(Options.templateDir + '/static').forEach(function (f) {
181 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
182 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
186 Options.LOG.inform("Setting up templates");
187 // used to check the details of things being linked to
188 Link.symbolSet = this.symbolSet;
191 var classTemplate = new Template({
192 templateFile : Options.templateDir + "/class.tmpl",
195 var classesTemplate = new Template({
196 templateFile : Options.templateDir +"/allclasses.tmpl",
199 var classesindexTemplate = new Template({
200 templateFile : Options.templateDir +"/index.tmpl",
203 var fileindexTemplate = new Template({
204 templateFile : Options.templateDir +"/allfiles.tmpl",
209 classTemplate.symbolSet = this.symbolSet;
212 function hasNoParent($) {
213 return ($.memberOf == "")
215 function isaFile($) {
216 return ($.is("FILE"))
218 function isaClass($) {
219 return ($.is("CONSTRUCTOR") || $.isNamespace);
222 var symbols = this.symbolSet.toArray();
224 var files = Options.srcFiles;
226 for (var i = 0, l = files.length; i < l; i++) {
228 var targetDir = Options.target + "/symbols/src/";
229 this.makeSrcFile(file, targetDir);
232 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
234 var classesIndex = classesTemplate.process(classes); // kept in memory
238 for (var i = 0, l = classes.length; i < l; i++) {
239 var symbol = classes[i];
242 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
243 classTemplate.process(symbol));
245 print("write " + Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt);
249 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
255 // regenrate the index with different relative links
257 var classesIndex = classesTemplate.process(classes);
261 File.write(Options.target + "/index."+ Options.publishExt,
262 classesindexTemplate.process(classes)
265 // blank everything???? classesindexTemplate = classesIndex = classes = null;
269 var documentedFiles = symbols.filter(function ($) {
270 return ($.is("FILE"))
275 for (var i = 0; i < files.length; i++) {
276 allFiles.push(new Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
279 for (var i = 0; i < documentedFiles.length; i++) {
280 var offset = files.indexOf(documentedFiles[i].alias);
281 allFiles[offset] = documentedFiles[i];
284 allFiles = allFiles.sort(makeSortby("name"));
285 File.write(Options.target , "/files."+Options.publishExt,
286 fileindexTemplate.process(allFiles)
291 publishJSON : function(file, data)
293 // what we need to output to be usefull...
295 var cfgProperties = [];
296 if (!data.comment.getTag('singleton').length) {
297 cfgProperties = data.configToArray();
298 cfgProperties = cfgProperties.sort(makeSortby("name"));
302 //println(cfgProperties.toSource());
304 for(var i =0; i < cfgProperties.length;i++) {
305 p = cfgProperties[i];
310 memberOf : p.memberOf == data.alias ? '' : p.memberOf
315 var ownEvents = data.methods.filter( function(e){
316 return e.isEvent && !e.comment.getTag('hide').length;
317 }).sort(makeSortby("name"));
322 for(var i =0; i < ownEvents.length;i++) {
325 name : m.name.substring(1),
326 sig : makeFuncSkel(m.params),
331 //println(props.toSource());
332 // we need to output:
343 File.write(file, JSON.stringify(ret, null, 2 ));
351 makeSrcFile: function(sourceFile)
355 name = sourceFile.substring(Options.baseDir.length+1);
356 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
358 name = name.replace(/\:/g, "_"); //??
360 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
361 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
362 File.write(Options.target+"/symbols/src/" + name,
364 '<title>' + sourceFile + '</title>' +
365 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
366 '</head><body class="highlightpage">' +