Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
FGRibreau committed Jan 12, 2013
1 parent 906a386 commit 8a1a307
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 368 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ lib-cov
*.out
*.pid
*.gz
/node_modules/


pids
logs
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Matt McManus
Copyright (c) 2013 Francois-Guillaume Ribreau

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
38 changes: 13 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# dox-foundation
# doxx

Use [dox](https://github.com/visionmedia/dox) to automatically generate beautiful html documentation.
Use [dox](https://github.com/visionmedia/dox) to automatically generate beautiful html documentation. Doxx is a total refactoring of [dox-foundation](https://github.com/punkave/dox-foundation/).

Outputted HTML is based on templates and css from [ZURB's Foundation](http://foundation.zurb.com/) and syntax highlighting is done by [Prism.js](http://prismjs.com/).
Outputted HTML is by default based on templates and css from [ZURB's Foundation](http://foundation.zurb.com/) and syntax highlighting is done by [Prism.js](http://prismjs.com/).

## Installation
Install the module with: `npm install dox-foundation -g`
Install the module with: `npm install doxx -g`

## Documentation
```
$ dox-foundation --help
$ doxx --help
Usage: dox-foundation [options]
Usage: doxx [options]
Options:
Expand All @@ -27,31 +27,19 @@ $ dox-foundation --help
Examples:
# stdin
$ dox-foundation > myfile.html
# operates over stdio
$ dox-foundation < myfile.js > myfile.html
# parse a whole folder
$ dox-foundation --source lib --target docs
$ doxx --source lib --target docs
```

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).

## Release History
* *0.0.1* - Initial release
* *0.2.0* - Readable output
* *0.3.0* - Support for folder parsing
* *0.4.0* - Improved project navigation, major refactor of folder code

## Thanks & Contributors

* Thanks to [dox-basic](https://github.com/jepso/dox-basic) for the inspiration and much of the original code.
* [@sdepold](https://github.com/sdepold)
* [@fgribreau](https://twitter.com/fgribreau)
* *0.0.1* - (dox-foundation) Initial release
* *0.2.0* - (dox-foundation) Readable output
* *0.3.0* - (dox-foundation) Support for folder parsing
* *0.4.0* - (dox-foundation) Improved project navigation, major refactor of folder code
* *0.5.0* - Initial release of doxx

## License
Copyright (c) 2012 P'unk Avenue
Licensed under the MIT license.
Copyright (c) 2013 Francois-Guillaume Ribreau
104 changes: 0 additions & 104 deletions bin/dox-foundation

This file was deleted.

89 changes: 89 additions & 0 deletions bin/doxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env node

var program = require('commander'),
fs = require('fs'),
path = require('path'),
_ = require('lodash'),

dir = require('../lib/dir'),
parse = require('../lib/parser'),
compile = require('../lib/compile'),
symbols = require('../lib/symbols'),

version = require('../package').version;

/**
* Options & Defaults
*/
var ignoredDirs = 'test,public,static,views,templates';

program
.version(version)
// .option('-r, --raw', 'output \'raw\' comments, leaving the markdown intact')
.option('-d, --debug', 'output parsed comments for debugging')
.option('-t, --title <string>', 'The title for the page produced')
.option('-s, --source <source>', 'The folder which should get parsed')
.option('-i, --ignore <directories>', 'Comma seperated list of directories to ignore. Default: ' + ignoredDirs)
.option('-T, --target <target>', 'The folder which will contain the results. Default: <process.cwd()>/docs')
.option('--template <jade template>', 'The jade template file to use');

function showHelp(){
console.log(' Examples:\n');
console.log(' # parse a whole folder');
console.log(' $ doxx --source ./lib --target ./docs');
}

// examples
program.on('--help', showHelp);

// parse argv
program.parse(process.argv);

if(program.template){
compile.tpl = fs.readFileSync(program.template).toString();
}

if (!program.source) {
console.error(" Error you must define a source\n");
return showHelp();
}

var target = path.resolve(process.cwd(), program.target) || process.cwd() + '/docs',
source = path.resolve(process.cwd(), program.source),
ignore = program.ignore || ignoredDirs;

// Cleanup and turn into an array the ignoredDirs
ignore = ignore.trim().replace(' ','').split(',');

// Find, cleanup and validate all potential files
var files = dir.collectFiles(source, ignore);

dir.createTargetFolders(target, files);

// Parse each file
files = files.map(function(file) {
var dox = parse(path.join(source, file), {});
return {
name: file,
dox: dox,
symbols: symbols(dox)
};
});

// Compute all symboles
var allSymbols = files.reduce(function(m, a, b){
m = (a.symbols || []).concat(b.symbols || []);
return m;
}, []);

// Render and write each file
files.forEach(function(file){

var options = _.extend({}, file, {
title: program.title || require(process.cwd() + '/package').name,
allSymbols: allSymbols
});

var compiled = compile(options);
fs.writeFileSync(path.join(target, file.name+".html"), compiled);
});
3 changes: 1 addition & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ module.exports = function(grunt) {

// Default task.
grunt.registerTask('default', 'lint');

};
};
20 changes: 20 additions & 0 deletions lib/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var jade = require('jade'),
fs = require('fs'),
path = require('path');
_ = require('lodash');

/**
* Compile
* @param {Object} options
* @return {String}
*/
function compile(options){
return jade.compile(compile.tpl,{})(options);
}

/**
* Template used to produce the documentation
*/
compile.tpl = fs.readFileSync(path.resolve(__dirname,'../views/template.jade')).toString();

module.exports = compile;
46 changes: 46 additions & 0 deletions lib/dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var fs = require('fs'),
path = require('path'),
path = require('path'),
mkdirp = require('mkdirp'),
findit = require('findit'),
_ = require('lodash');

/*
* Create an array of all the right files in the source dir
*/
exports.collectFiles = function(source, options, callback) {
var dirtyFiles = findit.findSync(source), // tee hee!
ignore = options.ignore || [],
files = [];

dirtyFiles.forEach(function(file){
file = path.relative(source, file);

var doNotIgnore = _.all(ignore, function(d){
// return true if no part of the path is in the ignore list
return (file.indexOf(d) === -1);
});

if ((file.substr(-2) === 'js') && doNotIgnore) {
files.push(file);
}
});

return files;
};

/*
* Make sure the folder structure in target mirrors source
*/
exports.createTargetFolders = function(target, files) {
var folders = [];

files.forEach(function(file){
var folder = file.substr(0, file.lastIndexOf('/'));

if ((folder !== '') && (folders.indexOf(folder) === -1)) {
folders.push(folder);
mkdirp.sync(target + '/' + folder);
}
});
};
Loading

0 comments on commit 8a1a307

Please sign in to comment.