More jsdoc work, including exporting of templatedocs.

This commit is contained in:
Jonathan Puckey 2011-06-01 12:19:15 +02:00
parent 5dd5694e3b
commit 3274102dec
7 changed files with 117 additions and 77 deletions

View file

@ -10,7 +10,18 @@
# All rights reserved. See LICENSE file for details. # All rights reserved. See LICENSE file for details.
# Generate documentation # Generate documentation
#
# MODE:
# docs Generates the JS API docs
# templatedocs Generates the website templates for the online JS API docs
if [ $# -eq 0 ]
then
MODE="docs"
else
MODE=$1
fi
cd jsdoc-toolkit cd jsdoc-toolkit
java -jar jsrun.jar app/run.js -c=conf/paperjs.conf java -jar jsrun.jar app/run.js -c=conf/$MODE.conf
cd .. cd ..

View file

@ -26,5 +26,8 @@
d: "../../out/docs", d: "../../out/docs",
// use this template // use this template
t: "templates/jsdoc" t: "templates/jsdoc",
// set variables:
D: "renderMode:docs"
} }

View file

@ -0,0 +1,33 @@
/*
This is an example of one way you could set up a configuration file to more
conveniently define some commandline options. You might like to do this if
you frequently reuse the same options. Note that you don't need to define
every option in this file, you can combine a configuration file with
additional options on the commandline if your wish.
You would include this configuration file by running JsDoc Toolkit like so:
java -jar jsrun.jar app/run.js -c=conf/sample.conf
*/
{
// source files to use
_: ['../../src'],
r: 2,
// document all functions, even uncommented ones
a: false,
// including those marked @private
p: false,
// use this directory as the output directory
d: "../../out/templates",
// use this template
t: "templates/jsdoc",
// set variables:
D: "renderMode:templatedocs"
}

View file

@ -1,29 +0,0 @@
Point
Rectangle
Size
Matrix
Color
GrayColor
RGBColor
GradientColor
Item
PathItem
Path
CompoundPath
TextItem
PointText
Raster
Group
Layer
PlacedItem
Symbol
Project
ProjectView
Segment
Curve
PathStyle
CharacterStyle
ParagraphStyle
Gradient
GradientStop
Symbol

View file

