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' divide: 'Division', equals: 'Comparison', modulo: 'Modulo'
}; };
var operatorClasses = {
Point: true,
Size: true
};
return { return {
isOperator: function(symbol) { isOperator: function(symbol) {
// As a convention, only add non static bean properties to // As a convention, only add non static bean properties to
@ -57,74 +52,56 @@ var Helpers = {
} }
} }
return id.join('-'); return id.join('-');
},
isaClass: function(symbol) {
return symbol.is('CONSTRUCTOR') || symbol.isNamespace
} }
}; };
var templates;
/** Called automatically by JsDoc Toolkit. */ /** Called automatically by JsDoc Toolkit. */
function publish(symbolSet) { function publish(symbolSet) {
publish.conf = { // trailing slash expected for dirs publish.conf = { // trailing slash expected for dirs
ext: ".html", ext: '.html',
outDir: JSDOC.opt.d || SYS.pwd+"../out/jsdoc/", outDir: JSDOC.opt.d || SYS.pwd + '../out/jsdoc/',
templatesDir: JSDOC.opt.t || SYS.pwd+"../templates/jsdoc/", templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
symbolsDir: "symbols/", resourcesDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'resources/',
srcDir: "symbols/src/" symbolsDir: 'symbols/',
srcDir: 'symbols/src/'
}; };
templates = { var templatesDir = publish.conf.templateDir + 'templates/';
_class: new JSDOC.JsPlate(publish.conf.templatesDir + "class.tmpl"), publish.templates = {
method: new JSDOC.JsPlate(publish.conf.templatesDir + "method.tmpl"), _class: 'class.tmpl',
property: new JSDOC.JsPlate(publish.conf.templatesDir + "property.tmpl"), method: 'method.tmpl',
parameters: new JSDOC.JsPlate(publish.conf.templatesDir + "parameters.tmpl"), property: 'property.tmpl',
operators: new JSDOC.JsPlate(publish.conf.templatesDir + "operators.tmpl"), parameters: 'parameters.tmpl',
examples: new JSDOC.JsPlate(publish.conf.templatesDir + "examples.tmpl"), operators: 'operators.tmpl',
constructor: new JSDOC.JsPlate(publish.conf.templatesDir + "constructor.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 for (var i in publish.templates) {
if (JSDOC.opt.s && defined(Link) && Link.prototype._makeSrcLink) { publish.templates[i] = new JSDOC.JsPlate(templatesDir +
Link.prototype._makeSrcLink = function(srcFilePath) { publish.templates[i]);
return "<"+srcFilePath+">";
}
} }
// Copy over the static files // Copy over the static files
copyDirectory( copyDirectory(
new java.io.File(publish.conf.templatesDir + 'resources/'), new java.io.File(publish.conf.resourcesDir),
new java.io.File(publish.conf.outDir + 'resources/') new java.io.File(publish.conf.outDir + 'resources/')
); );
// used to allow Link to check the details of things being linked to // used to allow Link to check the details of things being linked to
Link.symbolSet = symbolSet; 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 // get an array version of the symbolset, useful for filtering
var symbols = symbolSet.toArray(); var symbols = symbolSet.toArray(),
files = JSDOC.opt.srcFiles,
// create the hilited source code files classes = symbols.filter(Helpers.isaClass).sort(makeSortby('alias'));
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"));
// create a filemap in which outfiles must be to be named uniquely, ignoring case // create a filemap in which outfiles must be to be named uniquely, ignoring case
if (JSDOC.opt.u) { if (JSDOC.opt.u) {
@ -133,18 +110,20 @@ function publish(symbolSet) {
for (var i = 0, l = classes.length; i < l; i++) { for (var i = 0, l = classes.length; i < l; i++) {
var lcAlias = classes[i].alias.toLowerCase(); var lcAlias = classes[i].alias.toLowerCase();
if (!filemapCounts[lcAlias]) filemapCounts[lcAlias] = 1; if (!filemapCounts[lcAlias]) {
else filemapCounts[lcAlias]++; filemapCounts[lcAlias] = 1;
} else {
filemapCounts[lcAlias]++;
}
Link.filemap[classes[i].alias] = Link.filemap[classes[i].alias] = (filemapCounts[lcAlias] > 1) ?
(filemapCounts[lcAlias] > 1)? lcAlias + '_' + filemapCounts[lcAlias] : lcAlias;
lcAlias+"_"+filemapCounts[lcAlias] : lcAlias;
} }
} }
// create a class index, displayed in the left-hand column of every class page // create a class index, displayed in the left-hand column of every class page
Link.base = "../"; Link.base = '../';
publish.classesIndex = classesTemplate.process(classes); // kept in memory publish.conf.classesIndex = publish.templates.allClasses.process(classes); // kept in memory
// create each of the class pages // create each of the class pages
for (var i = 0, l = classes.length; i < l; i++) { for (var i = 0, l = classes.length; i < l; i++) {
@ -158,57 +137,21 @@ function publish(symbolSet) {
} }
Link.currentSymbol= symbol; Link.currentSymbol= symbol;
var output = ""; var html = publish.templates.html.process({
output = classTemplate.process(symbol); content: publish.templates._class.process(symbol),
title: symbol.alias
IO.saveFile(publish.conf.outDir+"symbols/", ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) + publish.conf.ext, output); })
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 // regenerate the index with different relative links, used in the index pages
Link.base = ""; Link.base = '';
publish.classesIndex = classesTemplate.process(classes); publish.conf.classesIndex = publish.templates.allClasses.process(classes);
// create the class index page var classesIndex = publish.templates.classesIndex.process(classes);
try { IO.saveFile(publish.conf.outDir, 'index' + publish.conf.ext, classesIndex);
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;
} }
/** Make a symbol sorter by some attribute. */ /** 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. */ /** Pull in the contents of an external file at the given path. */
function include(path) { function include(path) {
var path = publish.conf.templatesDir+path; var path = publish.conf.templateDir + path;
return IO.readFile(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. */ /** Build output for displaying function parameters. */
function makeSignature(params) { function makeSignature(params) {
if (!params) return "()"; if (!params) return '()';
var postString = ''; var postString = '';
var first = true; var first = true;
params = params.filter( params = params.filter(
function($) { 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 = ''; var signature = '';
@ -362,11 +285,6 @@ function stripTags(str, tag) {
return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), ''); return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), '');
} }
function copyStatic(dir) {
var dir = publish.conf.templatesDir + 'resources/';
}
function copyDirectory(sourceLocation, targetLocation) { function copyDirectory(sourceLocation, targetLocation) {
if (sourceLocation.isDirectory()) { if (sourceLocation.isDirectory()) {
if (!targetLocation.exists()) { 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); 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"> <div class="reference-class">
<h1>{+data.alias+}</h1> <h1>{+data.alias+}</h1>
<if test="inheritedClassLinks.length"> <if test="inheritedClassLinks.length">
@ -65,9 +52,9 @@
<!-- ============================== constructors ========================= --> <!-- ============================== constructors ========================= -->
<if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore"> <if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore">
<div class="reference-members"><h2>Constructors</h2> <div class="reference-members"><h2>Constructors</h2>
{+ templates.constructor.process(data) +} {+ publish.templates.constructor.process(data) +}
<for each="constructor" in="constructors"> <for each="constructor" in="constructors">
{+ templates.constructor.process(constructor) +} {+ publish.templates.constructor.process(constructor) +}
</for> </for>
</div> </div>
</if> </if>
@ -76,7 +63,7 @@
<if test="defined(operators)"> <if test="defined(operators)">
<div class="reference-members"><h2>Operators</h2> <div class="reference-members"><h2>Operators</h2>
<for each="member" in="operators"> <for each="member" in="operators">
{+ templates.operators.process(member) +} {+ publish.templates.operators.process(member) +}
</for> </for>
</div> </div>
</if> </if>
@ -84,7 +71,7 @@
<if test="defined(ownProperties) && ownProperties.length"> <if test="defined(ownProperties) && ownProperties.length">
<div class="reference-members"><h2>Properties</h2> <div class="reference-members"><h2>Properties</h2>
<for each="member" in="ownProperties"> <for each="member" in="ownProperties">
{+ templates.property.process(member) +} {+ publish.templates.property.process(member) +}
</for> </for>
</div> </div>
</if> </if>
@ -93,14 +80,14 @@
<if test="defined(ownMethods) && ownMethods.length"> <if test="defined(ownMethods) && ownMethods.length">
<div class="reference-members"><h2>Functions</h2> <div class="reference-members"><h2>Functions</h2>
<for each="member" in="ownMethods"> <for each="member" in="ownMethods">
{+ templates.method.process(member) +} {+ publish.templates.method.process(member) +}
</for> </for>
</div> </div>
</if> </if>
<if test="defined(staticMethods) && staticMethods.length"> <if test="defined(staticMethods) && staticMethods.length">
<div class="reference-members"><h2>Static Functions</h2> <div class="reference-members"><h2>Static Functions</h2>
<for each="member" in="staticMethods"> <for each="member" in="staticMethods">
{+ templates.method.process(member) +} {+ publish.templates.method.process(member) +}
</for> </for>
</div> </div>
</if> </if>
@ -109,7 +96,7 @@
<if test="inheritedClass.properties.length"> <if test="inheritedClass.properties.length">
<div class="reference-members"><h2>Inherited properties from {+ new Link().toSymbol(inheritedClass.className) +}</h2> <div class="reference-members"><h2>Inherited properties from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.properties"> <for each="member" in="inheritedClass.properties">
{+ templates.property.process(member) +} {+ publish.templates.property.process(member) +}
</for> </for>
</div> </div>
</if> </if>
@ -117,9 +104,8 @@
<if test="inheritedClass.methods.length"> <if test="inheritedClass.methods.length">
<div class="reference-members"><h2>Inherited functions from {+ new Link().toSymbol(inheritedClass.className) +}</h2> <div class="reference-members"><h2>Inherited functions from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.methods"> <for each="member" in="inheritedClass.methods">
{+ templates.method.process(member) +} {+ publish.templates.method.process(member) +}
</for> </for>
</div> </div>
</if> </if>
</for> </for>
</body>

View file

@ -28,7 +28,7 @@
<pre>{+example+}</pre> <pre>{+example+}</pre>
</for> </for>
</if> </if>
{+ templates.parameters.process(data) +} {+ publish.templates.parameters.process(data) +}
<if test="data.returns.length"> <if test="data.returns.length">
<ul><b>Returns:</b> <ul><b>Returns:</b>
<li> <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"> <for each="thisClass" in="data">
<div> <div>
<h2>{+(new Link().toSymbol(thisClass.alias))+}</h2> <h2>{+(new Link().toSymbol(thisClass.alias))+}</h2>
{+processInlineTags(summarize(thisClass.classDesc))+} {+processInlineTags(thisClass.classDesc)+}
</div> </div>
<hr /> <hr />
</for> </for>

View file

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

View file

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

View file

@ -26,9 +26,9 @@
</div> </div>
<if test="data.type"> <if test="data.type">
<div class="member-text"> <div class="member-text">
{+processInlineTags(data.desc)+} {+ processInlineTags(data.desc) +}
<if test="data.readOnly"><p>Read only.</p></if> <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"> <if test="data.defaultValue">
<ul><b>Default:</b> <ul><b>Default:</b>
<li> <li>