Permalink
Browse files

Started styles

  • Loading branch information...
1 parent 283e2e8 commit 07e50fbf65ee6cc47681e97fcb3b7ccc822ac0d0 @tj committed Jun 23, 2010
Showing with 145 additions and 58 deletions.
  1. +2 −0 Makefile
  2. +5 −58 bin/dox
  3. +126 −0 lib/index.js
  4. +2 −0 lib/styles/default/foot.html
  5. +7 −0 lib/styles/default/head.html
  6. +3 −0 lib/styles/default/style.css
View
@@ -3,8 +3,10 @@ PREFIX = /usr/local
install: bin/dox
cp -f $< $(PREFIX)/bin/dox
+ cp -fr lib ~/.node_libraries/dox
uninstall:
rm -f $(PREFIX)/bin/dox
+ rm -fr ~/.node_libraries/dox
.PHONY: install uninstall
View
@@ -1,62 +1,9 @@
#!/usr/bin/env node
-/**
- * Module dependencies.
+/*!
+ * Dox
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
*/
-var sys = require('sys'),
- fs = require('fs'),
- args = process.argv.slice(2);
-
-if (args) {
- args.forEach(function(arg){
- fs.readFile(arg, 'utf8', function(err, str){
- if (err) throw err;
- render(str, sys.print);
- });
- });
-} else {
- throw new Error('files required.');
-}
-
-function render(str, fn){
- var parts = str.split(/\s*\/\*([^]+?)\*\/\s*/g),
- blocks = [];
-
- // Populate blocks
- for (var i = 0, len = parts.length; i < len; ++i) {
- var part = parts[i],
- next = parts[i + 1] || '';
- // Empty
- if (/^\s*$/.test(part)) {
- continue;
- // Ignored comment
- } else if (/^!\s*\*/.test(part)) {
- continue;
- } else {
- ++i;
- var part = part
- .replace(/^ *\*/gm, '');
- blocks.push({
- comment: part,
- code: next
- });
- }
- }
-
- // Generate html
- var html = ['<table>'];
- for (var i = 0, len = blocks.length; i < len; ++i) {
- var block = blocks[i];
- html.push('<tr>');
- html.push('<td class="comment">', block.comment
- ? '<pre>' + block.comment + '</pre>'
- : '', '</td>');
- html.push('<td class="code">', block.code
- ? '<pre class="code">' + block.code + '</pre>'
- : '', '</td>');
- html.push('</tr>');
- }
-
- fn(html.concat('</table>').join('\n'));
-}
+require('dox').parse(process.argv.slice(2));
View
@@ -0,0 +1,126 @@
+
+/*!
+ * Dox
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys'),
+ fs = require('fs');
+
+/**
+ * Style name.
+ */
+
+var style = 'default';
+
+/**
+ * Document title.
+ */
+
+var title = 'Dont forget to use --title to specify me!';
+
+/**
+ * Parse JSDoc.
+ */
+
+var jsdoc = true;
+
+/**
+ * Parse the given arguments.
+ *
+ * @param {Array} args
+ * @api public
+ */
+
+exports.parse = function(args){
+ var files = [];
+
+ // Parse arguments
+ while (args.length) {
+ var arg = args.shift();
+ switch (arg) {
+ default:
+ files.push(arg);
+ }
+ }
+
+ if (files.length) {
+ var pending = files.length;
+
+ // Style
+ var head = fs.readFileSync(__dirname + '/styles/' + style + '/head.html', 'utf8');
+ var foot = fs.readFileSync(__dirname + '/styles/' + style + '/foot.html', 'utf8');
+ var css = fs.readFileSync(__dirname + '/styles/' + style + '/style.css', 'utf8');
+
+ // Substitutions
+ head = head.replace(/\{\{title\}\}/g, title).replace(/\{\{style\}\}/, css);
+
+ sys.print(head);
+
+ files.forEach(function(file){
+ fs.readFile(file, 'utf8', function(err, str){
+ if (err) throw err;
+ sys.print(render(str));
+ --pending || sys.print(foot);
+ });
+ });
+
+ } else {
+ throw new Error('files required.');
+ }
+};
+
+/**
+ * Generate html for the given string of code.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api public
+ */
+
+var render = exports.render = function(str){
+ var parts = str.split(/\s*\/\*([^]+?)\*\/\s*/g),
+ blocks = [];
+
+ // Populate blocks
+ for (var i = 0, len = parts.length; i < len; ++i) {
+ var part = parts[i],
+ next = parts[i + 1] || '';
+ // Empty
+ if (/^\s*$/.test(part)) {
+ continue;
+ // Ignored comment
+ } else if (/^!\s*\*/.test(part)) {
+ continue;
+ } else {
+ ++i;
+ var part = part
+ .replace(/^ *\*/gm, '');
+ blocks.push({
+ comment: part,
+ code: next
+ });
+ }
+ }
+
+ // Generate html
+ var html = ['<table>'];
+ for (var i = 0, len = blocks.length; i < len; ++i) {
+ var block = blocks[i];
+ html.push('<tr>');
+ html.push('<td class="comment">', block.comment
+ ? '<pre>' + block.comment + '</pre>'
+ : '', '</td>');
+ html.push('<td class="code">', block.code
+ ? '<pre class="code">' + block.code + '</pre>'
+ : '', '</td>');
+ html.push('</tr>');
+ }
+
+ return html.concat('</table>').join('\n');
+}
@@ -0,0 +1,2 @@
+ </body>
+</html>
@@ -0,0 +1,7 @@
+<html>
+ <head>
+ <title>{{title}}</title>
+ <style>{{style}}</style>
+ </head>
+ <body>
+ <h1>{{title}}</h1>
@@ -0,0 +1,3 @@
+body {
+ padding: 10px;
+}

0 comments on commit 07e50fb

Please sign in to comment.