Permalink
Browse files

add dox --api

because im too lazy to make another executable
  • Loading branch information...
1 parent 87ef976 commit fd6496e861b272408a868e327aee27bd464f2e60 @tj committed Oct 1, 2012
Showing with 29 additions and 2 deletions.
  1. +5 −2 bin/dox
  2. +18 −0 lib/api.js
  3. +6 −0 lib/dox.js
View
@@ -6,13 +6,14 @@
var program = require('commander')
, util = require('util')
- , dox = require('../');
+ , dox = require('..');
// options
program
.version(dox.version)
.option('-r, --raw', 'output "raw" comments, leaving the markdown intact')
+ .option('-a, --api', 'output markdown readme documentation')
.option('-d, --debug', 'output parsed comments for debugging');
// examples
@@ -38,9 +39,11 @@ var buf = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){ buf += chunk; });
process.stdin.on('end', function(){
- var obj = dox.parseComments(buf, { raw: program.raw });
+ var obj = dox.parseComments(buf, { raw: program.raw || program.api });
if (program.debug) {
process.stdout.write(util.inspect(obj, false, Infinity, true) + '\n');
+ } else if (program.api) {
+ process.stdout.write(dox.api(obj));
} else {
process.stdout.write(JSON.stringify(obj, null, 2));
}
View
@@ -0,0 +1,18 @@
+
+module.exports = function(comments){
+ var buf = [];
+
+ comments.forEach(function(comment){
+ if (comment.private) return;
+ if (comment.ignore) return;
+ var ctx = comment.ctx;
+ var desc = comment.description;
+ if (!ctx.string.indexOf('module.exports')) return;
+ buf.push('## ' + ctx.string.replace('.prototype.', '#'));
+ buf.push('');
+ buf.push(desc.full.trim().replace(/^/gm, ' '));
+ buf.push('');
+ });
+
+ return buf.join('\n');
+};
View
@@ -11,6 +11,12 @@ var markdown = require('github-flavored-markdown').parse
exports.version = '0.3.1';
+/**
+ * Expose api.
+ */
+
+exports.api = require('./api');
+
/**
* Parse comments in the given string of `js`.
*

0 comments on commit fd6496e

Please sign in to comment.