mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
jsdoc template: Move helper functions into global Utils object and replace <pre> tags with <pre class='code'> to have them highlighted by CodeMirror.
This commit is contained in:
parent
df86a91d7c
commit
14e46fe78f
8 changed files with 288 additions and 285 deletions
|
@ -1,3 +1,94 @@
|
||||||
|
/** 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/',
|
||||||
|
templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
|
||||||
|
staticDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'static/',
|
||||||
|
symbolsDir: 'packages/',
|
||||||
|
srcDir: 'symbols/src/'
|
||||||
|
};
|
||||||
|
publish.conf.packagesDir = publish.conf.outDir + 'packages/';
|
||||||
|
var templatesDir = publish.conf.templateDir + 'templates/';
|
||||||
|
publish.templates = {
|
||||||
|
_class: 'class.tmpl',
|
||||||
|
method: 'method.tmpl',
|
||||||
|
property: 'property.tmpl',
|
||||||
|
parameters: 'parameters.tmpl',
|
||||||
|
operators: 'operators.tmpl',
|
||||||
|
returns: 'returns.tmpl',
|
||||||
|
seeAlsos: 'see-alsos.tmpl',
|
||||||
|
example: 'example.tmpl',
|
||||||
|
constructor: 'constructor.tmpl',
|
||||||
|
html: 'html.tmpl',
|
||||||
|
allClasses: 'allClasses.tmpl',
|
||||||
|
menu: 'packages.tmpl'
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i in publish.templates) {
|
||||||
|
publish.templates[i] = new JSDOC.JsPlate(templatesDir +
|
||||||
|
publish.templates[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy over the static files
|
||||||
|
Utils.copyDirectory(
|
||||||
|
new java.io.File(publish.conf.staticDir),
|
||||||
|
new java.io.File(publish.conf.outDir)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (JSDOC.opt.u) {
|
||||||
|
var filemapCounts = {};
|
||||||
|
Link.filemap = {};
|
||||||
|
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]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Link.filemap[classes[i].alias] = (filemapCounts[lcAlias] > 1) ?
|
||||||
|
lcAlias + '_' + filemapCounts[lcAlias] : lcAlias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 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.packagesDir, name, html);
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.publishMenu();
|
||||||
|
}
|
||||||
|
|
||||||
var Operator = new function() {
|
var Operator = new function() {
|
||||||
var operators = {
|
var operators = {
|
||||||
add: '+', subtract: '-', multiply: '*', divide: '/', equals: '==',
|
add: '+', subtract: '-', multiply: '*', divide: '/', equals: '==',
|
||||||
|
@ -28,7 +119,7 @@ var Operator = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Helpers = {
|
var Utils = {
|
||||||
getSymbolId: function(symbol) {
|
getSymbolId: function(symbol) {
|
||||||
var id = [symbol.name.toLowerCase().replace(/[\^][0-9]/g, '')];
|
var id = [symbol.name.toLowerCase().replace(/[\^][0-9]/g, '')];
|
||||||
if (symbol.params) {
|
if (symbol.params) {
|
||||||
|
@ -75,291 +166,203 @@ var Helpers = {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return out.join('\n');
|
return out.join('\n');
|
||||||
}
|
},
|
||||||
};
|
|
||||||
|
|
||||||
/** 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/',
|
|
||||||
templateDir: JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/',
|
|
||||||
staticDir: (JSDOC.opt.t || SYS.pwd + '../templates/jsdoc/') + 'static/',
|
|
||||||
symbolsDir: 'packages/',
|
|
||||||
srcDir: 'symbols/src/'
|
|
||||||
};
|
|
||||||
publish.conf.packagesDir = publish.conf.outDir + 'packages/';
|
|
||||||
var templatesDir = publish.conf.templateDir + 'templates/';
|
|
||||||
publish.templates = {
|
|
||||||
_class: 'class.tmpl',
|
|
||||||
method: 'method.tmpl',
|
|
||||||
property: 'property.tmpl',
|
|
||||||
parameters: 'parameters.tmpl',
|
|
||||||
operators: 'operators.tmpl',
|
|
||||||
returns: 'returns.tmpl',
|
|
||||||
seeAlsos: 'see-alsos.tmpl',
|
|
||||||
example: 'example.tmpl',
|
|
||||||
constructor: 'constructor.tmpl',
|
|
||||||
html: 'html.tmpl',
|
|
||||||
allClasses: 'allClasses.tmpl',
|
|
||||||
menu: 'packages.tmpl'
|
|
||||||
};
|
|
||||||
|
|
||||||
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.staticDir),
|
|
||||||
new java.io.File(publish.conf.outDir)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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,
|
|
||||||
classes = symbols.filter(Helpers.isaClass).sort(makeSortby('alias'));
|
|
||||||
|
|
||||||
// create a filemap in which outfiles must be to be named uniquely, ignoring case
|
stripTags: function(str, tag) {
|
||||||
if (JSDOC.opt.u) {
|
var tag = tag || '.*?'; // Default: all tags
|
||||||
var filemapCounts = {};
|
return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), '');
|
||||||
Link.filemap = {};
|
},
|
||||||
for (var i = 0, l = classes.length; i < l; i++) {
|
|
||||||
var lcAlias = classes[i].alias.toLowerCase();
|
copyDirectory: function(sourceLocation, targetLocation) {
|
||||||
|
if (sourceLocation.isDirectory()) {
|
||||||
if (!filemapCounts[lcAlias]) {
|
if (!targetLocation.exists()) {
|
||||||
filemapCounts[lcAlias] = 1;
|
targetLocation.mkdir();
|
||||||
} else {
|
|
||||||
filemapCounts[lcAlias]++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Link.filemap[classes[i].alias] = (filemapCounts[lcAlias] > 1) ?
|
|
||||||
lcAlias + '_' + filemapCounts[lcAlias] : lcAlias;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Link.base = '../';
|
|
||||||
|
|
||||||
// create each of the class pages
|
var children = sourceLocation.list();
|
||||||
for (var i = 0, l = classes.length; i < l; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
var symbol = classes[i];
|
Utils.copyDirectory(new File(sourceLocation, children[i]),
|
||||||
|
new File(targetLocation, children[i]));
|
||||||
symbol.events = symbol.getEvents(); // 1 order matters
|
}
|
||||||
symbol.methods = symbol.getMethods(); // 2
|
} else {
|
||||||
for (var j = 0; j < symbol.methods.length; j++) {
|
// Copy the file with FileChannels:
|
||||||
var method = symbol.methods[j];
|
targetLocation.createNewFile();
|
||||||
method.isOperator = Operator.isOperator(method);
|
var src = new java.io.FileInputStream(sourceLocation).getChannel();
|
||||||
|
var dst = new java.io.FileOutputStream(targetLocation).getChannel();
|
||||||
|
var amount = dst.transferFrom(src, 0, src.size());
|
||||||
|
src.close();
|
||||||
|
dst.close();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
Link.currentSymbol= symbol;
|
|
||||||
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.packagesDir, name, html);
|
|
||||||
}
|
|
||||||
|
|
||||||
publishMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
function publishMenu() {
|
processGroupTitle: function(str, symbol) {
|
||||||
load(JSDOC.opt.t + 'classLayout.js');
|
var groupTitle = str.match(/\{@grouptitle ([^}]+)\}/);
|
||||||
function parseClassNames(classNames) {
|
if (groupTitle) {
|
||||||
var out = '';
|
symbol.groupTitle = groupTitle[1];
|
||||||
for (var i = 0, l = classNames.length; i < l; i++) {
|
str = str.replace(/\{@grouptitle ([^}]+)\}/, '');
|
||||||
if (typeof classNames[i] == 'string') {
|
}
|
||||||
var name = classNames[i];
|
return str;
|
||||||
out += (name == 'ruler') ? getRuler() : getLink(name);
|
},
|
||||||
} else {
|
|
||||||
for (var j in classNames[i]) {
|
publishMenu: function() {
|
||||||
out += getHeading(j);
|
load(JSDOC.opt.t + 'classLayout.js');
|
||||||
out += parseClassNames(classNames[i][j]);
|
function parseClassNames(classNames) {
|
||||||
|
var out = '';
|
||||||
|
for (var i = 0, l = classNames.length; i < l; i++) {
|
||||||
|
if (typeof classNames[i] == 'string') {
|
||||||
|
var name = classNames[i];
|
||||||
|
out += (name == 'ruler') ? getRuler() : getLink(name);
|
||||||
|
} else {
|
||||||
|
for (var j in classNames[i]) {
|
||||||
|
out += getHeading(j);
|
||||||
|
out += parseClassNames(classNames[i][j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
return out;
|
function getLink(name) {
|
||||||
}
|
return '<li><a href="' + name + '.html">' + name + '</a></li>';
|
||||||
function getLink(name) {
|
|
||||||
return '<li><a href="' + name + '.html">' + name + '</a></li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRuler() {
|
|
||||||
return '<li><hr /></li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHeading(title) {
|
|
||||||
return '<li><h3>' + title + '</h3></li>';
|
|
||||||
}
|
|
||||||
var first = true,
|
|
||||||
out = '<ul class="package-classes">';
|
|
||||||
for (var i in classLayout) {
|
|
||||||
out += '<li' + (first ? ' class="first">' : '>');
|
|
||||||
out += '<h2>' + i + '</h2>';
|
|
||||||
out += parseClassNames(classLayout[i]);
|
|
||||||
out += '</li>';
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
out += '</ul';
|
|
||||||
|
|
||||||
var classesIndex = publish.templates.menu.process(out);
|
|
||||||
IO.saveFile(publish.conf.packagesDir, 'packages.html', classesIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Make a symbol sorter by some attribute. */
|
|
||||||
function makeSortby(attribute) {
|
|
||||||
return function(a, b) {
|
|
||||||
if (a[attribute] != undefined && b[attribute] != undefined) {
|
|
||||||
a = a[attribute].toLowerCase();
|
|
||||||
b = b[attribute].toLowerCase();
|
|
||||||
if (a < b) return -1;
|
|
||||||
if (a > b) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Pull in the contents of an external file at the given path. */
|
function getRuler() {
|
||||||
function include(path) {
|
return '<li><hr /></li>';
|
||||||
var path = publish.conf.templateDir + path;
|
|
||||||
return IO.readFile(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Build output for displaying function parameters. */
|
|
||||||
function makeSignature(params) {
|
|
||||||
if (!params) return '()';
|
|
||||||
var postString = '';
|
|
||||||
var first = true;
|
|
||||||
params = params.filter(
|
|
||||||
function($) {
|
|
||||||
return $.name.indexOf('.') == -1; // don't show config params in signature
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
var signature = '';
|
function getHeading(title) {
|
||||||
var postSignature = '';
|
return '<li><h3>' + title + '</h3></li>';
|
||||||
for (var i = 0, l = params.length; i < l; i++) {
|
|
||||||
var param = params[i];
|
|
||||||
if (param.isOptional) {
|
|
||||||
signature += '[';
|
|
||||||
postSignature += ']';
|
|
||||||
}
|
}
|
||||||
if (i > 0)
|
var first = true,
|
||||||
signature += ', ';
|
out = '<ul class="package-classes">';
|
||||||
signature += param.name;
|
for (var i in classLayout) {
|
||||||
}
|
out += '<li' + (first ? ' class="first">' : '>');
|
||||||
return '(' + signature + postSignature + ')';
|
out += '<h2>' + i + '</h2>';
|
||||||
}
|
out += parseClassNames(classLayout[i]);
|
||||||
|
out += '</li>';
|
||||||
function processGroupTitle(str, symbol) {
|
first = false;
|
||||||
var groupTitle = str.match(/\{@grouptitle ([^}]+)\}/);
|
|
||||||
if (groupTitle) {
|
|
||||||
symbol.groupTitle = groupTitle[1];
|
|
||||||
str = str.replace(/\{@grouptitle ([^}]+)\}/, '');
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function processInlineTags(str, param) {
|
|
||||||
if (!param)
|
|
||||||
param = {};
|
|
||||||
// <code>..</code> -> <pre>..</pre>
|
|
||||||
str = str.replace(/<(\/)*(code)>/g, '<$1pre>');
|
|
||||||
|
|
||||||
// {@link ...} -> html links
|
|
||||||
str = str.replace(/\{@link ([^} ]+) ?\}/gi,
|
|
||||||
function(match, symbolName) {
|
|
||||||
return new Link().toSymbol(symbolName.replace(/[\^]/g, '-'));
|
|
||||||
}
|
}
|
||||||
);
|
out += '</ul';
|
||||||
// {@code ...} -> code blocks
|
|
||||||
str = str.replace(/\{@code[\s]([^}]+)\}/gi,
|
var classesIndex = publish.templates.menu.process(out);
|
||||||
function(match, code) {
|
IO.saveFile(publish.conf.packagesDir, 'packages.html', classesIndex);
|
||||||
return '<tt>' + code + '</tt>';
|
},
|
||||||
|
|
||||||
|
makeSortby: function(attribute) {
|
||||||
|
return function(a, b) {
|
||||||
|
if (a[attribute] != undefined && b[attribute] != undefined) {
|
||||||
|
a = a[attribute].toLowerCase();
|
||||||
|
b = b[attribute].toLowerCase();
|
||||||
|
if (a < b) return -1;
|
||||||
|
if (a > b) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
|
|
||||||
// {@true ...} -> true if.. false otherwise..
|
/** Pull in the contents of an external file at the given path. */
|
||||||
str = str.replace(/\{@true[\s]([^}]+)\}/gi,
|
include: function(path) {
|
||||||
function(match, text) {
|
var path = publish.conf.templateDir + path;
|
||||||
return '<tt>true</tt> ' + text + ', <tt>false</tt> otherwise';
|
return IO.readFile(path);
|
||||||
}
|
},
|
||||||
);
|
|
||||||
|
|
||||||
var lineBreak = java.lang.System.getProperty('line.separator');
|
|
||||||
|
|
||||||
// Convert any type of lineBreak to the one we're using now:
|
|
||||||
str = str.replace(/(\r\n|\n|\r)/g, function(match, lineBreak) {
|
|
||||||
return lineBreak;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Replace inline <code></code> with <tt></tt>
|
processInlineTags: function(str, param) {
|
||||||
str = str.replace(/<code>[ \t]*([^\n\r]*?)[ \t]*<\/code>/g, function(match, content) {
|
if (!param)
|
||||||
return '<tt>' + content + '</tt>';
|
param = {};
|
||||||
});
|
// <code>..</code> -> <pre>..</pre>
|
||||||
|
str = str.replace(/<(\/)*(code)>/g, '<$1pre>');
|
||||||
|
|
||||||
// Put code and pre tags on the same line as the content, as white-space: pre is set:
|
// <pre> -> <pre class="code">
|
||||||
str = str.replace(/(<(?:code|pre)>)\s*([\u0000-\uffff]*?)\s*(<\/(?:code|pre)>)/g, function(match, open, content, close) {
|
str = str.replace(/<pre>/g, '<pre class="code">');
|
||||||
// Filter out the first white space at the beginning of each line, since
|
|
||||||
// that stems from the space after the * in the comment and replace <code>
|
// {@link ...} -> html links
|
||||||
// with <pre>, to fix a IE problem where lighter.js does not receive
|
str = str.replace(/\{@link ([^} ]+) ?\}/gi,
|
||||||
// linebreaks from code tags weven when white-space: pre is set.
|
function(match, symbolName) {
|
||||||
return '<pre>' + content.replace(/(\r\n|\n|\r) /mg, function(match, lineBreak) {
|
return new Link().toSymbol(symbolName.replace(/[\^]/g, '-'));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// {@code ...} -> code blocks
|
||||||
|
str = str.replace(/\{@code[\s]([^}]+)\}/gi,
|
||||||
|
function(match, code) {
|
||||||
|
return '<tt>' + code + '</tt>';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// {@true ...} -> true if.. false otherwise..
|
||||||
|
str = str.replace(/\{@true[\s]([^}]+)\}/gi,
|
||||||
|
function(match, text) {
|
||||||
|
return '<tt>true</tt> ' + text + ', <tt>false</tt> otherwise';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var lineBreak = java.lang.System.getProperty('line.separator');
|
||||||
|
|
||||||
|
// Convert any type of lineBreak to the one we're using now:
|
||||||
|
str = str.replace(/(\r\n|\n|\r)/g, function(match, lineBreak) {
|
||||||
return lineBreak;
|
return lineBreak;
|
||||||
}) + '</pre>';
|
|
||||||
});
|
|
||||||
// Empty lines -> Paragraphs
|
|
||||||
if (!param.stripParagraphs) {
|
|
||||||
if (param.wrapInParagraphs === undefined || param.wrapInParagraphs)
|
|
||||||
str = '<p>' + str.trim() + '</p>';
|
|
||||||
str = str.trim().replace(/(\r\n|\n|\r)\s*(\r\n|\n|\r)/g, function(match, lineBreak) {
|
|
||||||
return '</p>' + lineBreak + '<p>';
|
|
||||||
});
|
});
|
||||||
// Automatically put </p><p> at the end of sentences with line breaks.
|
|
||||||
// Match following </p> and <p> tags and swallow them. This happens when
|
|
||||||
// the original content contains these.
|
|
||||||
str = str.trim().replace(/([.:?!;])\s*(\r\n|\n|\r)(\s*)(<\/p>|<p>|)/g, function(match, before, lineBreak, whiteSpace, after) {
|
|
||||||
// Include following whiteSpace as well, since for code blocks they are relevant (e.g. indentation on new line)
|
|
||||||
return before + '</p>' + lineBreak + whiteSpace + '<p>';
|
|
||||||
});
|
|
||||||
// Filter out <p> tags within and around <code> and <pre> blocks again
|
|
||||||
str = str.replace(/((?:<p>\s*|)<(?:code|pre)[^>]*>[\u0000-\uffff]*<\/(?:code|pre)>(?:\s*<\/p>|))/g, function(match, code) {
|
|
||||||
return stripTags(code, 'p');
|
|
||||||
});
|
|
||||||
// Filter out empty paragraphs
|
|
||||||
str = str.replace(/<p><\/p>/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function stripTags(str, tag) {
|
// Replace inline <code></code> with <tt></tt>
|
||||||
var tag = tag || '.*?'; // Default: all tags
|
str = str.replace(/<code>[ \t]*([^\n\r]*?)[ \t]*<\/code>/g, function(match, content) {
|
||||||
return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), '');
|
return '<tt>' + content + '</tt>';
|
||||||
}
|
});
|
||||||
|
|
||||||
function copyDirectory(sourceLocation, targetLocation) {
|
// Put code and pre tags on the same line as the content, as white-space: pre is set:
|
||||||
if (sourceLocation.isDirectory()) {
|
str = str.replace(/(<(?:code|pre)>)\s*([\u0000-\uffff]*?)\s*(<\/(?:code|pre)>)/g, function(match, open, content, close) {
|
||||||
if (!targetLocation.exists()) {
|
// Filter out the first white space at the beginning of each line, since
|
||||||
targetLocation.mkdir();
|
// that stems from the space after the * in the comment and replace <code>
|
||||||
|
// with <pre>, to fix a IE problem where lighter.js does not receive
|
||||||
|
// linebreaks from code tags weven when white-space: pre is set.
|
||||||
|
return '<pre>' + content.replace(/(\r\n|\n|\r) /mg, function(match, lineBreak) {
|
||||||
|
return lineBreak;
|
||||||
|
}) + '</pre>';
|
||||||
|
});
|
||||||
|
// Empty lines -> Paragraphs
|
||||||
|
if (!param.stripParagraphs) {
|
||||||
|
if (param.wrapInParagraphs === undefined || param.wrapInParagraphs)
|
||||||
|
str = '<p>' + str.trim() + '</p>';
|
||||||
|
str = str.trim().replace(/(\r\n|\n|\r)\s*(\r\n|\n|\r)/g, function(match, lineBreak) {
|
||||||
|
return '</p>' + lineBreak + '<p>';
|
||||||
|
});
|
||||||
|
// Automatically put </p><p> at the end of sentences with line breaks.
|
||||||
|
// Match following </p> and <p> tags and swallow them. This happens when
|
||||||
|
// the original content contains these.
|
||||||
|
str = str.trim().replace(/([.:?!;])\s*(\r\n|\n|\r)(\s*)(<\/p>|<p>|)/g, function(match, before, lineBreak, whiteSpace, after) {
|
||||||
|
// Include following whiteSpace as well, since for code blocks they are relevant (e.g. indentation on new line)
|
||||||
|
return before + '</p>' + lineBreak + whiteSpace + '<p>';
|
||||||
|
});
|
||||||
|
// Filter out <p> tags within and around <code> and <pre> blocks again
|
||||||
|
str = str.replace(/((?:<p>\s*|)<(?:code|pre)[^>]*>[\u0000-\uffff]*<\/(?:code|pre)>(?:\s*<\/p>|))/g, function(match, code) {
|
||||||
|
return Utils.stripTags(code, 'p');
|
||||||
|
});
|
||||||
|
// Filter out empty paragraphs
|
||||||
|
str = str.replace(/<p><\/p>/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
var children = sourceLocation.list();
|
return str;
|
||||||
for (var i = 0; i < children.length; i++) {
|
},
|
||||||
copyDirectory(new File(sourceLocation, children[i]),
|
|
||||||
new File(targetLocation, children[i]));
|
/** Build output for displaying function parameters. */
|
||||||
|
makeSignature: function(params) {
|
||||||
|
if (!params) return '()';
|
||||||
|
var postString = '';
|
||||||
|
var first = true;
|
||||||
|
params = params.filter(
|
||||||
|
function($) {
|
||||||
|
return $.name.indexOf('.') == -1; // don't show config params in signature
|
||||||
|
}
|
||||||
|
);
|
||||||
|
var signature = '';
|
||||||
|
var postSignature = '';
|
||||||
|
for (var i = 0, l = params.length; i < l; i++) {
|
||||||
|
var param = params[i];
|
||||||
|
if (param.isOptional) {
|
||||||
|
signature += '[';
|
||||||
|
postSignature += ']';
|
||||||
|
}
|
||||||
|
if (i > 0)
|
||||||
|
signature += ', ';
|
||||||
|
signature += param.name;
|
||||||
}
|
}
|
||||||
} else {
|
return '(' + signature + postSignature + ')';
|
||||||
// Copy the file with FileChannels:
|
|
||||||
targetLocation.createNewFile();
|
|
||||||
var src = new java.io.FileInputStream(sourceLocation).getChannel();
|
|
||||||
var dst = new java.io.FileOutputStream(targetLocation).getChannel();
|
|
||||||
var amount = dst.transferFrom(src, 0, src.size());
|
|
||||||
src.close();
|
|
||||||
dst.close();
|
|
||||||
}
|
}
|
||||||
}
|
};
|
|
@ -47,7 +47,7 @@
|
||||||
<if test="inheritedClassLinks.length">
|
<if test="inheritedClassLinks.length">
|
||||||
<p> Extends {+ inheritedClassLinks.join(', ') +}</p>
|
<p> Extends {+ inheritedClassLinks.join(', ') +}</p>
|
||||||
</if>
|
</if>
|
||||||
{+processInlineTags(data.classDesc)+}
|
{+Utils.processInlineTags(data.classDesc)+}
|
||||||
</div>
|
</div>
|
||||||
<!-- ============================== constructors ========================= -->
|
<!-- ============================== 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">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{!
|
{!
|
||||||
var constructorId = Helpers.getConstructorId(data);
|
var constructorId = Utils.getConstructorId(data);
|
||||||
var name = data.alias.replace(/(#|\^).+$/, '');
|
var name = data.alias.replace(/(#|\^).+$/, '');
|
||||||
data.desc = processGroupTitle(data.desc, data);
|
data.desc = Utils.processGroupTitle(data.desc, data);
|
||||||
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: ''}];
|
||||||
!}
|
!}
|
||||||
|
@ -10,22 +10,22 @@
|
||||||
</if>
|
</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>{+ makeSignature(data.params) +}</tt></a>
|
<a name="{+constructorId+}" href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ Utils.makeSignature(data.params) +}</tt></a>
|
||||||
</div>
|
</div>
|
||||||
<div id="{+constructorId+}-description" class="member-description hidden">
|
<div id="{+constructorId+}-description" class="member-description hidden">
|
||||||
<div class="member-header">
|
<div class="member-header">
|
||||||
<div class="member-title">
|
<div class="member-title">
|
||||||
<div class="member-link">
|
<div class="member-link">
|
||||||
<a href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ makeSignature(data.params) +}</tt></a>
|
<a href="#" onClick="return toggleMember('{+constructorId+}', false);"><tt><b>{+ name +}</b>{+ Utils.makeSignature(data.params) +}</tt></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+constructorId+}', false);"></div>
|
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+constructorId+}', false);"></div>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-text">{+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) +}
|
||||||
{+ Helpers.parseExamples(data) +}
|
{+ Utils.parseExamples(data) +}
|
||||||
{+ publish.templates.seeAlsos.process(data) +}
|
{+ publish.templates.seeAlsos.process(data) +}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{!
|
{!
|
||||||
data.desc = processGroupTitle(data.desc, data);
|
data.desc = Utils.processGroupTitle(data.desc, data);
|
||||||
var memberId = Helpers.getSymbolId(data);
|
var memberId = Utils.getSymbolId(data);
|
||||||
var functionTitle = '<b>' + data.name.replace(/\^\d+$/, '') + '</b>' + makeSignature(data.params);
|
var functionTitle = '<b>' + data.name.replace(/\^\d+$/, '') + '</b>' + Utils.makeSignature(data.params);
|
||||||
if (data.isStatic)
|
if (data.isStatic)
|
||||||
functionTitle = '<b>' + data.memberOf + '.</b>' + functionTitle;
|
functionTitle = '<b>' + data.memberOf + '.</b>' + functionTitle;
|
||||||
!}
|
!}
|
||||||
|
@ -23,11 +23,11 @@
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
{+ processInlineTags(data.desc) +}
|
{+ Utils.processInlineTags(data.desc) +}
|
||||||
{+ publish.templates.parameters.process(data) +}
|
{+ publish.templates.parameters.process(data) +}
|
||||||
{+ publish.templates.returns.process(data) +}
|
{+ publish.templates.returns.process(data) +}
|
||||||
{+ publish.templates.seeAlsos.process(data) +}
|
{+ publish.templates.seeAlsos.process(data) +}
|
||||||
{+ Helpers.parseExamples(data) +}
|
{+ Utils.parseExamples(data) +}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -35,10 +35,10 @@
|
||||||
</div>
|
</div>
|
||||||
<if test="operator.type">
|
<if test="operator.type">
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
{+ processInlineTags(operator.desc) +}
|
{+ Utils.processInlineTags(operator.desc) +}
|
||||||
{+ publish.templates.returns.process(operator) +}
|
{+ publish.templates.returns.process(operator) +}
|
||||||
{+ publish.templates.seeAlsos.process(operator) +}
|
{+ publish.templates.seeAlsos.process(operator) +}
|
||||||
{+ Helpers.parseExamples(operator) +}
|
{+ Utils.parseExamples(operator) +}
|
||||||
</div>
|
</div>
|
||||||
</if>
|
</if>
|
||||||
<if test="operatorCount == data.length - 1">
|
<if test="operatorCount == data.length - 1">
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<li>
|
<li>
|
||||||
<tt>{+ parameter.name +}: </tt>
|
<tt>{+ parameter.name +}: </tt>
|
||||||
{+ new Link().toSymbol(parameter.type) +}
|
{+ new Link().toSymbol(parameter.type) +}
|
||||||
<if test="parameter.desc">— {+processInlineTags(parameter.desc, {stripParagraphs: true})+}</if>
|
<if test="parameter.desc">— {+Utils.processInlineTags(parameter.desc, {stripParagraphs: true})+}</if>
|
||||||
<if test="parameter.isOptional">— optional</if><if test="parameter.defaultValue">, default: <tt>{+parameter.defaultValue+}</tt></if>
|
<if test="parameter.isOptional">— optional</if><if test="parameter.defaultValue">, default: <tt>{+parameter.defaultValue+}</tt></if>
|
||||||
</li>
|
</li>
|
||||||
</for>
|
</for>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{!
|
{!
|
||||||
data.desc = processGroupTitle(data.desc, data);
|
data.desc = Utils.processGroupTitle(data.desc, data);
|
||||||
|
|
||||||
var memberId = Helpers.getSymbolId(data);
|
var memberId = Utils.getSymbolId(data);
|
||||||
var title = '<b>' + data.name.replace(/\^\d+$/, '') + '</b>';
|
var title = '<b>' + data.name.replace(/\^\d+$/, '') + '</b>';
|
||||||
if (data.isStatic)
|
if (data.isStatic)
|
||||||
title = '<b>' + data.memberOf + '.</b>' + title;
|
title = '<b>' + data.memberOf + '.</b>' + title;
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
</div>
|
</div>
|
||||||
<if test="data.type">
|
<if test="data.type">
|
||||||
<div class="member-text">
|
<div class="member-text">
|
||||||
{+ processInlineTags(data.desc) +}
|
{+ Utils.processInlineTags(data.desc) +}
|
||||||
<if test="data.readOnly">
|
<if test="data.readOnly">
|
||||||
<p>Read only.</p>
|
<p>Read only.</p>
|
||||||
</if>
|
</if>
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{+ publish.templates.seeAlsos.process(data) +}
|
{+ publish.templates.seeAlsos.process(data) +}
|
||||||
{+ Helpers.parseExamples(data) +}
|
{+ Utils.parseExamples(data) +}
|
||||||
</div>
|
</div>
|
||||||
</if>
|
</if>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<ul><b>Returns:</b>
|
<ul><b>Returns:</b>
|
||||||
<for each="item" in="data.returns">
|
<for each="item" in="data.returns">
|
||||||
<li>
|
<li>
|
||||||
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}</tt><if test="item.desc"> — </if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}
|
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}</tt><if test="item.desc"> — </if></if>{+Utils.processInlineTags(item.desc, { stripParagraphs: true })+}
|
||||||
</li>
|
</li>
|
||||||
</for>
|
</for>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue