mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Tutorials support in template.
This commit is contained in:
parent
f6216e6d28
commit
ac02928d3d
@ -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.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;
|
||||
};
|
||||
|
||||
@ -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);
|
||||
@ -358,8 +359,8 @@
|
||||
}
|
||||
|
||||
if (globals.length) generate('Global', [{kind: 'globalobj'}], 'global.html');
|
||||
|
||||
|
||||
|
||||
|
||||
function generate(title, docs, filename) {
|
||||
var data = {
|
||||
title: title,
|
||||
@ -381,9 +382,39 @@
|
||||
|
||||
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) {
|
||||
|
||||
53
templates/default/tmpl/tutorial.tmpl
Normal file
53
templates/default/tmpl/tutorial.tmpl
Normal 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>
|
||||
Loading…
x
Reference in New Issue
Block a user