More docs rendering work.

This commit is contained in:
Jonathan Puckey 2011-05-27 17:59:31 +02:00
parent f9d9847320
commit 41925ea990
5 changed files with 64 additions and 12 deletions

View file

@ -59,7 +59,7 @@
<if test="inheritedClassLinks.length">
<p> Extends {+ inheritedClassLinks.join(', ') +}</p>
</if>
<p>{+processInlineTags(data.classDesc)+}</p>
{+processInlineTags(data.classDesc)+}
</div>
<!-- ============================== constructors ========================= -->
<if test="!/(Event|Style)/.test(data.alias)">
@ -78,7 +78,7 @@
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+data.classId+}', false);"></div>
<div class="clear"></div>
</div>
<div class="member-text"><p>{+processInlineTags(data.desc)+}</p>
<div class="member-text">{+processInlineTags(data.desc)+}
<if test="data.example.length">
<for each="example" in="data.example">
<pre>{+example+}</pre>
@ -89,7 +89,7 @@
<ul><b>Returns:</b>
<li>
<for each="item" in="data.returns">
<dd>{+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+}{+processInlineTags(item.desc)+}</dd>
<dd>{+((item.type)?"<span class=\"light fixedFont\">{"+(new Link().toSymbol(item.type))+"}</span> " : "")+}{+processInlineTags(item.desc, { stripParagraphs: true })+}</dd>
</for>
</li>
</ul>

View file

@ -22,14 +22,14 @@
<div class="member-close"><input type="button" value="Close" onClick="toggleMember('{+ memberId +}', false);"></div>
<div class="clear"></div>
</div>
<div class="member-text"><p>{+processInlineTags(data.desc)+}</p>
<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) +}
<if test="data.returns.length">
<ul><b>Returns:</b>
<for each="item" in="data.returns">
<li>
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}<if test="item.desc">&nbsp;&mdash;&nbsp;</if></if>{+processInlineTags(item.desc)+}</tt>
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}<if test="item.desc">&nbsp;&mdash;&nbsp;</if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
</li>
</for>
</ul>

View file

@ -34,12 +34,12 @@
<div class="clear"></div>
</div>
<if test="operator.type">
<div class="member-text"><p>{+processInlineTags(operator.desc)+}</p>
<div class="member-text">{+processInlineTags(operator.desc)+}
{+ new JSDOC.JsPlate(publish.conf.templatesDir+"examples.tmpl").process(operator) +}
<ul><b>Returns:</b>
<for each="item" in="operator.returns">
<li>
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}&nbsp;&mdash;&nbsp;</if>{+processInlineTags(item.desc)+}</tt>
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}&nbsp;&mdash;&nbsp;</if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
</li>
</for>
</ul></div>

View file

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

View file

@ -1,5 +1,3 @@
var templates;
var Operator = new function() {
var operators = {
add: '+', subtract: '-', multiply: '*', divide: '/', equals: '==',
@ -51,6 +49,7 @@ var Helpers = {
}
};
var templates;
/** Called automatically by JsDoc Toolkit. */
function publish(symbolSet) {
publish.conf = { // trailing slash expected for dirs
@ -276,7 +275,9 @@ function processGroupTitle(str, symbol) {
return str;
}
function processInlineTags(str) {
function processInlineTags(str, param) {
if (!param)
param = {};
// <code>..</code> -> <pre>..</pre>
str = str.replace(/<(\/)*(code)>/g, '<$1pre>');
@ -292,9 +293,59 @@ function processInlineTags(str) {
return '<tt>' + code + '</tt>';
}
);
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>
str = str.replace(/<code>[ \t]*([^\n\r]*?)[ \t]*<\/code>/g, function(match, content) {
return '<tt>' + content + '</tt>';
});
// Put code and pre tags on the same line as the content, as white-space: pre is set:
str = str.replace(/(<(?:code|pre)>)\s*([\u0000-\uffff]*?)\s*(<\/(?:code|pre)>)/g, function(match, open, content, close) {
// 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>
// 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 stripTags(code, 'p');
});
// Filter out empty paragraphs
str = str.replace(/<p><\/p>/g, '');
}
return str;
}
function stripTags(str, tag) {
var tag = tag || '.*?'; // Default: all tags
return str.replace(new RegExp('<' + tag + '>|</' + tag + '>', 'g'), '');
}
function copyStatic(dir) {
var dir = publish.conf.templatesDir + 'resources/';