@ -1,14 +1,16 @@
/** Called automatically by JsDoc Toolkit. */ /** Called automatically by JsDoc Toolkit. */
function publish(symbolSet) { function publish(symbolSet) {
var renderMode = JSDOC.opt.D.renderMode;
publish.conf = { // trailing slash expected for dirs publish.conf = { // trailing slash expected for dirs
ext: '.html', ext: renderMode == 'docs' ? '.html' : '.jstl',
outDir: JSDOC.opt.d || SYS.pwd + '../out/jsdoc/', outDir: JSDOC.opt.d || SYS.pwd + '../out/jsdoc/',
templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/', templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
staticDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'static/', staticDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'static/',
symbolsDir: 'packages/', symbolsDir: renderMode == 'docs' ? 'packages/' : 'paper/',
srcDir: 'symbols/src/' srcDir: 'symbols/src/',
renderMode: renderMode
}; };
publish.conf.packagesDir = publish.conf.outDir + 'packages/'; publish.conf.packagesDir = publish.conf.outDir + publish.conf.symbolsDir;
var templatesDir = publish.conf.templateDir + 'templates/'; var templatesDir = publish.conf.templateDir + 'templates/';
publish.templates = { publish.templates = {
_class: 'class.tmpl', _class: 'class.tmpl',
@ -29,12 +31,17 @@ function publish(symbolSet) {
publish.templates[i] = new JSDOC.JsPlate(templatesDir + publish.templates[i] = new JSDOC.JsPlate(templatesDir +
publish.templates[i]); publish.templates[i]);
} }
// Copy over the static files if (renderMode == 'docs') {
Utils.copyDirectory( // Copy over the static files
new java.io.File(publish.conf.staticDir), Utils.copyDirectory(
new java.io.File(publish.conf.outDir) 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 // used to allow Link to check the details of things being linked to
Link.symbolSet = symbolSet; Link.symbolSet = symbolSet;
@ -77,16 +84,19 @@ function publish(symbolSet) {
} }
Link.currentSymbol= symbol; Link.currentSymbol= symbol;
var html = publish.templates.html.process({ var html = publish.templates._class.process(symbol);
content: publish.templates._class.process(symbol),
title: symbol.alias
});
var name = ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias) var name = ((JSDOC.opt.u)? Link.filemap[symbol.alias] : symbol.alias)
+ publish.conf.ext; + publish.conf.ext;
if (renderMode == 'docs') {
html = publish.templates.html.process({
content: html,
title: symbol.alias
});
}
IO.saveFile(publish.conf.packagesDir, name, html); IO.saveFile(publish.conf.packagesDir, name, html);
} }
if (renderMode == 'docs')
Utils.publishMenu(); Utils.publishMenu();
} }
var Operator = new function() { var Operator = new function() {
@ -195,6 +205,17 @@ var Utils = {
} }
}, },
deleteFiles: function(path) {
if (path.isDirectory()) {
var files = path.listFiles();
for (var i = 0, l = files.length; i < l; i++) {
Utils.deleteFiles(files[i]);
}
}
if (!path['delete']())
throw Error('Could not delete ' + path);
},
processGroupTitle: function(str, symbol) { processGroupTitle: function(str, symbol) {
var groupTitle = str.match(/\{@grouptitle ([^}]+)\}/); var groupTitle = str.match(/\{@grouptitle ([^}]+)\}/);
if (groupTitle) { if (groupTitle) {

View file

@ -1,5 +1,5 @@
{! data.classId = data.alias.toLowerCase() !}
{! {!
data.classId = data.alias.toLowerCase();
var constructors = data.methods.filter(function($){return $.memberOf == data.alias && $.isConstructor}); var constructors = data.methods.filter(function($){return $.memberOf == data.alias && $.isConstructor});
var ownProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isConstructor}); var ownProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && !$.isStatic && !$.isConstructor});
var staticProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic && !$.isConstructor}); var staticProperties = data.properties.filter(function($){return $.memberOf == data.alias && !$.isNamespace && $.isStatic && !$.isConstructor});
@ -43,14 +43,14 @@
} }
!} !}
<div class="reference-class"> <div class="reference-class">
<h1>{+data.alias+}</h1> <if test="publish.conf.renderMode == 'docs'"><h1>{+data.alias+}</h1></if>
<if test="inheritedClassLinks.length"> <if test="inheritedClassLinks.length">
<p> Extends {+ inheritedClassLinks.join(', ') +}</p> <p> Extends {+ inheritedClassLinks.join(', ') +}</p>
</if> </if>
{+Utils.processInlineTags(data.classDesc)+} {+Utils.processInlineTags(data.classDesc)+}
</div> </div>
<!-- ============================== constructors ========================= -->
<if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore && data.desc.length"> <if test="!/(Event|Style)/.test(data.alias) && !data.isNamespace && !data.ignore && data.desc.length">
<!-- ============================== constructors ========================= -->
<div class="reference-members"><h2>Constructors</h2> <div class="reference-members"><h2>Constructors</h2>
{+ publish.templates.constructor.process(data) +} {+ publish.templates.constructor.process(data) +}
<for each="constructor" in="constructors"> <for each="constructor" in="constructors">
@ -59,8 +59,8 @@
</div> </div>
</if> </if>
<!-- ============================== properties ========================= -->
<if test="defined(operators)"> <if test="defined(operators)">
<!-- ============================== properties ========================= -->
<div class="reference-members"><h2>Operators</h2> <div class="reference-members"><h2>Operators</h2>
<for each="member" in="operators"> <for each="member" in="operators">
{+ publish.templates.operators.process(member) +} {+ publish.templates.operators.process(member) +}
@ -76,8 +76,8 @@
</div> </div>
</if> </if>
<!-- ============================== method details ========================= -->
<if test="defined(ownMethods) && ownMethods.length"> <if test="defined(ownMethods) && ownMethods.length">
<!-- ============================== methods ================================ -->
<div class="reference-members"><h2>Functions</h2> <div class="reference-members"><h2>Functions</h2>
<for each="member" in="ownMethods"> <for each="member" in="ownMethods">
{+ publish.templates.method.process(member) +} {+ publish.templates.method.process(member) +}
@ -92,21 +92,24 @@
</div> </div>
</if> </if>
<for each="inheritedClass" in="inheritedClasses"> <for each="inheritedClass" in="inheritedClasses">
<!-- ============================== properties ========================= --> <if test="inheritedClass.properties.length">
<if test="inheritedClass.properties.length"> <!-- =========================== inherited properties ====================== -->
<div class="reference-members"><h2>Properties inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2> <div class="reference-members"><h2>Properties inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.properties"> <for each="member" in="inheritedClass.properties">
{+ publish.templates.property.process(member) +} {+ publish.templates.property.process(member) +}
</for>
</div>
</if>
<!-- ============================== properties ========================= -->
<if test="inheritedClass.methods.length">
<div class="reference-members"><h2>Functions inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.methods">
{+ publish.templates.method.process(member) +}
</for>
</div>
</if>
</for> </for>
<p class="footer">Copyright &#169; 21011 <a href="http://www.lehni.org" target="_blank">J&uuml;rg Lehni</a> &amp; <a href="http://www.jonathanpuckey.com" target="_blank">Jonathan Puckey</a>. All Rights Reserved.</p> </div>
</if>
<if test="inheritedClass.methods.length">
<!-- =========================== inherited methods ========================= -->
<div class="reference-members"><h2>Functions inherited from {+ new Link().toSymbol(inheritedClass.className) +}</h2>
<for each="member" in="inheritedClass.methods">
{+ publish.templates.method.process(member) +}
</for>
</div>
</if>
</for>
<if test="publish.conf.renderMode == 'docs'">
<!-- =========================== copyright notice ========================= -->
<p class="footer">Copyright &#169; 21011 <a href="http://www.lehni.org" target="_blank">J&uuml;rg Lehni</a> &amp; <a href="http://www.jonathanpuckey.com" target="_blank">Jonathan Puckey</a>. All Rights Reserved.</p>
</if>

