From 13526499cfc52bfdccc32132d1ee9eb2bc40f9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wrzeszcz?= Date: Thu, 15 Dec 2011 10:02:05 +0100 Subject: [PATCH] Tutorials base structure. --- jsdoc.js | 12 ++++- rhino_modules/jsdoc/opts/parser.js | 1 + rhino_modules/jsdoc/tutorial.js | 63 ++++++++++++++++++++++++ rhino_modules/jsdoc/tutorial/resolver.js | 37 ++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 rhino_modules/jsdoc/tutorial.js create mode 100644 rhino_modules/jsdoc/tutorial/resolver.js diff --git a/jsdoc.js b/jsdoc.js index 5f8447a0..42656b37 100644 --- a/jsdoc.js +++ b/jsdoc.js @@ -142,7 +142,8 @@ function main() { opts: { parser: require('jsdoc/opts/parser'), } - }; + }, + resolver; env.opts = jsdoc.opts.parser.parse(env.args); @@ -240,6 +241,12 @@ function main() { exit(0); } + resolver = require('jsdoc/tutorial/resolver'); + var Tutorial = require('jsdoc/tutorial').Tutorial; + + // tutorials handling + //TODO + env.opts.template = env.opts.template || 'templates/default'; // should define a global "publish" function @@ -248,7 +255,8 @@ function main() { if (typeof publish === 'function') { publish( new (require('typicaljoe/taffy'))(docs), - env.opts + env.opts, + resolver.root ); } else { // TODO throw no publish warning? diff --git a/rhino_modules/jsdoc/opts/parser.js b/rhino_modules/jsdoc/opts/parser.js index 43cb6e3b..4c015b8e 100644 --- a/rhino_modules/jsdoc/opts/parser.js +++ b/rhino_modules/jsdoc/opts/parser.js @@ -25,6 +25,7 @@ argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when argParser.addOption('h', 'help', false, 'Print this message and quit.'); argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.'); argParser.addOption('q', 'query', true, 'Provide a querystring to define custom variable names/values to add to the options hash.'); +argParser.addOption('u', 'tutorials', false, 'Directory in which JSDoc should search for tutorials.'); // TODO [-R, recurseonly] = a number representing the depth to recurse diff --git a/rhino_modules/jsdoc/tutorial.js b/rhino_modules/jsdoc/tutorial.js new file mode 100644 index 00000000..f82ae93a --- /dev/null +++ b/rhino_modules/jsdoc/tutorial.js @@ -0,0 +1,63 @@ +/** + @overview + @author Rafał Wrzeszcz + @license Apache License 2.0 - See file 'LICENSE.md' in this project. + */ + +/** + @module jsdoc/tutorial + */ + +/** + @class + @classdesc Represents a single JSDoc tutorial. + @param {string} name - Tutorial name. + @param {string} content - Text content. + */ +exports.Tutorial = function(name, content) { + this.title = this.name = name; + this.content = content; + + // default values + this.parent = null; + this.children = []; + this.type = exports.Tutorial.HTML; +}; + +/** Tutorial source types. + @enum {string} + */ +exports.Tutorial.TYPES = { + HTML: "html", + MD: "markdown" +}; + +/** Moves children from current parent to different one. + @param {Tutorial} parent + */ +exports.Tutorial.prototype.setParent = function(parent) { + // removes node from old parent + if (this.parent) { + this.parent.removeChild(this); + } + + this.parent = parent; + this.parent.addChild(this); +}; + +/** Removes children from current node. + @param {Tutorial} child + */ +exports.Tutorial.prototype.removeChild = function(child) { + var index = this.children.indexOf(child); + if (index != -1) { + this.children.splice(index, 1); + } +}; + +/** Adds new children to current node. + @param {Tutorial} child + */ +exports.Tutorial.prototype.addChild = function(child) { + this.children.push(child); +}; diff --git a/rhino_modules/jsdoc/tutorial/resolver.js b/rhino_modules/jsdoc/tutorial/resolver.js new file mode 100644 index 00000000..807873fe --- /dev/null +++ b/rhino_modules/jsdoc/tutorial/resolver.js @@ -0,0 +1,37 @@ +/** + @overview + @author Rafał Wrzeszcz + @license Apache License 2.0 - See file 'LICENSE.md' in this project. + */ + +/** + @module jsdoc/tutorial/resolver + */ + +var tutorial = require('jsdoc/tutorial'); + +var tutorials = {}, + length = 0; + +/** Adds new tutorial. + @param {tutorial.Tutorial} tutorial - New tutorial. + */ +exports.addTutorial = function(tutorial) { + tutorials[tutorial.name] = tutorial; + ++length; + + // default temporary parent + tutorial.setParent(exports.root); +}; + +/** Root tutorial. + @type tutorial.Tutorial + */ +exports.root = new tutorial.Tutorial('', ''); + +/** Resolves hierarchical structure. + @param {object} map - Contents map. + */ +exports.resolve = function(map) { + //TODO +};