Tutorials support in template.

This commit is contained in:
Rafał Wrzeszcz 2011-12-15 13:21:52 +01:00
parent f6216e6d28
commit ac02928d3d
3 changed files with 101 additions and 7 deletions

View File

@ -131,7 +131,17 @@ exports.toTutorial = toTutorial = function(tutorial, content) {
content = content || node.title;
return '<a href="tutorial-'+strToFilename(node.name)+exports.fileExtension+'">'+content+'</a>';
return '<a href="'+exports.tutorialToUrl(tutorial)+'">'+content+'</a>';
}
exports.longnameToUrl = linkMap.longnameToUrl;
exports.tutorialToUrl = function(tutorial) {
var node = tutorials.getByName(tutorial);
// no such tutorial
if (!node) {
throw new Error('No such tutorial: '+tutorial);
}
return 'tutorial-'+strToFilename(node.name)+exports.fileExtension;
};

View File

@ -17,7 +17,8 @@
*/
publish = function(data, opts, tutorials) {
var out = '',
containerTemplate = template.render(fs.readFileSync(__dirname + '/templates/default/tmpl/container.tmpl'));
containerTemplate = template.render(fs.readFileSync(__dirname + '/templates/default/tmpl/container.tmpl')),
tutorialTemplate = template.render(fs.readFileSync(__dirname + '/templates/default/tmpl/tutorial.tmpl'));
// set up tutorials for helper
helper.setTutorials(tutorials);
@ -382,8 +383,38 @@
fs.writeFileSync(path, html)
}
function generateTutorial(title, tutorial, filename) {
var data = {
title: title,
header: tutorial.title,
content: tutorial.parse(),
children: tutorial.children,
nav: nav,
// helpers
render: render,
find: find,
linkto: linkto,
tutoriallink: tutoriallink,
htmlsafe: htmlsafe
};
var path = outdir + '/' + filename,
html = tutorialTemplate.call(data, data);
// yes, you can use {@link} in tutorials too!
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
fs.writeFileSync(path, html)
}
// tutorials can have only one parent so there is no risk for loops
//TODO: generate tutorials from root.children up
function saveChildren(node) {
node.children.forEach(function(child) {
generateTutorial('Tutorial: '+child.title, child, helper.tutorialToUrl(child.name));
});
}
saveChildren(tutorials);
}
function hashToLink(doclet, hash) {

View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: <?js= title ?></title>
<script src="http://shjs.sourceforge.net/sh_main.min.js"> </script>
<script src="http://shjs.sourceforge.net/lang/sh_javascript.min.js"> </script>
<link type="text/css" rel="stylesheet" href="styles/node-dark.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title"><?js= title ?></h1>
<section>
<header>
<?js if (children.length > 0) { ?>
<ul><?js
children.forEach(function(t) {
print('<li>'+tutoriallink(t.name)+'</li>');
});
?></ul>
<?js } ?>
<h2><?js= header ?></h2>
</header>
<article>
<?js= content ?>
</article>
</section>
</div>
<nav>
<?js= nav ?>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/micmath/jsdoc">JSDoc 3</a> on <?js= (new Date()) ?>
</footer>
<script> sh_highlightDocument(); </script>
</body>
</html>