mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
jsdoc: clean up templates a bit and improve rendering of @example tags.
This commit is contained in:
parent
e3069eaaed
commit
8637bc4203
9 changed files with 67 additions and 49 deletions
|
@ -56,6 +56,25 @@ var Helpers = {
|
|||
|
||||
isaClass: function(symbol) {
|
||||
return symbol.is('CONSTRUCTOR') || symbol.isNamespace
|
||||
},
|
||||
|
||||
parseExamples: function(symbol) {
|
||||
var out = [],
|
||||
examples = symbol.example;
|
||||
for (var i = 0, l = examples.length; i < l; i++) {
|
||||
var example = examples[i],
|
||||
lines = example.toString().split('\n'),
|
||||
description = [];
|
||||
// The description is the first commented lines:
|
||||
while (/^[\/]{2}/.test(lines[0])) {
|
||||
description.push(lines.shift().replace('// ', ''));
|
||||
}
|
||||
out.push(publish.templates.example.process({
|
||||
description: description.join(' ').trim(),
|
||||
code: lines.join('\n').trim()
|
||||
}));
|
||||
}
|
||||
return out.join('\n');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -77,7 +96,9 @@ function publish(symbolSet) {
|
|||
property: 'property.tmpl',
|
||||
parameters: 'parameters.tmpl',
|
||||
operators: 'operators.tmpl',
|
||||
examples: 'examples.tmpl',
|
||||
returns: 'returns.tmpl',
|
||||
seeAlsos: 'see-alsos.tmpl',
|
||||
example: 'example.tmpl',
|
||||
constructor: 'constructor.tmpl',
|
||||
html: 'html.tmpl',
|
||||
allClasses: 'allClasses.tmpl',
|
||||
|
|
|
@ -118,3 +118,8 @@ ul.package-classes {
|
|||
.package-classes li h2 {
|
||||
margin-left: -10px;
|
||||
}
|
||||
|
||||
.member-text .CodeMirror {
|
||||
margin-bottom: 16px;
|
||||
margin-top: 8px;
|
||||
}
|
|
@ -23,23 +23,11 @@
|
|||
<div class="clear"></div>
|
||||
</div>
|
||||
<div class="member-text">{+processInlineTags(data.desc)+}
|
||||
<if test="data.example.length">
|
||||
<for each="example" in="data.example">
|
||||
<pre>{+example+}</pre>
|
||||
</for>
|
||||
</if>
|
||||
{+ publish.templates.parameters.process(data) +}
|
||||
<if test="data.returns.length">
|
||||
<ul><b>Returns:</b>
|
||||
<li>
|
||||
<for each="item" in="data.returns">
|
||||
<li>
|
||||
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}<if test="item.desc"> — </if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
|
||||
</li>
|
||||
</for>
|
||||
</li>
|
||||
</ul>
|
||||
</if>
|
||||
{+ publish.templates.returns.process(data) +}
|
||||
{+ Helpers.parseExamples(data) +}
|
||||
{+ publish.templates.seeAlsos.process(data) +}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,2 @@
|
|||
<b>Example</b> <if test="data.description.length">{+ '— ' + data.description +}</if>
|
||||
<pre class="code">{+data.code+}</pre>
|
|
@ -24,24 +24,10 @@
|
|||
</div>
|
||||
<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">
|
||||
<li>
|
||||
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +}<if test="item.desc"> — </if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
|
||||
</li>
|
||||
</for>
|
||||
</ul>
|
||||
</if>
|
||||
<if test="data.see.length">
|
||||
<p><b>See also:</b>
|
||||
<for each="item" in="data.see">
|
||||
<tt>{+ new Link().toSymbol(item) +}</tt>
|
||||
</for>
|
||||
</p>
|
||||
</if>
|
||||
{+ publish.templates.returns.process(data) +}
|
||||
{+ publish.templates.seeAlsos.process(data) +}
|
||||
{+ Helpers.parseExamples(data) +}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -35,15 +35,11 @@
|
|||
</div>
|
||||
<if test="operator.type">
|
||||
<div class="member-text">
|
||||
{+processInlineTags(operator.desc)+}
|
||||
{+ publish.templates.examples.process(operator) +}
|
||||
<ul><b>Returns:</b>
|
||||
<for each="item" in="operator.returns">
|
||||
<li>
|
||||
<tt><if test="defined(item.type)">{+ new Link().toSymbol(item.type) +} — </if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
|
||||
</li>
|
||||
</for>
|
||||
</ul></div>
|
||||
{+ processInlineTags(operator.desc) +}
|
||||
{+ publish.templates.returns.process(operator) +}
|
||||
{+ publish.templates.seeAlsos.process(operator) +}
|
||||
{+ Helpers.parseExamples(operator) +}
|
||||
</div>
|
||||
</if>
|
||||
<if test="operatorCount == data.length - 1">
|
||||
</div>
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
<div class="clear"></div>
|
||||
</div>
|
||||
<if test="data.type">
|
||||
<div class="member-text">
|
||||
{+ processInlineTags(data.desc) +}
|
||||
<if test="data.readOnly"><p>Read only.</p></if>
|
||||
{+ publish.templates.examples.process(data) +}
|
||||
<div class="member-text">
|
||||
{+ processInlineTags(data.desc) +}
|
||||
<if test="data.readOnly">
|
||||
<p>Read only.</p>
|
||||
</if>
|
||||
<if test="data.defaultValue">
|
||||
<ul><b>Default:</b>
|
||||
<li>
|
||||
|
@ -38,9 +39,12 @@
|
|||
</if>
|
||||
<ul><b>Type:</b>
|
||||
<li>
|
||||
<tt>{+new Link().toSymbol(data.type)+}</tt>
|
||||
<tt>{+new Link().toSymbol(data.type)+}</tt>
|
||||
</li>
|
||||
</ul></div>
|
||||
</ul>
|
||||
{+ publish.templates.seeAlsos.process(data) +}
|
||||
{+ Helpers.parseExamples(data) +}
|
||||
</div>
|
||||
</if>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,9 @@
|
|||
<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"> — </if></if>{+processInlineTags(item.desc, { stripParagraphs: true })+}</tt>
|
||||
</li>
|
||||
</for>
|
||||
</ul>
|
||||
</if>
|
|
@ -0,0 +1,7 @@
|
|||
<if test="data.see.length">
|
||||
<p><b>See also:</b>
|
||||
<for each="item" in="data.see">
|
||||
<tt>{+ new Link().toSymbol(item) +}</tt>
|
||||
</for>
|
||||
</p>
|
||||
</if>
|
Loading…
Reference in a new issue