jsdoc: clean up templates and publish.js.

This commit is contained in:
Jonathan Puckey 2011-05-28 15:43:26 +02:00
parent 1bcb8a3e34
commit 54b40faf5d
13 changed files with 90 additions and 204 deletions

View file

@ -8,11 +8,6 @@ var Operator = new function() {
divide: 'Division', equals: 'Comparison', modulo: 'Modulo'
};
var operatorClasses = {
Point: true,
Size: true
};
return {
isOperator: function(symbol) {
// As a convention, only add non static bean properties to
@ -57,74 +52,56 @@ var Helpers = {
}
}
return id.join('-');
},
isaClass: function(symbol) {
return symbol.is('CONSTRUCTOR') || symbol.isNamespace
}
};
var templates;
/** Called automatically by JsDoc Toolkit. */
function publish(symbolSet) {
publish.conf = { // trailing slash expected for dirs
ext: ".html",
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/",
templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/",
symbolsDir: "symbols/",
srcDir: "symbols/src/"
ext: '.html',
outDir: JSDOC.opt.d || SYS.pwd + '../out/jsdoc/',
templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
resourcesDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'resources/',
symbolsDir: 'symbols/',
srcDir: 'symbols/src/'
};
templates = {
_class: new JSDOC.JsPlate(publish.conf.templatesDir + "class.tmpl"),
method: new JSDOC.JsPlate(publish.conf.templatesDir + "method.tmpl"),
property: new JSDOC.JsPlate(publish.conf.templatesDir + "property.tmpl"),
parameters: new JSDOC.JsPlate(publish.conf.templatesDir + "parameters.tmpl"),
operators: new JSDOC.JsPlate(publish.conf.templatesDir + "operators.tmpl"),
examples: new JSDOC.JsPlate(publish.conf.templatesDir + "examples.tmpl"),
constructor: new JSDOC.JsPlate(publish.conf.templatesDir + "constructor.tmpl")
var templatesDir = publish.conf.templateDir + 'templates/';
publish.templates = {
_class: 'class.tmpl',
method: 'method.tmpl',
property: 'property.tmpl',
parameters: 'parameters.tmpl',
operators: 'operators.tmpl',
examples: 'examples.tmpl',
constructor: 'constructor.tmpl',
html: 'html.tmpl',
allClasses: 'allClasses.tmpl',
classesIndex: 'index.tmpl'
};
// is source output is suppressed, just display the links to the source file
if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) {
Link.prototype._makeSrcLink = function(srcFilePath) {
return "<"+srcFilePath+">";
}
for (var i in publish.templates) {
publish.templates[i] = new JSDOC.JsPlate(templatesDir +
publish.templates[i]);
}
// Copy over the static files
copyDirectory(
new java.io.File(publish.conf.templatesDir + 'resources/'),
new java.io.File(publish.conf.resourcesDir),
new java.io.File(publish.conf.outDir + 'resources/')
);
// used to allow Link to check the details of things being linked to
Link.symbolSet = symbolSet;
// create the required templates
try {
var classTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"class.tmpl");
var classesTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allclasses.tmpl");
}
catch(e) {
print("Couldn't create the required templates: "+e);
quit();
}
// some ustility filters
function hasNoParent($) {return ($.memberOf == "")}
function isaFile($) {return ($.is("FILE"))}
function isaClass($) {return ($.is("CONSTRUCTOR") || $.isNamespace)}
// get an array version of the symbolset, useful for filtering
var symbols = symbolSet.toArray();
// create the hilited source code files
var files = JSDOC.opt.srcFiles;
for (var i = 0, l = files.length; i < l; i++) {
var file = files[i];
var srcDir = publish.conf.outDir + "symbols/src/";
makeSrcFile(file, srcDir);
}
// get a list of all the classes in the symbolset
var classes = symbols.filter(isaClass).sort(makeSortby("alias"));
var symbols = symbolSet.toArray(),
files = JSDOC.opt.srcFiles,
classes = symbols.filter(Helpers.isaClass).sort(makeSortby('alias'));
// create a filemap in which outfiles must be to be named uniquely, ignoring case
if (JSDOC.opt.u) {
@ -133,18 +110,20 @@ function publish(symbolSet) {
for (var i = 0, l = classes.length; i < l; i++) {
var lcAlias = classes[i].alias.toLowerCase();
if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1;
else filemapCounts[lcAlias]++;
if (!filemapCounts[lcAlias]) {
filemapCounts[lcAlias] = 1;
} else {
filemapCounts[lcAlias]++;
}
Link.filemap[classes[i].alias] =
(filemapCounts[lcAlias] > 1)?
lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
Link.filemap[classes[i].alias] = (filemapCounts[lcAlias] > 1) ?
lcAlias + '_' + filemapCounts[lcAlias] : lcAlias;
}
}
// create a class index, displayed in the left-hand column of every class page
Link.base = "../";
publish.classesIndex = classesTemplate.process(classes); // kept in memory
Link.base = '../';
publish.conf.classesIndex = publish.templates.allClasses.process(classes); // kept in memory
// create each of the class pages
for (var i = 0, l = classes.length; i < l; i++) {
@ -158,57 +137,21 @@ function publish(symbolSet) {
}
Link.currentSymbol= symbol;
var output = "";
output = classTemplate.process(symbol);
IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output);
var html = publish.templates.html.process({
content: publish.templates._class.process(symbol),
title: symbol.alias
})
var name = ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias)
+ publish.conf.ext;
IO.saveFile(publish.conf.outDir + 'symbols/', name, html);
}
// regenerate the index with different relative links, used in the index pages
Link.base = "";
publish.classesIndex = classesTemplate.process(classes);
Link.base = '';
publish.conf.classesIndex = publish.templates.allClasses.process(classes);
// create the class index page
try {
var classesindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"index.tmpl");
}
catch(e) { print(e.message); quit(); }
var classesIndex = classesindexTemplate.process(classes);
IO.saveFile(publish.conf.outDir, "index"+publish.conf.ext, classesIndex);
classesindexTemplate = classesIndex = classes = null;
// create the file index page
try {
var fileindexTemplate = new JSDOC.JsPlate(publish.conf.templatesDir+"allfiles.tmpl");
}
catch(e) { print(e.message); quit(); }
var documentedFiles = symbols.filter(isaFile); // files that have file-level docs
var allFiles = []; // not all files have file-level docs, but we need to list every one
for (var i = 0; i < files.length; i++) {
allFiles.push(new JSDOC.Symbol(files[i], [], "FILE", new JSDOC.DocComment("/** */")));
}
for (var i = 0; i < documentedFiles.length; i++) {
var offset = files.indexOf(documentedFiles[i].alias);
allFiles[offset] = documentedFiles[i];
}
allFiles = allFiles.sort(makeSortby("name"));
// output the file index page
var filesIndex = fileindexTemplate.process(allFiles);
IO.saveFile(publish.conf.outDir, "files"+publish.conf.ext, filesIndex);
fileindexTemplate = filesIndex = files = null;
}
/** Just the first sentence (up to a full stop). Should not break on dotted variable names. */
function summarize(desc) {
if (typeof desc != "undefined")
return desc.match(/([\w\W]+?\.)[^a-z0-9_$]/i)? RegExp.$1 : desc;
var classesIndex = publish.templates.classesIndex.process(classes);
IO.saveFile(publish.conf.outDir, 'index' + publish.conf.ext, classesIndex);
}
/** Make a symbol sorter by some attribute. */
@ -226,38 +169,18 @@ function makeSortby(attribute) {
/** Pull in the contents of an external file at the given path. */
function include(path) {
var path = publish.conf.templatesDir+path;
var path = publish.conf.templateDir + path;
return IO.readFile(path);
}
/** Turn a raw source file into a code-hilited page in the docs. */
function makeSrcFile(path, srcDir, name) {
if (JSDOC.opt.s) return;
if (!name) {
name = path.replace(/\.\.?[\\\/]/g, "").replace(/[\\\/]/g, "_");
name = name.replace(/\:/g, "_");
}
var src = {path: path, name:name, charset: IO.encoding, hilited: ""};
if (defined(JSDOC.PluginManager)) {
JSDOC.PluginManager.run("onPublishSrc", src);
}
if (src.hilited) {
IO.saveFile(srcDir, name+publish.conf.ext, src.hilited);
}
}
/** Build output for displaying function parameters. */
function makeSignature(params) {
if (!params) return "()";
if (!params) return '()';
var postString = '';
var first = true;
params = params.filter(
function($) {
return $.name.indexOf(".") == -1; // don't show config params in signature
return $.name.indexOf('.') == -1; // don't show config params in signature
}
);
var signature = '';
@ -362,11 +285,6 @@ function stripTags(str, tag) {
return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), '');
}
function copyStatic(dir) {
var dir = publish.conf.templatesDir + 'resources/';
}
function copyDirectory(sourceLocation, targetLocation) {
if (sourceLocation.isDirectory()) {
if (!targetLocation.exists()) {

View file

@ -1,35 +0,0 @@
<symbol alias="{+data.alias+}">
<name>{+data.name+}</name>
<memberOf>{+data.memberOf+}</memberOf>
<isStatic>{+data.isStatic+}</isStatic>
<isa>{+data.isa+}</isa>
<desc>{+data.desc+}</desc>
<classDesc>{+data.classDesc+}</classDesc>
<methods><for each="method" in="data.methods">
<method>
<name>{+method.name+}</name>
<memberOf>{+method.memberOf+}</memberOf>
<isStatic>{+method.isStatic+}</isStatic>
<desc>{+method.desc+}</desc>
<params><for each="param" in="method.params">
<param>
<type>{+param.type+}</type>
<name>{+param.name+}</name>
<desc>{+param.desc+}</desc>
<defaultValue>{+param.defaultValue+}</defaultValue>
</param></for>
</params>
</method></for>
</methods>
<properties><for each="property" in="data.properties">
<property>
<name>{+property.name+}</name>
<memberOf>{+property.memberOf+}</memberOf>
<isStatic>{+property.isStatic+}</isStatic>
<desc>{+property.desc+}</desc>
<type>{+property.type+}</type>
</property></for>
</properties>
</symbol>

View file

@ -42,19 +42,6 @@
inheritedClasses[symbol.memberOf].methods.push(symbol);
}
!}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>{+data.alias+}</title>
<base target="classFrame">
<link rel="stylesheet" href="../resources/css/reference.css" type="text/css">
<link rel="stylesheet" href="../resources/css/style.css" type="text/css">
<link rel="stylesheet" href="../resources/css/lighter.css" type="text/css">
<script src="../resources/js/bootstrap.js" type="text/javascript"></script>
<script src="../resources/js/lighter.js" type="text/javascript"></script>
<script src="../resources/js/reference.js" type="text/javascript"></script>
</head>
<body class="reference">
<div class="reference-class">
<h1>{+data.alias+}</h1>
<if test="inheritedClassLinks.length">
@ -65,9 +52,9 @@
<!-- ============================== constructors ========================= -->
<if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore">
<div class="reference-members"><h2>Constructors</h2>
{+ templates.constructor.process(data) +}
{+ publish.templates.constructor.process(data) +}
<for each="constructor" in="constructors">
{+ templates.constructor.process(constructor) +}
{+ publish.templates.constructor.process(constructor) +}
</for>
</div>
</if>
@ -76,7 +63,7 @@
<if test="defined(operators)">
<div class="reference-members"><h2>Operators</h2>
<for each="member" in="operators">
{+ templates.operators.process(member) +}
{+ publish.templates.operators.process(member) +}
</for>
</div>
</if>
@ -84,7 +71,7 @@
<if test="defined(ownProperties) && ownProperties.length">
<div class="reference-members"><h2>Properties</h2>
<for each="member" in="ownProperties">
{+ templates.property.process(member) +}
{+ publish.templates.property.process(member) +}
</for>
</div>
</if>
@ -93,14 +80,14 @@
<if test="defined(ownMethods) && ownMethods.length">
<div class="reference-members"><h2>Functions</h2>
<for each="member" in="ownMethods">
{+ templates.method.process(member) +}
{+ publish.templates.method.process(member) +}
</for>
</div>
</if>
<if test="defined(staticMethods) && staticMethods.length">
<div class="reference-members"><h2>Static Functions</h2>
<for each="member" in="staticMethods">
{+ templates.method.process(member) +}
{+ publish.templates.method.process(member) +}
</for>
</div>
</if>
@ -109,7 +96,7 @@
<if test="inheritedClass.properties.length">
<div class="reference-members"><h2>Inherited properties from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.properties">
{+ templates.property.process(member) +}
{+ publish.templates.property.process(member) +}
</for>
</div>
</if>
@ -117,9 +104,8 @@
<if test="inheritedClass.methods.length">
<div class="reference-members"><h2>Inherited functions from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.methods">
{+ templates.method.process(member) +}
{+ publish.templates.method.process(member) +}
</for>
</div>
</if>
</for>
</body>
</for>

View file

@ -28,7 +28,7 @@
<pre>{+example+}</pre>
</for>
</if>
{+ templates.parameters.process(data) +}
{+ publish.templates.parameters.process(data) +}
<if test="data.returns.length">
<ul><b>Returns:</b>
<li>

View file

@ -0,0 +1,15 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>{+ data.title +}</title>
<base target="classFrame">
<link rel="stylesheet" href="../resources/css/reference.css" type="text/css">
<link rel="stylesheet" href="../resources/css/style.css" type="text/css">
<link rel="stylesheet" href="../resources/css/lighter.css" type="text/css">
<script src="../resources/js/bootstrap.js" type="text/javascript"></script>
<script src="../resources/js/lighter.js" type="text/javascript"></script>
<script src="../resources/js/reference.js" type="text/javascript"></script>
</head>
<body class="reference">
{+ data.content +}
</body>

View file

@ -25,7 +25,7 @@
<for each="thisClass" in="data">
<div>
<h2>{+(new Link().toSymbol(thisClass.alias))+}</h2>
{+processInlineTags(summarize(thisClass.classDesc))+}
{+processInlineTags(thisClass.classDesc)+}
</div>
<hr />
</for>

View file

@ -22,9 +22,10 @@
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+ memberId +}', false);"></div>
<div class="clear"></div>
</div>
<div class="member-text">{+processInlineTags(data.desc)+}
{+ new JSDOC.JsPlate(publish.conf.templatesDir+"examples.tmpl").process(data) +}
{+ new JSDOC.JsPlate(publish.conf.templatesDir+"parameters.tmpl").process(data) +}
<div class="member-text">
{+ processInlineTags(data.desc) +}
{+ publish.templates.examples.process(data) +}
{+ publish.templates.parameters.process(data) +}
<if test="data.returns.length">
<ul><b>Returns:</b>
<for each="item" in="data.returns">

View file

@ -34,8 +34,9 @@
<div class="clear"></div>
</div>
<if test="operator.type">
<div class="member-text">{+processInlineTags(operator.desc)+}
{+ new JSDOC.JsPlate(publish.conf.templatesDir+"examples.tmpl").process(operator) +}
<div class="member-text">
{+processInlineTags(operator.desc)+}
{+ publish.templates.examples.process(operator) +}
<ul><b>Returns:</b>
<for each="item" in="operator.returns">
<li>

View file

@ -26,9 +26,9 @@
</div>
<if test="data.type">
<div class="member-text">
{+processInlineTags(data.desc)+}
{+ processInlineTags(data.desc) +}
<if test="data.readOnly"><p>Read only.</p></if>
{+ new JSDOC.JsPlate(publish.conf.templatesDir+"examples.tmpl").process(data) +}
{+ publish.templates.examples.process(data) +}
<if test="data.defaultValue">
<ul><b>Default:</b>
<li>