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;
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 this.srcFiles = this.srcFiles.concat(
72 File.list(Options.src[i] ).filter(
74 var thisExt = $.split(".").pop().toLowerCase();
75 return (ext.indexOf(thisExt) > -1); // || thisExt in JSDOC.handlers);
76 // we're only interested in files with certain extensions
85 _parseSrcFiles : function()
89 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
91 var srcFile = this.srcFiles[i];
94 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
97 // disabled at present!@!!
99 if (false && !Options.disablecache && File.exists(cacheFile)) {
102 var c_mt = File.getTimes(cacheFile);
103 var o_mt = File.getTimes(srcFile);
104 //println(c_mt.toSource());
105 // println(o_mt.toSource());
107 // this check does not appear to work according to the doc's - need to check it out.
109 if (c_mt[0] > o_mt[0]) { // cached time > original time!
110 // use the cached mtimes..
111 var syms = JSON.parse(File.read(cacheFile));
113 throw "Conversion of cache not done yet!";
115 for (var sy in syms) {
116 //println("ADD:" + sy );
117 Parser.symbols.addSymbol(syms[sy]);
125 Options.LOG.warn("reading : " + srcFile);
126 src = File.read(srcFile);
129 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
133 var txs = new TextStream(src);
135 var tr = new TokenReader({ keepComments : true, keepWhite : true });
136 var ts = new TokenStream(txs);
138 Parser.parse(ts, srcFile);
140 //var outstr = JSON.stringify(
141 // Parser.filesSymbols[srcFile]._index
143 //File.write(cacheFile, outstr);
156 publish : function() {
163 if (!File.exists(Options.target))
164 File.mkdir(Options.target);
165 if (!File.exists(Options.target+"/symbols"))
166 File.mkdir(Options.target+"/symbols");
167 if (!File.exists(Options.target+"/symbols/src"))
168 File.mkdir(Options.target+"/symbols/src");
170 // copy everything in 'static' into
171 File.list(Options.templatesDir + '/static').forEach(function (f) {
172 File.copy(Options.templatesDir + '/static/' + f, Options.target + '/' + f);
174 if (!File.isDirectory(Options.target +"/json")) {
175 File.makeDir(Options.target +"/json");
178 // used to check the details of things being linked to
179 Link.symbolSet = symbolSet;
182 var classTemplate = new Template({
183 templateFile : Options.templatesDir + "/class.tmpl",
186 var classesTemplate = new Template({
187 templateFile : Options.templatesDir +"/allclasses.tmpl",
190 var classesindexTemplate = new Template({
191 templateFile : Options.templatesDir +"/index.tmpl",
194 var fileindexTemplate = new Template({
195 templateFile : Options.templatesDir +"/allfiles.tmpl",
200 classTemplate.symbolSet = symbolSet;
203 function hasNoParent($) {
204 return ($.memberOf == "")
206 function isaFile($) {
207 return ($.is("FILE"))
209 function isaClass($) {
210 return ($.is("CONSTRUCTOR") || $.isNamespace);
213 var symbols = symbolSet.toArray();
215 var files = Options.srcFiles;
217 for (var i = 0, l = files.length; i < l; i++) {
219 var targetDir = Options.target + "/symbols/src/";
220 this.makeSrcFile(file, targetDir);
223 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
225 var classesIndex = classesTemplate.process(classes); // kept in memory
229 for (var i = 0, l = classes.length; i < l; i++) {
230 var symbol = classes[i];
233 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
234 classTemplate.process(symbol));
236 print("write " + Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt);
240 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
246 // regenrate the index with different relative links
248 var classesIndex = classesTemplate.process(classes);
252 File.write(Options.target + "/index."+ Options.publishExt,
253 classesindexTemplate.process(classes)
256 // blank everything???? classesindexTemplate = classesIndex = classes = null;
260 var documentedFiles = symbols.filter(function ($) {
261 return ($.is("FILE"))
266 for (var i = 0; i < files.length; i++) {
267 allFiles.push(new Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
270 for (var i = 0; i < documentedFiles.length; i++) {
271 var offset = files.indexOf(documentedFiles[i].alias);
272 allFiles[offset] = documentedFiles[i];
275 allFiles = allFiles.sort(makeSortby("name"));
276 File.write(Options.target , "/files."+Options.publishExt,
277 fileindexTemplate.process(allFiles)
282 publishJSON : function(file, data)
284 // what we need to output to be usefull...
286 var cfgProperties = [];
287 if (!data.comment.getTag('singleton').length) {
288 cfgProperties = data.configToArray();
289 cfgProperties = cfgProperties.sort(makeSortby("name"));
293 //println(cfgProperties.toSource());
295 for(var i =0; i < cfgProperties.length;i++) {
296 p = cfgProperties[i];
301 memberOf : p.memberOf == data.alias ? '' : p.memberOf
306 var ownEvents = data.methods.filter( function(e){
307 return e.isEvent && !e.comment.getTag('hide').length;
308 }).sort(makeSortby("name"));
313 for(var i =0; i < ownEvents.length;i++) {
316 name : m.name.substring(1),
317 sig : makeFuncSkel(m.params),
322 //println(props.toSource());
323 // we need to output:
334 File.write(file, JSON.stringify(ret, null, 2 ));
342 makeSrcFile: function(sourceFile)
346 name = sourceFile.substring(Options.baseDir.length);
347 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
348 name = name.replace(/\:/g, "_"); //??
351 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
352 File.write(Options.target+"/symbols/src/" + name,
354 '<title>' + sourceFile + '</title>' +
355 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
356 '</head><body class="highlightpage">' +