Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit e475572906c2ce4ed9d1d0e4ced3278d946cc2f1 0 parents
Morten Siebuhr msiebuhr authored
Showing with 132 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +69 −0 onedox.js
  3. +16 −0 package.json
  4. +45 −0 templates/index.html
2  .gitignore
@@ -0,0 +1,2 @@
+doc/
+node_modules/
69 onedox.js
@@ -0,0 +1,69 @@
+#!/usr/bin/env node
+/*
+ * Generate some documentation from DOX + stupid templating.
+ */
+
+// Make `require()` work on HTML too!
+require('jinjs').registerExtension(".html");
+
+var dox = require('dox'),
+ fs = require('fs'),
+ optimist = require('optimist'),
+ path = require('path'),
+ template = require('./templates/index.html');
+
+var argv = optimist
+ .usage("$0 --out <outdir> file1.js ...")
+ .describe("out", "Dir to write output in")
+ .demand(1)
+ .demand("out")
+ .argv;
+
+/*
+ * Read files and DOX them.
+ */
+var files = [],
+ linkList = {};
+
+argv._.forEach(function (file) {
+ try {
+ var docs = dox.parseComments(fs.readFileSync(file, 'utf-8'));
+ } catch (e) {
+ console.error("✗ Couldn't parse", file);
+ return;
+ }
+
+ var outFile = file.replace(/\.js$/, '').replace(/\//g, '_') + '.html';
+ linkList[file] = outFile;
+ files.push({
+ source: file,
+ dox: docs,
+ outFile: path.join(argv.out, outFile)
+ });
+});
+
+/*
+ * Run each file through the template and write it out.
+ */
+files.forEach(function (file) {
+ fs.writeFileSync(file.outFile, template.render({
+ docs: file.dox,
+ menu: linkList,
+ title: file.source
+ }));
+ console.log("✓ Wrote", file.outFile);
+});
+
+/*
+ * No index.html created?
+ */
+if (!('index.js' in linkList)) {
+ var index = path.join(argv.out, "index.html");
+ fs.writeFileSync(index, template.render({
+ docs: [],
+ menu: linkList,
+ title: "Documentation index"
+ }));
+ console.log("✓ Wrote", index, "(no index.js to use as entry point)");
+}
+
16 package.json
@@ -0,0 +1,16 @@
+{
+ "author": "Morten Siebuhr",
+ "name": "onedox",
+ "description": "Annotated source code documenter",
+ "version": "0.0.0",
+ "bin": {
+ "onedox": "./onedox.js"
+ },
+ "dependencies": {
+ "dox": "*",
+ "jinjs": "*",
+ "optimist": "*"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {}
+}
45 templates/index.html
@@ -0,0 +1,45 @@
+<html>
+ <head>
+ <title>{{ title }}</title>
+
+ <style>
+ body {
+ font-family: helvetica, sans-serif;
+ }
+ a, a:visited, h1 {
+ color: darkred;
+ }
+ a:hover {
+ color: white;
+ background: darkred;
+ }
+ td {
+ vertical-align: top;
+ padding-bottom: 10px;
+ }
+ menu {
+ border-bottom: 2px solid wheat;
+ padding: 3px;
+ }
+ </style>
+ </head>
+ <body>
+ <h1><tt>{{ title }}</tt></h1>
+ {% if menu %}
+ <menu>
+ {% for file, url in menu %}
+ <a href="{{ url }}">{{ file }}</a>
+ {% endfor %}
+ </menu>
+ {% endif %}
+
+ <table>
+ {% for d in docs %}
+ <tr>
+ <td>{{ d.description.full }}</td>
+ <td><pre>{{ d.code }}</pre></td>
+ </tr>
+ {% endfor %}
+ </table>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.