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;
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..
71 this.srcFiles = this.srcFiles.concat(
73 File.list(Options.src[i] ).filter(
75 if (Options['exclude-src'].indexOf($) > -1) {
78 var thisExt = $.split(".").pop().toLowerCase();
79 return (ext.indexOf(thisExt) > -1); // || thisExt in JSDOC.handlers);
80 // we're only interested in files with certain extensions
89 _parseSrcFiles : function()
93 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
95 var srcFile = this.srcFiles[i];
98 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
100 //println(cacheFile);
101 // disabled at present!@!!
103 if (false && !Options.disablecache && File.exists(cacheFile)) {
106 var c_mt = File.getTimes(cacheFile);
107 var o_mt = File.getTimes(srcFile);
108 //println(c_mt.toSource());
109 // println(o_mt.toSource());
111 // this check does not appear to work according to the doc's - need to check it out.
113 if (c_mt[0] > o_mt[0]) { // cached time > original time!
114 // use the cached mtimes..
115 var syms = JSON.parse(File.read(cacheFile));
117 throw "Conversion of cache not done yet!";
119 for (var sy in syms) {
120 //println("ADD:" + sy );
121 Parser.symbols.addSymbol(syms[sy]);
129 Options.LOG.warn("reading : " + srcFile);
130 src = File.read(srcFile);
133 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
137 var txs = new TextStream(src);
139 var tr = new TokenReader({ keepComments : true, keepWhite : true });
141 var ts = new TokenStream(tr.tokenize(txs));
143 Parser.parse(ts, srcFile);
145 //var outstr = JSON.stringify(
146 // Parser.filesSymbols[srcFile]._index
148 //File.write(cacheFile, outstr);
161 publish : function() {
168 if (!File.exists(Options.target))
169 File.mkdir(Options.target);
170 if (!File.exists(Options.target+"/symbols"))
171 File.mkdir(Options.target+"/symbols");
172 if (!File.exists(Options.target+"/symbols/src"))
173 File.mkdir(Options.target+"/symbols/src");
175 // copy everything in 'static' into
176 File.list(Options.templatesDir + '/static').forEach(function (f) {
177 File.copy(Options.templatesDir + '/static/' + f, Options.target + '/' + f);
179 if (!File.isDirectory(Options.target +"/json")) {
180 File.makeDir(Options.target +"/json");
183 // used to check the details of things being linked to
184 Link.symbolSet = symbolSet;
187 var classTemplate = new Template({
188 templateFile : Options.templatesDir + "/class.tmpl",
191 var classesTemplate = new Template({
192 templateFile : Options.templatesDir +"/allclasses.tmpl",
195 var classesindexTemplate = new Template({
196 templateFile : Options.templatesDir +"/index.tmpl",
199 var fileindexTemplate = new Template({
200 templateFile : Options.templatesDir +"/allfiles.tmpl",
205 classTemplate.symbolSet = symbolSet;
208 function hasNoParent($) {
209 return ($.memberOf == "")
211 function isaFile($) {
212 return ($.is("FILE"))
214 function isaClass($) {
215 return ($.is("CONSTRUCTOR") || $.isNamespace);
218 var symbols = symbolSet.toArray();
220 var files = Options.srcFiles;
222 for (var i = 0, l = files.length; i < l; i++) {
224 var targetDir = Options.target + "/symbols/src/";
225 this.makeSrcFile(file, targetDir);
228 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
230 var classesIndex = classesTemplate.process(classes); // kept in memory
234 for (var i = 0, l = classes.length; i < l; i++) {
235 var symbol = classes[i];
238 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
239 classTemplate.process(symbol));
241 print("write " + Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt);
245 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
251 // regenrate the index with different relative links
253 var classesIndex = classesTemplate.process(classes);
257 File.write(Options.target + "/index."+ Options.publishExt,
258 classesindexTemplate.process(classes)
261 // blank everything???? classesindexTemplate = classesIndex = classes = null;
265 var documentedFiles = symbols.filter(function ($) {
266 return ($.is("FILE"))
271 for (var i = 0; i < files.length; i++) {
272 allFiles.push(new Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
275 for (var i = 0; i < documentedFiles.length; i++) {
276 var offset = files.indexOf(documentedFiles[i].alias);
277 allFiles[offset] = documentedFiles[i];
280 allFiles = allFiles.sort(makeSortby("name"));
281 File.write(Options.target , "/files."+Options.publishExt,
282 fileindexTemplate.process(allFiles)
287 publishJSON : function(file, data)
289 // what we need to output to be usefull...
291 var cfgProperties = [];
292 if (!data.comment.getTag('singleton').length) {
293 cfgProperties = data.configToArray();
294 cfgProperties = cfgProperties.sort(makeSortby("name"));
298 //println(cfgProperties.toSource());
300 for(var i =0; i < cfgProperties.length;i++) {
301 p = cfgProperties[i];
306 memberOf : p.memberOf == data.alias ? '' : p.memberOf
311 var ownEvents = data.methods.filter( function(e){
312 return e.isEvent && !e.comment.getTag('hide').length;
313 }).sort(makeSortby("name"));
318 for(var i =0; i < ownEvents.length;i++) {
321 name : m.name.substring(1),
322 sig : makeFuncSkel(m.params),
327 //println(props.toSource());
328 // we need to output:
339 File.write(file, JSON.stringify(ret, null, 2 ));
347 makeSrcFile: function(sourceFile)
351 name = sourceFile.substring(Options.baseDir.length);
352 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
353 name = name.replace(/\:/g, "_"); //??
356 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
357 File.write(Options.target+"/symbols/src/" + name,
359 '<title>' + sourceFile + '</title>' +
360 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
361 '</head><body class="highlightpage">' +