From 6580e17629460b1b497bdfe25e8410ad565ebe04 Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Tue, 29 May 2012 16:27:49 +0100 Subject: [PATCH] Added support for @example in haruki. Added Readme with informations about haruki. --- templates/haruki/README.md | 26 ++++++++++++++++++++++++++ templates/haruki/publish.js | 31 +++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 templates/haruki/README.md diff --git a/templates/haruki/README.md b/templates/haruki/README.md new file mode 100644 index 00000000..4a8e5cf1 --- /dev/null +++ b/templates/haruki/README.md @@ -0,0 +1,26 @@ +OVERVIEW +======== + +JSDoc 3 Haruki is an experimental template optimised for use with publishing processes that consume either JSON or XML. Whereas the default JSDoc template outputs an HTML representation of your docs, Haruki will output a JSON, or optionally an XML, representation. + +Currently Haruki only supports a subset of the tags supported by the default template. Those are: + + * @name + * @desc + * @type + * @namespace + * @function (or @method) + * @var (or @member) + * @class + * @event + * @param + * @returns + * @throws + * @example + * @access (like @private or @public) + + +USAGE +===== + + ./jsdoc myscript.js -t templates/haruki -d console -q format=xml \ No newline at end of file diff --git a/templates/haruki/publish.js b/templates/haruki/publish.js index 694ce6a4..765b70d9 100644 --- a/templates/haruki/publish.js +++ b/templates/haruki/publish.js @@ -1,8 +1,11 @@ /** @overview Builds a tree-like JSON string from the doclet data. @version 0.0.1 + @example + ./jsdoc scratch/jsdoc_test.js -t templates/haruki -d console -q format=xml */ +//var dumper = require('jsdoc/util/dumper'); (function() { /** @@ -81,7 +84,8 @@ 'access': element.access || '', 'virtual': !!element.virtual, 'description': element.description || '', - 'parameters': [ ] + 'parameters': [ ], + 'examples': [] }; if (element.returns) { @@ -91,6 +95,12 @@ }; } + if (element.examples) { + for (var i = 0, len = element.examples.length; i < len; i++) { + parentNode.functions[element.name].examples.push(element.examples[i]); + } + } + if (element.params) { for (var i = 0, len = element.params.length; i < len; i++) { thisFunction.parameters.push({ @@ -127,8 +137,8 @@ 'access': element.access || '', 'virtual': !!element.virtual, 'description': element.description || '', - 'parameters': [ - ] + 'parameters': [], + 'examples': [] }; if (element.returns) { @@ -138,6 +148,12 @@ }; } + if (element.examples) { + for (var i = 0, len = element.examples.length; i < len; i++) { + thisEvent.examples.push(element.examples[i]); + } + } + if (element.params) { for (var i = 0, len = element.params.length; i < len; i++) { thisEvent.parameters.push({ @@ -167,10 +183,17 @@ 'name': element.name, 'description': element.description || '', 'parameters': [ - ] + ], + 'examples': [] } }; + if (element.examples) { + for (var i = 0, len = element.examples.length; i < len; i++) { + thisClass.constructor.examples.push(element.examples[i]); + } + } + if (element.params) { for (var i = 0, len = element.params.length; i < len; i++) { thisClass.constructor.parameters.push({