PageRenderTime 42ms CodeModel.GetById 15ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://jsdoc-toolkit.googlecode.com/
JavaScript | 97 lines | 76 code | 15 blank | 6 comment | 19 complexity | ad6b361a6a26e40f96d6542e00c87685 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), JsDoc.opt.e);
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	classfiles = {};
60	for (var c in allClasses) {
61		classfiles[c] = c+".html";
62	}
63	linkToType.classfiles = classfiles;
64	
65	for (var c in allClasses) {
66		var output = classTemplate.process(allClasses[c]);
67		IO.saveFile(context.d, classfiles[c], output);
68	}
69	
70	output = classTemplate.process([globals]); // expects an array
71	IO.saveFile(context.d, "globals.html", output);
72	
73	var output = indexTemplate.process(allClasses);
74	IO.saveFile(context.d, "allclasses-frame.html", output);
75	IO.copyFile(context.t+"index.html", context.d);
76	IO.copyFile(context.t+"splash.html", context.d);
77}
78
79/**
80	Takes a string of object types and adds links if there exists
81	any documentation files in the output for that type.
82	@param typeString Like "Foo" or "Foo[] | Bar".
83 */
84function linkToType(typeString) {
85	var sep = /[^a-zA-Z0-9._$]+/;
86	var types = typeString.split(sep);
87	
88	for (var i = 0; i < types.length; i++) {
89		var link = linkToType.classfiles[types[i]];
90		if (link) {
91			var re = new RegExp('(^|[^a-zA-Z0-9._$])'+types[i]+'($|[^a-zA-Z0-9._$])');
92			typeString = typeString.replace(re, "$1<a href=\""+link+"\">"+types[i]+"</a>$2", "g");
93		}
94	}
95	
96	return typeString;
97}