Skip to content

Commit

Permalink
jodoc can be configured by CommonJS Modules, AMD modules should work …
Browse files Browse the repository at this point in the history
…as well too
  • Loading branch information
drewwells committed Jul 25, 2011
1 parent 60926e2 commit 0a111f4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
71 changes: 44 additions & 27 deletions jodoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,62 @@ var sys = require('sys'),

//Return an options struct, with files
function getOptions() {

var args = process.argv.slice(2),
config,
arg = '',
options = {
files: []
};

while(args.length > 0) {
arg = args.shift();
switch(arg)
{
case '--server':
case '-s': options.server = true;
//Allow port to be passed optionally
if( !isNaN( args[0] ) ){
options.server = args.shift();
}
break;
};

case '--output':
case '-o': options.output = args.shift();
break;
if( args.length === 1 ){

case '--template': options.template = args.shift();
break;
try{

case '--toc': options.toc = args.shift();
break;
config = require( process.argv[2] );
return config;
} catch ( err ){

case '-t':
case '--title': options.title = args.shift();
break;
sys.puts( "Configuration module not found or failed to load, is it a value CommonJS module?" );
}

case '-ni':
case '--no-index': options.noindex = true;
break;
} else {

default: options.files.push(arg);
while(args.length > 0) {
arg = args.shift();
switch(arg)
{
case '--server':
case '-s': options.server = true;
//Allow port to be passed optionally
if( !isNaN( args[0] ) ){
options.server = args.shift();
}
break;

case '--output':
case '-o': options.output = args.shift();
break;

case '--template': options.template = args.shift();
break;

case '--toc': options.toc = args.shift();
break;

case '-t':
case '--title': options.title = args.shift();
break;

case '-ni':
case '--no-index': options.noindex = true;
break;

default: options.files.push(arg);
}
}
}

return options;
}

Expand Down
14 changes: 14 additions & 0 deletions samples/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
toc: 'doc/toc.mdown',
title: 'joDoc',
template: 'doc/template.html',
output: 'dist/doc',
server: true,
files: [
//Order here decides the order which it appears in the non-output directory form
'doc/main.mdown',
'doc/styleguide.mdown',
'src/core.js',
'src/utility.js',
]
};

0 comments on commit 0a111f4

Please sign in to comment.