Permalink
Browse files

Clean up generated file-navigation.

Fixes #4.
  • Loading branch information...
1 parent 6da6dfe commit 1b2f5c9c24fe5984f7663328b84f318bda9e6d83 @msiebuhr msiebuhr committed Nov 1, 2012
Showing with 52 additions and 5 deletions.
  1. +36 −3 onedox.js
  2. +16 −2 templates/index.html
View
@@ -46,17 +46,50 @@ mkdirp(staticDir, function () {
source: file,
dox: parser(file),
outFileRelative: outFile,
- outFile: path.join(argv.out, outFile)
+ outFile: path.join(argv.out, outFile),
+ sourceFilename: path.basename(file)
});
});
+ /* Show a nice tree hierarcy.
+ */
+ var menuTree = {},
+ inspect = require('util').inspect;
+
+ parsedFiles.forEach(function (file) {
+ var dirname = path.dirname(file.source);
+
+ if (dirname in menuTree) {
+ menuTree[dirname].files.push(file);
+ } else {
+ menuTree[dirname] = {
+ sortKey: dirname,
+ files: [file],
+ dirname: path.basename(dirname) + "/",
+ indent: dirname.split("/").length - 1
+ };
+ }
+ });
+
+ // Flatten and sort based on full path (`sortKey`).
+ var menu = [];
+ Object.keys(menuTree).sort().forEach(function (key) {
+ // Sort file names in folder
+ menuTree[key].files.sort(function (a, b) {
+ return a.sourceFilename.localeCompare(b.sourceFilename);
+ });
+
+ // Push it on the output array
+ menu.push(menuTree[key]);
+ });
+
/*
* Run each file through the template and write it out.
*/
parsedFiles.forEach(function (file) {
fs.writeFileSync(file.outFile, template.render({
docs: file.dox,
- files: parsedFiles,
+ menu: menu,
title: file.source
}));
console.log("✓ Wrote", file.outFile);
@@ -72,7 +105,7 @@ mkdirp(staticDir, function () {
if (indexHtml) {
var index = path.join(argv.out, "index.html");
fs.writeFileSync(index, template.render({
- files: parsedFiles,
+ menu: menu,
title: "Documentation index"
}));
console.log("✓ Wrote", index, "(no index.js to use as entry point)");
View
@@ -44,13 +44,27 @@
border-bottom: 2px solid wheat;
padding: 3px;
}
+
+ menu .dirname {
+ font-family: Monospace;
+ font-size: 1.1em;
+ }
+
+ menu a {
+ margin-left: 0.5em;
+ }
</style>
</head>
<body>
<h1><tt>{{ title }}</tt></h1>
<menu>
- {% for f in files %}
- <a href="{{ f.outFileRelative }}">{{ f.source }}</a>
+ {% for dir in menu %}
+ <span class="dirname" style="padding-left: {{ dir.indent * 1.5 }}em;">{{ dir.dirname }}</span>
+
+ {% for file in dir.files %}
+ <a href="{{ file.outFileRelative }}">{{ file.sourceFilename }}</a>
+ {% endfor %}
+ <br/>
{% endfor %}
</menu>

0 comments on commit 1b2f5c9

Please sign in to comment.