From f57d4748266f590ce4e4fc1abaf24c1ec3d6cf4f Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Sat, 7 May 2011 22:23:53 +0100 Subject: [PATCH] Added ejs templates. --- jsdoc.js | 19 +++++++++++++++-- lib/Rhino-Require/README.md | 26 ++++++++++++++++++++--- node_modules/jsdoc/doclet.js | 23 +++++++++++++++++++- node_modules/jsdoc/parser.js | 10 ++++++--- test-rhino.js | 15 -------------- test.js | 8 ------- test/examples/only_comments.js | 2 -- test/jsdoc_parser.js | 13 ------------ test/jsdoc_parser_comments.js | 38 ---------------------------------- test/jsdoc_parser_function.js | 29 -------------------------- test/narcissus.js | 24 --------------------- 11 files changed, 69 insertions(+), 138 deletions(-) delete mode 100755 test-rhino.js delete mode 100644 test.js delete mode 100644 test/examples/only_comments.js delete mode 100644 test/jsdoc_parser.js delete mode 100644 test/jsdoc_parser_comments.js delete mode 100644 test/jsdoc_parser_function.js delete mode 100644 test/narcissus.js diff --git a/jsdoc.js b/jsdoc.js index 36d520dc..2261bce9 100644 --- a/jsdoc.js +++ b/jsdoc.js @@ -38,14 +38,29 @@ console.log('USAGE: node main.js yourfile.js'); process.exit(0); } + var srcFile = opts._[0]; var src = fs.readFileSync(srcFile, 'utf-8'); var parser = require('jsdoc/parser'); - var symbols = parser.parse(src); + var docs = parser.parse(src); - console.log( dumper.dump(symbols) ); +// docs = _.map(docs, function(doc) { +// if (!doc.jsdoc) { doc.jsdoc = {}; } +// doc.jsdoc.longname = doc.longname; +// return doc.jsdoc; +// }); + + if (opts.expel) { + console.log( dumper.dump(docs) ); + } + else { + var taffy = require('./templates/lib/taffy'); + var publisher = require('./templates/default'); + + console.log( publisher.publish( new taffy(docs) ) ); + } })(); \ No newline at end of file diff --git a/lib/Rhino-Require/README.md b/lib/Rhino-Require/README.md index 3443e153..c1d6023e 100644 --- a/lib/Rhino-Require/README.md +++ b/lib/Rhino-Require/README.md @@ -1,9 +1,29 @@ Rhino-Require ==== -This is require() for rhino. - A nodejs-like implementation of the commonjs `require` function, implemented to be compatible with the Mozilla Rhino JavaScript engine. -Written by Michael Mathews. Licensed as public domain. \ No newline at end of file +Usage +---- + +Assuming you have created a JavaScript commonjs module and saved it at +`./node_modules/twiddler/index.js` + + module.exports = { + twiddle: function(str) { + } + }; + +You can then load that module into your `./main.js` script using Rhino-Require. + + load('lib/rhino-require.js'); + + var twiddler = require('twiddler'); + twiddler.twiddle('foo'); + +License +---- + +Written by Michael Mathews. Licensed as public domain. + diff --git a/node_modules/jsdoc/doclet.js b/node_modules/jsdoc/doclet.js index 13a21fbb..bf5e7970 100644 --- a/node_modules/jsdoc/doclet.js +++ b/node_modules/jsdoc/doclet.js @@ -3,6 +3,7 @@ exports.Doclet = Doclet; function Doclet(jsdoc, meta) { + if (jsdoc !== '') { this.tags = this.parseTags(jsdoc); } @@ -10,6 +11,14 @@ this.tags = []; } + if (!this.hasOwnProperty('kind') && meta && meta.hasOwnProperty('kind')) { + this.kind = meta.kind; + } + + if (!this.hasOwnProperty('longname') && meta && meta.hasOwnProperty('longname')) { + this.longname = meta.longname; + } + plugin.manager.run('doclet', [this]); } @@ -17,7 +26,7 @@ // tags have [title, type, pname, text] commentSrc = fixDescription( trim(commentSrc) ); - this.src = commentSrc; + this.jsdoc = commentSrc; var tags = splitTags(commentSrc), tag; @@ -79,6 +88,18 @@ if ( /\{(.+?)\}/.test(tag.text) ) { tag.text = trim(RegExp.$1); } + + doc.type = tag.text; + } + }; + + dict['name'] = { + has: ['value'], + title: 'name', + onTag: function(tag, doc) { + tag.text = trim(tag.text); + + doc.name = tag.text; } }; diff --git a/node_modules/jsdoc/parser.js b/node_modules/jsdoc/parser.js index b6dc00a1..c62a4fd1 100644 --- a/node_modules/jsdoc/parser.js +++ b/node_modules/jsdoc/parser.js @@ -41,7 +41,7 @@ var handle = { JSDOC: function(jsdoc) { //console.log( '>>> jsdoc "'+jsdoc+'"' ); - symbols.push({longname: null, jsdoc: new Doclet(jsdoc)}); + symbols.push( new Doclet(jsdoc, {longname: ''}) ); }, VAR: function(node) { var child = null, @@ -54,7 +54,11 @@ } var namePath = path.join('') + (path.length?'~':'') + child.name; - symbols.push({longname: namePath, jsdoc: defined(child.jsdoc)? new Doclet(child.jsdoc) : new Doclet('')}); + symbols.push( + defined(child.jsdoc)? + new Doclet(child.jsdoc, {longname: namePath, kind: 'var'}) + : new Doclet('', {longname: namePath, kind: 'var'}) + ); //console.log( '>>> variable '+namePath+(defined(child.jsdoc)? ' "'+child.jsdoc+'"' : '') ); var children = walkable(child); if (children) { walk(children); } @@ -64,7 +68,7 @@ var namePath = path.join('') + (path.length?'~':'') + node.name, jsdoc = defined(node.jsdoc)? node.jsdoc : ''; - symbols.push({longname: namePath, jsdoc: new Doclet(jsdoc)}); + symbols.push( new Doclet(jsdoc, {longname: namePath, kind: 'function'}) ); //console.log( '>>> function '+namePath+(defined(node.jsdoc)? ' "'+node.jsdoc+'"' : '') ); path.push((path.length?'~':'')+node.name); walk(node.body.children); diff --git a/test-rhino.js b/test-rhino.js deleted file mode 100755 index 9c948f9f..00000000 --- a/test-rhino.js +++ /dev/null @@ -1,15 +0,0 @@ -load('lib/rhino-shim.js'); -load('lib/nodeunit.js'); - -var fs = require('fs'), - testFiles = fs.ls('./test/'), - testFile; - -while ( testFile = testFiles.shift() ) { - var testName = testFile.replace(/\.js$/, ''); - var test = {}; - - test[testName] = require(testName); - - nodeunit.run(test); -} \ No newline at end of file diff --git a/test.js b/test.js deleted file mode 100644 index df7a4ca7..00000000 --- a/test.js +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env node - -if (typeof load !== 'undefined') { - load('lib/rhino-shim.js'); -} - -var reporter = require('nodeunit').reporters['default']; -reporter.run(['./test']); \ No newline at end of file diff --git a/test/examples/only_comments.js b/test/examples/only_comments.js deleted file mode 100644 index 97b325ce..00000000 --- a/test/examples/only_comments.js +++ /dev/null @@ -1,2 +0,0 @@ -/**@overview nothing but comments 1*/ -/**@overview nothing but comments 2*/ \ No newline at end of file diff --git a/test/jsdoc_parser.js b/test/jsdoc_parser.js deleted file mode 100644 index 416b1a30..00000000 --- a/test/jsdoc_parser.js +++ /dev/null @@ -1,13 +0,0 @@ -var parser = require('jsdoc/parser'); - -exports['The jsdoc parser should exist.'] = function(t) { - t.expect(1); - t.equal( typeof parser, 'object' ); - t.done(); -}; - -exports['The parser should have a parse function.'] = function(t) { - t.expect(1); - t.equal( typeof parser.parse, 'function' ); - t.done(); -}; diff --git a/test/jsdoc_parser_comments.js b/test/jsdoc_parser_comments.js deleted file mode 100644 index 7cd7f908..00000000 --- a/test/jsdoc_parser_comments.js +++ /dev/null @@ -1,38 +0,0 @@ -var parser = require('jsdoc/parser'); -var dumper = require('jsdoc/util/dumper'); - -exports['Parse a source containing only a jsdoc comment.'] = function(t) { - t.expect(1); - var docs = parser.parse('/**@doc*/'); - t.equal( docs.length, 1, 'should result in docs that contain the comment' ); - t.done(); -}; - -exports['Parse a source ending with a jsdoc comment.'] = function(t) { - t.expect(1); - var docs = parser.parse(';/**@doc*/'); - t.equal( docs.length, 1, 'should result in docs that contain the comment' ); - t.done(); -}; - -exports['Parse a source with a jsdoc comment preceding a jsdoc comment.'] = function(t) { - t.expect(1); - var docs = parser.parse('/**@doc1*/ /**@doc2*/ var x;'); - t.equal( docs.length, 2, 'should result in docs containing both the comments' ); - t.done(); -}; - -exports['Parse a source with only single line comments.'] = function(t) { - t.expect(1); - var docs = parser.parse('// foo'); - t.equal( docs.length, 0, 'should result in docs that are empty' ); - - t.done(); -}; - -exports['Parse a source with only single non-jsdoc multi-line comments.'] = function(t) { - t.expect(1); - var docs = parser.parse('/*foo*/'); - t.equal( docs.length, 0, 'should result in docs that are empty' ); - t.done(); -}; diff --git a/test/jsdoc_parser_function.js b/test/jsdoc_parser_function.js deleted file mode 100644 index 4d33c18b..00000000 --- a/test/jsdoc_parser_function.js +++ /dev/null @@ -1,29 +0,0 @@ -var parser = require('jsdoc/parser'); - -exports['An undocumented named function.'] = function(t) { - t.expect(3); - var docs = parser.parse('function foo() {}'); - t.equal( docs.length, 1, 'should result in 1 doc' ); - t.equal( typeof docs[0].longname, 'string', 'should have a longname set' ); - t.equal( docs[0].longname, 'foo', 'should have a longname equal to the function name' ); - t.done(); -}; - -exports['A documented named function.'] = function(t) { - t.expect(4); - var docs = parser.parse('/**@desc a function*/ function foo() {}'); - t.equal( docs.length, 1, 'should result in 1 doc' ); - t.equal( docs[0].longname, 'foo', 'should have a longname equal to the function name' ); - t.equal( typeof docs[0].jsdoc, 'object', 'should have a jsdoc set' ); - t.equal( docs[0].jsdoc.src, '@desc a function', 'should have a jsdoc equal to the preceding doc comment' ); - t.done(); -}; - -exports['A nested documented named function.'] = function(t) { - t.expect(2); - var docs = parser.parse('function foo() { /**@desc a function*/ function bar() {} }'); - t.equal( docs.length, 2, 'should result in 2 docs' ); - t.equal( docs[1].longname, 'foo~bar', 'the inner function should have a longname equal to ~' ); - t.done(); -}; - diff --git a/test/narcissus.js b/test/narcissus.js deleted file mode 100644 index aa062d9d..00000000 --- a/test/narcissus.js +++ /dev/null @@ -1,24 +0,0 @@ -var narcissus = require('narcissus'); - -exports['Narcissus should exist.'] = function(t) { - t.expect(2); - t.equal( typeof narcissus, 'object' ); - t.equal( typeof narcissus.Narcissus, 'object' ); - t.done(); -}; - -exports['Narcissus parse should be a function.'] = function(t) { - t.expect(2); - t.equal( typeof narcissus.Narcissus.parser, 'object' ); - t.equal( typeof narcissus.Narcissus.parser.parse, 'function' ); - t.done(); -}; - -exports['Narcissus parse should generate an AST from source.'] = function(t) { - t.expect(1); - var src = 'var foo = 1;', - ast = narcissus.Narcissus.parser.parse(src, 'filename', 1); - - t.equal( typeof ast, 'object' ); - t.done(); -}; \ No newline at end of file