PageRenderTime 39ms CodeModel.GetById 28ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/version1.x/templates/sweet/publish.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 79 lines | 58 code | 13 blank | 8 comment | 12 complexity | 47cbf880825129aa23b582da7791b065 MD5 | raw file
 1require("app/JsHilite.js");
 2
 3function publish(fileGroup, context) {
 4	var file_template = new JsPlate(context.t+"file.tmpl");
 5	
 6	// build up classname to file mapping
 7	var index = {};
 8	linkToType.classfiles = {};
 9	for (var i = 0; i < fileGroup.files.length; i++) {
10		if (context.d) {
11			var our_name = generateFilename(i);
12			index[our_name] = {name: (fileGroup.files[i].filename), classes: []};
13		
14			for (var s = 0; s < fileGroup.files[i].symbols.length; s++) {
15				if (fileGroup.files[i].symbols[s].isa == "CONSTRUCTOR") {
16					index[our_name].classes.push(fileGroup.files[i].symbols[s].alias);
17					if (our_name) linkToType.classfiles[fileGroup.files[i].symbols[s].alias] = our_name;
18//					//fileGroup.classfiles[fileGroup.files[i].symbols[s].alias] = our_name;
19				}
20			}	
21	
22			// make copy original source code with syntax hiliting
23			var sourceFile = fileGroup.files[i].path;
24			if (sourceFile) {
25				var hiliter = new JsHilite(IO.readFile(sourceFile), JsDoc.opt.e);
26				IO.saveFile(context.d, "src"+our_name, hiliter.hilite());
27				
28				fileGroup.files[i].source = "src"+our_name;
29			}
30		}
31	}
32	
33	for (var i = 0; i < fileGroup.files.length; i++) {
34		if (context.d) {
35			var output = file_template.process(fileGroup.files[i]);
36			IO.saveFile(context.d, generateFilename(i), output);
37		}
38	}
39	
40	var indx_template = new JsPlate(context.t+"index.tmpl");
41	var index = indx_template.process(index);
42	if (context.d) {
43		IO.saveFile(context.d, "file_list.html", index);
44		
45		IO.copyFile(context.t+"index.html", context.d);
46		IO.copyFile(context.t+"splash.html", context.d);
47		IO.copyFile(context.t+"default.css", context.d);
48		
49		IO.copyFile(context.t+"file.gif", context.d);
50		IO.copyFile(context.t+"overview.gif", context.d);
51		IO.copyFile(context.t+"constructor.gif", context.d);
52		IO.copyFile(context.t+"function.gif", context.d);
53		IO.copyFile(context.t+"object.gif", context.d);
54	}
55}
56
57function generateFilename(i) {
58	return "_"+((i+1<10)?"0"+(i+1):(i+1))+".html"
59}
60
61/**
62	Takes a string of object types and adds links if there exists
63	any documentation files in the output for that type.
64	@param typeString Like "Foo" or "Foo[] | Bar".
65 */
66function linkToType(typeString) {
67	var sep = /[^a-zA-Z0-9._$]+/;
68	var types = typeString.split(sep);
69	
70	for (var i = 0; i < types.length; i++) {
71		var link = linkToType.classfiles[types[i]];
72		if (link) {
73			var re = new RegExp('(^|[^a-zA-Z0-9._$])'+types[i]+'($|[^a-zA-Z0-9._$])');
74			typeString = typeString.replace(re, "$1<a href=\""+link+"#"+types[i]+"\">"+types[i]+"</a>$2", "g");
75		}
76	}
77	
78	return typeString;
79}