/** Called automatically by JsDoc Toolkit. */
load(JSDOC.opt.t + 'src/Symbol.js');
load(JSDOC.opt.t + 'src/Utils.js');
load(JSDOC.opt.t + 'src/Operator.js');
load(JSDOC.opt.t + 'src/Render.js');

function publish(symbolSet) {
	var renderMode = JSDOC.opt.D.renderMode;
	publish.conf = {  // trailing slash expected for dirs
		ext: renderMode == 'docs' ? '.html' : '.jstl',
		outDir: JSDOC.opt.d || SYS.pwd + '../out/jsdoc/',
		templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
		staticDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'static/',
		symbolsDir: renderMode == 'docs' ? 'packages/' : 'paper/',
		srcDir: 'symbols/src/',
		renderMode: renderMode,
		globalName: 'Global Scope'
	};
	publish.conf.packagesDir = publish.conf.outDir + publish.conf.symbolsDir;

	if (renderMode == 'docs') {
		// Copy over the static files
		Utils.copyDirectory(
			new java.io.File(publish.conf.staticDir),
			new java.io.File(publish.conf.outDir)
		);
	} else {
		Utils.deleteFiles(new File(publish.conf.outDir));
		new java.io.File(publish.conf.outDir + 'paper/').mkdirs();
	}

	// used to allow Link to check the details of things being linked to
	Link.symbolSet = symbolSet;

	// get an array version of the symbolset, useful for filtering
	var symbols = symbolSet.toArray(),
		files = JSDOC.opt.srcFiles,
		aliasSort = Utils.makeSortby('alias'),
 		classes = symbols.filter(Utils.isaClass).sort(aliasSort);
	
	// create a filemap in which outfiles must be to be named uniquely, ignoring case
	// Since we want lowercase links in templatedocs, we always use this
	if (JSDOC.opt.u || templatedocs) {
		var filemapCounts = {};
		Link.filemap = {};
		for (var i = 0, l = classes.length; i < l; i++) {
			var alias = classes[i].alias,
				lcAlias = alias.toLowerCase();
			
			if (!filemapCounts[lcAlias]) {
				filemapCounts[lcAlias] = 1;
			} else {
				filemapCounts[lcAlias]++;
			}
			// Use lowercase links for templatedocs
			var linkAlias = templatedocs ? lcAlias : alias;
			Link.filemap[alias] = filemapCounts[lcAlias] > 1
					? linkAlias + '_' + filemapCounts[lcAlias] : linkAlias;
		}
	}
	
	Link.base = '../';

	// create each of the class pages
	for (var i = 0, l = classes.length; i < l; i++) {
		var symbol = classes[i];
		
		symbol.events = symbol.getEvents();   // 1 order matters
		symbol.methods = symbol.getMethods(); // 2
		for (var j = 0; j < symbol.methods.length; j++) {
			var method = symbol.methods[j];
			method.isOperator = Operator.isOperator(method);
		}
		
		Link.currentSymbol= symbol;
		var html = Render._class(symbol);
		var name = ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias)
				+ publish.conf.ext;
		if (renderMode == 'docs') {
			html = Render.html({
				content: html,
				title: symbol.alias
			});
		}
		IO.saveFile(publish.conf.packagesDir, name, html);
	}
	if (templatedocs) {
		IO.saveFile(publish.conf.outDir, 'packages.js', Render.indexjs());
	} else {
		IO.saveFile(publish.conf.classesDir, 'index.html', Render.index());
	}
}
@@ -261,16 +261,117 @@
 erMode;%0A
+%09var templatedocs = renderMode == 'templatedocs';%0A%09var extension = templatedocs ? '.jstl' : '.html';%0A
 %09publish
@@ -421,57 +421,8 @@
 irs%0A
-%09%09ext: renderMode == 'docs' ? '.html' : '.jstl',%0A
 %09%09ou
@@ -668,16 +668,103 @@
 aper/',%0A
+%09%09// Use no extensions in links for templatedocs%0A%09%09ext: templatedocs ? '' : extension,%0A
 %09%09srcDir
@@ -2776,24 +2776,17 @@
 %09%09+ 
-publish.conf.ext
+extension
 ;%0A%09%09

Use no extensions in links for templatedocs.