Added ejs templates.

This commit is contained in:
Michael Mathews 2011-05-07 22:23:53 +01:00
parent 47b513424c
commit f57d474826
11 changed files with 69 additions and 138 deletions

View File

@ -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) ) );
}
})();

View File

@ -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.
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.

23
node_modules/jsdoc/doclet.js generated vendored
View File

@ -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;
}
};

10
node_modules/jsdoc/parser.js generated vendored
View File

@ -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);

View File

@ -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);
}

View File

@ -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']);

View File

@ -1,2 +0,0 @@
/**@overview nothing but comments 1*/
/**@overview nothing but comments 2*/

View File

@ -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();
};

View File

@ -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();
};

View File

@ -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 <the outer function name>~<the inner function name>' );
t.done();
};

View File

@ -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();
};