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 (!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 src = File.read(srcFile);
128 LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
133 var tr = new TokenReader();
134 var ts = new TokenStream(tr.tokenize(src));
136 Parser.parse(ts, srcFile);
138 //var outstr = JSON.stringify(
139 // Parser.filesSymbols[srcFile]._index
141 //File.write(cacheFile, outstr);
154 publish : function() {
161 if (!File.exists(Options.target))
162 File.mkdir(Options.target);
163 if (!File.exists(Options.target+"/symbols"))
164 File.mkdir(Options.target+"/symbols");
165 if (!File.exists(Options.target+"/symbols/src"))
166 File.mkdir(Options.target+"/symbols/src");
168 // copy everything in 'static' into
169 File.list(Options.templatesDir + '/static').forEach(function (f) {
170 File.copy(Options.templatesDir + '/static/' + f, Options.target + '/' + f);
172 if (!File.isDirectory(Options.target +"/json")) {
173 File.makeDir(Options.target +"/json");
176 // used to check the details of things being linked to
177 Link.symbolSet = symbolSet;
180 var classTemplate = new Template({
181 templateFile : Options.templatesDir + "/class.tmpl",
184 var classesTemplate = new Template({
185 templateFile : Options.templatesDir +"/allclasses.tmpl",
188 var classesindexTemplate = new Template({
189 templateFile : Options.templatesDir +"/index.tmpl",
192 var fileindexTemplate = new Template({
193 templateFile : Options.templatesDir +"/allfiles.tmpl",
198 classTemplate.symbolSet = symbolSet;
201 function hasNoParent($) {
202 return ($.memberOf == "")
204 function isaFile($) {
205 return ($.is("FILE"))
207 function isaClass($) {
208 return ($.is("CONSTRUCTOR") || $.isNamespace);
211 var symbols = symbolSet.toArray();
213 var files = Options.srcFiles;
215 for (var i = 0, l = files.length; i < l; i++) {
217 var targetDir = Options.target + "/symbols/src/";
218 this.makeSrcFile(file, targetDir);
221 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
223 var classesIndex = classesTemplate.process(classes); // kept in memory
227 for (var i = 0, l = classes.length; i < l; i++) {
228 var symbol = classes[i];
231 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
232 classTemplate.process(symbol));
234 print("write " + Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt);
238 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
244 // regenrate the index with different relative links
246 var classesIndex = classesTemplate.process(classes);
250 File.write(Options.target + "/index."+ Options.publishExt,
251 classesindexTemplate.process(classes)
254 // blank everything???? classesindexTemplate = classesIndex = classes = null;
258 var documentedFiles = symbols.filter(function ($) {
259 return ($.is("FILE"))
264 for (var i = 0; i < files.length; i++) {
265 allFiles.push(new Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
268 for (var i = 0; i < documentedFiles.length; i++) {
269 var offset = files.indexOf(documentedFiles[i].alias);
270 allFiles[offset] = documentedFiles[i];
273 allFiles = allFiles.sort(makeSortby("name"));
274 File.write(Options.target , "/files."+Options.publishExt,
275 fileindexTemplate.process(allFiles)
280 publishJSON : function(file, data)
282 // what we need to output to be usefull...
284 var cfgProperties = [];
285 if (!data.comment.getTag('singleton').length) {
286 cfgProperties = data.configToArray();
287 cfgProperties = cfgProperties.sort(makeSortby("name"));
291 //println(cfgProperties.toSource());
293 for(var i =0; i < cfgProperties.length;i++) {
294 p = cfgProperties[i];
299 memberOf : p.memberOf == data.alias ? '' : p.memberOf
304 var ownEvents = data.methods.filter( function(e){
305 return e.isEvent && !e.comment.getTag('hide').length;
306 }).sort(makeSortby("name"));
311 for(var i =0; i < ownEvents.length;i++) {
314 name : m.name.substring(1),
315 sig : makeFuncSkel(m.params),
320 //println(props.toSource());
321 // we need to output:
332 File.write(file, JSON.stringify(ret, null, 2 ));
340 makeSrcFile: function(sourceFile)
344 name = sourceFile.substring(Options.baseDir.length);
345 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
346 name = name.replace(/\:/g, "_"); //??
349 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
350 File.write(Options.target+"/symbols/src/" + name,
352 '<title>' + sourceFile + '</title>' +
353 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
354 '</head><body class="highlightpage">' +