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 DocComment = imports.DocComment.DocComment;
21 /****************** INCLUDES ARE ALL AT THE BOTTOM OF THIS FILE!!!!! *******************/
23 // should not realy be here -- or anywhere...??
26 Options = false; // refer to this everywhere!
37 build : function (opts)
42 Options.LOG.inform("JsDoc Toolkit main() running at "+new Date()+".");
43 //Options.LOG.inform("With options: ");
45 if (Options.cacheDirectory.length && !File.isDirectory(Options.cacheDirectory)) {
46 File.mkdir(Options.cacheDirectory)
49 Options.srcFiles = this._getSrcFiles();
50 this._parseSrcFiles();
51 this.symbolSet = Parser.symbols;
53 // this currently uses the concept of publish.js...
62 _getSrcFiles : function()
68 ext = Options.ext.split(",").map(function($) {return $.toLowerCase()});
71 for (var i = 0; i < Options.src.length; i++) {
72 // add to sourcefiles..
74 File.list(Options.src[i] ).forEach(function($) {
75 if (Options['exclude-src'].indexOf($) > -1) {
78 var thisExt = $.split(".").pop().toLowerCase();
79 if (ext.indexOf(thisExt) < 0) {
82 _this.srcFiles.push(Options.src[i] + '/' + $);
86 //Seed.print(JSON.stringify(this.srcFiles, null,4));Seed.quit();
90 _parseSrcFiles : function()
94 for (var i = 0, l = this.srcFiles.length; i < l; i++) {
96 var srcFile = this.srcFiles[i];
99 var cacheFile = Options.cacheDirectory + srcFile.replace(/\//g, '_') + ".cache";
101 //println(cacheFile);
102 // disabled at present!@!!
104 if (false && !Options.disablecache && File.exists(cacheFile)) {
107 var c_mt = File.getTimes(cacheFile);
108 var o_mt = File.getTimes(srcFile);
109 //println(c_mt.toSource());
110 // println(o_mt.toSource());
112 // this check does not appear to work according to the doc's - need to check it out.
114 if (c_mt[0] > o_mt[0]) { // cached time > original time!
115 // use the cached mtimes..
116 var syms = JSON.parse(File.read(cacheFile));
118 throw "Conversion of cache not done yet!";
120 for (var sy in syms) {
121 //println("ADD:" + sy );
122 Parser.symbols.addSymbol(syms[sy]);
130 Options.LOG.inform("reading : " + srcFile);
131 src = File.read(srcFile);
134 Options.LOG.warn("Can't read source file '"+srcFile+"': "+e.message);
138 var txs = new TextStream(src);
140 var tr = new TokenReader({ keepComments : true, keepWhite : true , sepIdents: false });
142 var ts = new TokenStream(tr.tokenize(txs));
144 Parser.parse(ts, srcFile);
146 //var outstr = JSON.stringify(
147 // Parser.filesSymbols[srcFile]._index
149 //File.write(cacheFile, outstr);
162 publish : function() {
163 Options.LOG.inform("Publishing");
168 Options.LOG.inform("Making directories");
169 if (!File.isDirectory(Options.target))
170 File.mkdir(Options.target);
171 if (!File.isDirectory(Options.target+"/symbols"))
172 File.mkdir(Options.target+"/symbols");
173 if (!File.isDirectory(Options.target+"/symbols/src"))
174 File.mkdir(Options.target+"/symbols/src");
176 if (!File.isDirectory(Options.target +"/json")) {
177 File.mkdir(Options.target +"/json");
180 Options.LOG.inform("Copying files from static: " +Options.templateDir);
181 // copy everything in 'static' into
182 File.list(Options.templateDir + '/static').forEach(function (f) {
183 Options.LOG.inform("Copy " + Options.templateDir + '/static/' + f + ' to ' + Options.target + '/' + f);
184 File.copyFile(Options.templateDir + '/static/' + f, Options.target + '/' + f, Gio.FileCopyFlags.OVERWRITE);
188 Options.LOG.inform("Setting up templates");
189 // used to check the details of things being linked to
190 Link.symbolSet = this.symbolSet;
193 var classTemplate = new Template({
194 templateFile : Options.templateDir + "/class.tmpl",
197 var classesTemplate = new Template({
198 templateFile : Options.templateDir +"/allclasses.tmpl",
201 var classesindexTemplate = new Template({
202 templateFile : Options.templateDir +"/index.tmpl",
205 var fileindexTemplate = new Template({
206 templateFile : Options.templateDir +"/allfiles.tmpl",
211 classTemplate.symbolSet = this.symbolSet;
214 function hasNoParent($) {
215 return ($.memberOf == "")
217 function isaFile($) {
218 return ($.is("FILE"))
220 function isaClass($) {
221 return ($.is("CONSTRUCTOR") || $.isNamespace);
223 function makeSortby(attribute) {
224 return function(a, b) {
225 if (a[attribute] != undefined && b[attribute] != undefined) {
226 a = a[attribute]; //.toLowerCase();
227 b = b[attribute];//.toLowerCase();
228 if (a < b) return -1;
243 var symbols = this.symbolSet.toArray();
245 var files = Options.srcFiles;
247 for (var i = 0, l = files.length; i < l; i++) {
249 var targetDir = Options.target + "/symbols/src/";
250 this.makeSrcFile(file, targetDir);
253 var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
255 //Options.LOG.inform("classTemplate Process : all classes");
257 // var classesIndex = classesTemplate.process(classes); // kept in memory
259 Options.LOG.inform("iterate classes");
261 for (var i = 0, l = classes.length; i < l; i++) {
262 var symbol = classes[i];
265 Options.LOG.inform("classTemplate Process : " + symbol.alias);
267 File.write(Options.target+"/symbols/" +symbol.alias+'.' + Options.publishExt ,
268 classTemplate.process(symbol));
274 this.publishJSON(Options.target+"/json/", symbol.alias+'.json', symbol)
280 // regenrate the index with different relative links
282 //var classesIndex = classesTemplate.process(classes);
284 Options.LOG.inform("build index");
286 File.write(Options.target + "/index."+ Options.publishExt,
287 classesindexTemplate.process(classes)
290 // blank everything???? classesindexTemplate = classesIndex = classes = null;
294 var documentedFiles = symbols.filter(function ($) {
295 return ($.is("FILE"))
300 for (var i = 0; i < files.length; i++) {
301 allFiles.push(new Symbol(files[i], [], "FILE", new DocComment("/** */")));
304 for (var i = 0; i < documentedFiles.length; i++) {
305 var offset = files.indexOf(documentedFiles[i].alias);
306 allFiles[offset] = documentedFiles[i];
309 allFiles = allFiles.sort(makeSortby("name"));
310 Options.LOG.inform("write files index");
312 File.write(Options.target + "/files."+Options.publishExt,
313 fileindexTemplate.process(allFiles)
318 publishJSON : function(file, data)
320 // what we need to output to be usefull...
322 var cfgProperties = [];
323 if (!data.comment.getTag('singleton').length) {
324 cfgProperties = data.configToArray();
325 cfgProperties = cfgProperties.sort(makeSortby("name"));
329 //println(cfgProperties.toSource());
331 for(var i =0; i < cfgProperties.length;i++) {
332 p = cfgProperties[i];
337 memberOf : p.memberOf == data.alias ? '' : p.memberOf
342 var ownEvents = data.methods.filter( function(e){
343 return e.isEvent && !e.comment.getTag('hide').length;
344 }).sort(makeSortby("name"));
349 for(var i =0; i < ownEvents.length;i++) {
352 name : m.name.substring(1),
353 sig : makeFuncSkel(m.params),
358 //println(props.toSource());
359 // we need to output:
370 File.write(file, JSON.stringify(ret, null, 2 ));
378 makeSrcFile: function(sourceFile)
380 // this stuff works...
384 name = sourceFile.substring(Options.baseDir.length+1);
385 name = name.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
387 name = name.replace(/\:/g, "_"); //??
389 Options.LOG.inform("Write Source file : " + Options.target+"/symbols/src/" + name);
390 var pretty = imports.PrettyPrint.toPretty(File.read(sourceFile));
391 File.write(Options.target+"/symbols/src/" + name,
393 '<title>' + sourceFile + '</title>' +
394 '<link rel="stylesheet" type="text/css" href="../../../highlight-js.css"/>' +
395 '</head><body class="highlightpage">' +