PageRenderTime 28ms CodeModel.GetById 15ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/jsdoc_toolkit-1.3.3/templates/sunny/publish.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 73 lines | 61 code | 11 blank | 1 comment | 16 complexity | b03c73dec667b691984d4e5588a09cd3 MD5 | raw file
 1require("app/JsHilite.js");
 2
 3function basename(filename) {
 4	filename.match(/([^\/\\]+)\.[^\/\\]+$/);
 5	return RegExp.$1;
 6}
 7
 8function publish(fileGroup, context) {
 9	var classTemplate = new JsPlate(context.t+"class.tmpl");
10	var indexTemplate = new JsPlate(context.t+"index.tmpl");
11	
12	var allFiles = {};
13	var allClasses = {};
14	var globals = {methods:[], properties:[], alias:"GLOBALS", isStatic:true};
15	
16	for (var i = 0; i < fileGroup.files.length; i++) {
17		var file_basename = basename(fileGroup.files[i].filename);
18		var file_srcname = file_basename+".src.html";
19		
20		for (var s = 0; s < fileGroup.files[i].symbols.length; s++) {
21			if (fileGroup.files[i].symbols[s].isa == "CONSTRUCTOR") {
22				var thisClass = fileGroup.files[i].symbols[s];
23				// sort inherited methods by class
24				var inheritedMethods = fileGroup.files[i].symbols[s].getInheritedMethods();
25				if (inheritedMethods.length > 0) {
26					thisClass.inherited = {};
27					for (var n = 0; n < inheritedMethods.length; n++) {
28						if (! thisClass.inherited[inheritedMethods[n].memberof]) thisClass.inherited[inheritedMethods[n].memberof] = [];
29						thisClass.inherited[inheritedMethods[n].memberof].push(inheritedMethods[n]);
30					}
31				}
32				
33				thisClass.name = fileGroup.files[i].symbols[s].alias;
34				thisClass.source = file_srcname;
35				thisClass.filename = fileGroup.files[i].filename;
36				thisClass.docs = thisClass.name+".html";
37				
38				if (!allClasses[thisClass.name]) allClasses[thisClass.name] = [];
39				allClasses[thisClass.name].push(thisClass);
40			}
41			else if (fileGroup.files[i].symbols[s].alias == fileGroup.files[i].symbols[s].name) {
42				if (fileGroup.files[i].symbols[s].isa == "FUNCTION") {
43					globals.methods.push(fileGroup.files[i].symbols[s]);
44				}
45				else {
46					globals.properties.push(fileGroup.files[i].symbols[s]);
47				}
48			}
49		}
50		
51		if (!allFiles[fileGroup.files[i].path]) {
52			var hiliter = new JsHilite(IO.readFile(fileGroup.files[i].path));
53			IO.saveFile(context.d, file_srcname, hiliter.hilite());
54		}
55		fileGroup.files[i].source = file_srcname;
56		allFiles[fileGroup.files[i].path] = true;
57	}
58	
59	for (var c in allClasses) {
60		outfile = c+".html";
61		allClasses[c].outfile = outfile;
62		var output = classTemplate.process(allClasses[c]);
63		IO.saveFile(context.d, outfile, output);
64	}
65	
66	output = classTemplate.process([globals]);
67	IO.saveFile(context.d, "globals.html", output);
68	
69	var output = indexTemplate.process(allClasses);
70	IO.saveFile(context.d, "allclasses-frame.html", output);
71	IO.copyFile(context.t+"index.html", context.d);
72	IO.copyFile(context.t+"splash.html", context.d);
73}