View file

@ -5,9 +5,7 @@
if (data.returns.length == 0) if (data.returns.length == 0)
data.returns = [{type: data.memberOf ? data.memberOf : data.alias, desc: ''}]; data.returns = [{type: data.memberOf ? data.memberOf : data.alias, desc: ''}];
!} !}
<if test="defined(data.groupTitle)"> <if test="defined(data.groupTitle)"><h3>{+data.groupTitle+}</h3></if>
<h3>{+data.groupTitle+}</h3>
</if>
<div id="{+constructorId+}" class="member"> <div id="{+constructorId+}" class="member">
<div id="{+constructorId+}-link" class="member-link"> <div id="{+constructorId+}-link" class="member-link">
<a name="{+constructorId+}" href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ Utils.makeSignature(data.params) +}</tt></a> <a name="{+constructorId+}" href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ Utils.makeSignature(data.params) +}</tt></a>
@ -23,10 +21,10 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="member-text">{+Utils.processInlineTags(data.desc)+} <div class="member-text">{+Utils.processInlineTags(data.desc)+}
{+ publish.templates.parameters.process(data) +} {+ publish.templates.parameters.process(data) +}
{+ publish.templates.returns.process(data) +} {+ publish.templates.returns.process(data) +}
{+ Utils.parseExamples(data) +} {+ Utils.parseExamples(data) +}
{+ publish.templates.seeAlsos.process(data) +} {+ publish.templates.seeAlsos.process(data) +}
</div> </div>
</div> </div>