From ac02928d3de1269cd61fbe59f85e18eaa78beeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Thu, 15 Dec 2011 13:21:52 +0100 Subject: [PATCH] Tutorials support in template. --- rhino_modules/jsdoc/util/templateHelper.js | 14 +++++- templates/default/publish.js | 41 +++++++++++++++-- templates/default/tmpl/tutorial.tmpl | 53 ++++++++++++++++++++++ 3 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 templates/default/tmpl/tutorial.tmpl diff --git a/rhino_modules/jsdoc/util/templateHelper.js b/rhino_modules/jsdoc/util/templateHelper.js index 4d3710a2..37c0579d 100644 --- a/rhino_modules/jsdoc/util/templateHelper.js +++ b/rhino_modules/jsdoc/util/templateHelper.js @@ -131,7 +131,17 @@ exports.toTutorial = toTutorial = function(tutorial, content) { content = content || node.title; - return ''+content+''; + return ''+content+''; } -exports.longnameToUrl = linkMap.longnameToUrl; \ No newline at end of file +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; +}; diff --git a/templates/default/publish.js b/templates/default/publish.js index 1916f0e1..013b6c14 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -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 foo + + 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) { diff --git a/templates/default/tmpl/tutorial.tmpl b/templates/default/tmpl/tutorial.tmpl new file mode 100644 index 00000000..b0e1354b --- /dev/null +++ b/templates/default/tmpl/tutorial.tmpl @@ -0,0 +1,53 @@ + + + + + JSDoc: <?js= title ?> + + + + + + + + + + +
+ +

+ +
+ +
+ 0) { ?> +
    '+tutoriallink(t.name)+''); + }); + ?>
+ + +

+
+ +
+ +
+ +
+
+ + + +
+ + + + + + \ No newline at end of file