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;
13 Options = imports.Options.Options;
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...??
39 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
40 //Options.LOG.inform("With options: ");
42 if (!File.isDirectory(Options.cacheDirectory)) {
43 File.mkdir(Options.cacheDirectory)
46 Options.srcFiles = this._getSrcFiles();
47 this._parseSrcFiles();
48 this.symbolSet = Parser.symbols;
50 // this currently uses the concept of publish.js...
59 _getSrcFiles : function()
65 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
68 for (var i = 0; i < Options.src.length; i++) {
69 this.srcFiles = this.srcFiles.concat(
71 File.list(Options.src[i] ).filter(
73 var thisExt = $.split(".").pop().toLowerCase();
74 return (ext.indexOf(thisExt) > -1); // || thisExt in JSDOC.handlers);
75 // we're only interested in files with certain extensions
84 _parseSrcFiles : function()
88 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
90 var srcFile = this.srcFiles[i];
93 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
96 // disabled at present!@!!
98 if (false && !Options.disablecache && File.exists(cacheFile)) {
101 var c_mt = File.getTimes(cacheFile);
102 var o_mt = File.getTimes(srcFile);
103 //println(c_mt.toSource());
104 // println(o_mt.toSource());
106 // this check does not appear to work according to the doc's - need to check it out.
108 if (c_mt[0] > o_mt[0]) { // cached time > original time!
109 // use the cached mtimes..
110 var syms = JSON.parse(File.read(cacheFile));
112 throw "Conversion of cache not done yet!";
114 for (var sy in syms) {
115 //println("ADD:" + sy );
116 Parser.symbols.addSymbol(syms[sy]);
124 src = File.read(srcFile);
127 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
132 var tr = new TokenReader();
133 var ts = new TokenStream(tr.tokenize(src));
135 Parser.parse(ts, srcFile);
137 //var outstr = JSON.stringify(
138 // Parser.filesSymbols[srcFile]._index
140 //File.write(cacheFile, outstr);
153 publish : function() {
160 if (!File.exists(Options.target))
161 File.mkdir(Options.target);
162 if (!File.exists(Options.target+"/symbols"))
163 File.mkdir(Options.target+"/symbols");
164 if (!File.exists(Options.target+"/symbols/src"))
165 File.mkdir(Options.target+"/symbols/src");
167 // copy everything in 'static' into
168 File.list(Options.templatesDir + '/static').forEach(function (f) {
169 File.copy(Options.templatesDir + '/static/' + f, Options.target + '/' + f);
171 if (!File.isDirectory(Options.target +"/json")) {
172 File.makeDir(Options.target +"/json");
175 // used to check the details of things being linked to
176 Link.symbolSet = symbolSet;
179 var classTemplate = new Template({
180 templateFile : Options.templatesDir + "/class.tmpl",
183 var classesTemplate = new Template({
184 templateFile : Options.templatesDir +"/allclasses.tmpl",
187 var classesindexTemplate = new Template({
188 templateFile : Options.templatesDir +"/index.tmpl",
191 var fileindexTemplate = new Template({
192 templateFile : Options.templatesDir +"/allfiles.tmpl",
197 classTemplate.symbolSet = symbolSet;
200 function hasNoParent($) {
201 return ($.memberOf == "")
203 function isaFile($) {
204 return ($.is("FILE"))
206 function isaClass($) {
207 return ($.is("CONSTRUCTOR") || $.isNamespace);
210 var symbols = symbolSet.toArray();
212 var files = Options.srcFiles;
214 for (var i = 0, l = files.length; i < l; i++) {
216 var targetDir = Options.target + "/symbols/src/";
217 this.makeSrcFile(file, targetDir);
220 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
222 var classesIndex = classesTemplate.process(classes); // kept in memory
226 for (var i = 0, l = classes.length; i < l; i++) {
227 var symbol = classes[i];
230 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
231 classTemplate.process(symbol));
233 print("write " + Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt);
237 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
243 // regenrate the index with different relative links
245 var classesIndex = classesTemplate.process(classes);
249 File.write(Options.target + "/index."+ Options.publishExt,
250 classesindexTemplate.process(classes)
253 // blank everything???? classesindexTemplate = classesIndex = classes = null;
257 var documentedFiles = symbols.filter(function ($) {
258 return ($.is("FILE"))
263 for (var i = 0; i < files.length; i++) {
264 allFiles.push(new Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
267 for (var i = 0; i < documentedFiles.length; i++) {
268 var offset = files.indexOf(documentedFiles[i].alias);
269 allFiles[offset] = documentedFiles[i];
272 allFiles = allFiles.sort(makeSortby("name"));
273 File.write(Options.target , "/files."+Options.publishExt,
274 fileindexTemplate.process(allFiles)
279 publishJSON = function(file, data)
281 // what we need to output to be usefull...
283 var cfgProperties = [];
284 if (!data.comment.getTag('singleton').length) {
285 cfgProperties = data.configToArray();
286 cfgProperties = cfgProperties.sort(makeSortby("name"));
290 //println(cfgProperties.toSource());
292 for(var i =0; i < cfgProperties.length;i++) {
293 p = cfgProperties[i];
298 memberOf : p.memberOf == data.alias ? '' : p.memberOf
303 var ownEvents = data.methods.filter( function(e){
304 return e.isEvent && !e.comment.getTag('hide').length;
305 }).sort(makeSortby("name"));
310 for(var i =0; i < ownEvents.length;i++) {
313 name : m.name.substring(1),
314 sig : makeFuncSkel(m.params),
319 //println(props.toSource());
320 // we need to output:
331 File.write(file, JSON.stringify(ret, null, 2 ));
339 makeSrcFile: function(sourceFile)
343 name = sourceFile.substring(Options.baseDir.length);
344 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
345 name = name.replace(/\:/g, "_"); //??
348 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
349 File.write(Options.target+"/symbols/src/" + name,
351 '<title>' + sourceFile + '</title>' +
352 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
353 '</head><body class="highlightpage">' +