Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit.

  • Loading branch information...
commit e475572906c2ce4ed9d1d0e4ced3278d946cc2f1 0 parents
Morten Siebuhr msiebuhr authored
2  .gitignore
... ... @@ -0,0 +1,2 @@
  1 +doc/
  2 +node_modules/
69 onedox.js
... ... @@ -0,0 +1,69 @@
  1 +#!/usr/bin/env node
  2 +/*
  3 + * Generate some documentation from DOX + stupid templating.
  4 + */
  5 +
  6 +// Make `require()` work on HTML too!
  7 +require('jinjs').registerExtension(".html");
  8 +
  9 +var dox = require('dox'),
  10 + fs = require('fs'),
  11 + optimist = require('optimist'),
  12 + path = require('path'),
  13 + template = require('./templates/index.html');
  14 +
  15 +var argv = optimist
  16 + .usage("$0 --out <outdir> file1.js ...")
  17 + .describe("out", "Dir to write output in")
  18 + .demand(1)
  19 + .demand("out")
  20 + .argv;
  21 +
  22 +/*
  23 + * Read files and DOX them.
  24 + */
  25 +var files = [],
  26 + linkList = {};
  27 +
  28 +argv._.forEach(function (file) {
  29 + try {
  30 + var docs = dox.parseComments(fs.readFileSync(file, 'utf-8'));
  31 + } catch (e) {
  32 + console.error("✗ Couldn't parse", file);
  33 + return;
  34 + }
  35 +
  36 + var outFile = file.replace(/\.js$/, '').replace(/\//g, '_') + '.html';
  37 + linkList[file] = outFile;
  38 + files.push({
  39 + source: file,
  40 + dox: docs,
  41 + outFile: path.join(argv.out, outFile)
  42 + });
  43 +});
  44 +
  45 +/*
  46 + * Run each file through the template and write it out.
  47 + */
  48 +files.forEach(function (file) {
  49 + fs.writeFileSync(file.outFile, template.render({
  50 + docs: file.dox,
  51 + menu: linkList,
  52 + title: file.source
  53 + }));
  54 + console.log("✓ Wrote", file.outFile);
  55 +});
  56 +
  57 +/*
  58 + * No index.html created?
  59 + */
  60 +if (!('index.js' in linkList)) {
  61 + var index = path.join(argv.out, "index.html");
  62 + fs.writeFileSync(index, template.render({
  63 + docs: [],
  64 + menu: linkList,
  65 + title: "Documentation index"
  66 + }));
  67 + console.log("✓ Wrote", index, "(no index.js to use as entry point)");
  68 +}
  69 +
16 package.json
... ... @@ -0,0 +1,16 @@
  1 +{
  2 + "author": "Morten Siebuhr",
  3 + "name": "onedox",
  4 + "description": "Annotated source code documenter",
  5 + "version": "0.0.0",
  6 + "bin": {
  7 + "onedox": "./onedox.js"
  8 + },
  9 + "dependencies": {
  10 + "dox": "*",
  11 + "jinjs": "*",
  12 + "optimist": "*"
  13 + },
  14 + "devDependencies": {},
  15 + "optionalDependencies": {}
  16 +}
45 templates/index.html
... ... @@ -0,0 +1,45 @@
  1 +<html>
  2 + <head>
  3 + <title>{{ title }}</title>
  4 +
  5 + <style>
  6 + body {
  7 + font-family: helvetica, sans-serif;
  8 + }
  9 + a, a:visited, h1 {
  10 + color: darkred;
  11 + }
  12 + a:hover {
  13 + color: white;
  14 + background: darkred;
  15 + }
  16 + td {
  17 + vertical-align: top;
  18 + padding-bottom: 10px;
  19 + }
  20 + menu {
  21 + border-bottom: 2px solid wheat;
  22 + padding: 3px;
  23 + }
  24 + </style>
  25 + </head>
  26 + <body>
  27 + <h1><tt>{{ title }}</tt></h1>
  28 + {% if menu %}
  29 + <menu>
  30 + {% for file, url in menu %}
  31 + <a href="{{ url }}">{{ file }}</a>
  32 + {% endfor %}
  33 + </menu>
  34 + {% endif %}
  35 +
  36 + <table>
  37 + {% for d in docs %}
  38 + <tr>
  39 + <td>{{ d.description.full }}</td>
  40 + <td><pre>{{ d.code }}</pre></td>
  41 + </tr>
  42 + {% endfor %}
  43 + </table>
  44 + </body>
  45 +</html>

0 comments on commit e475572

Please sign in to comment.
Something went wrong with that request. Please try again.