Skip to content
Browse files

Added option to create README.md from each module's docstring

  • Loading branch information...
1 parent e299e21 commit 8bd9d9fdc7df93ecfa8b3fb8b947bbe76ca97796 @lmaccherone committed Jan 10, 2012
Showing with 35 additions and 15 deletions.
  1. +1 −1 Cakefile
  2. +34 −14 src/docgen.coffee
View
2 Cakefile
@@ -12,7 +12,7 @@ task 'install', 'install the `coffeedoc` command into /usr/local (or --prefix)',
lib = base + '/lib/coffeedoc'
exec([
'mkdir -p ' + lib
- 'cp -rf bin README.md resources lib ' + lib
+ 'cp -rf bin README.md resources src vendor ' + lib
'ln -sf ' + lib + '/bin/coffeedoc ' + base + '/bin/coffeedoc'
].join(' && '), (err, stdout, stderr) ->
if err then console.error stderr
View
48 src/docgen.coffee
@@ -19,6 +19,8 @@ OPTIONS =
'-o, --output': 'Set output directory (default: ./docs)'
'--commonjs ': 'Use if target scripts use CommonJS for module loading (default)'
'--requirejs ': 'Use if target scripts use RequireJS for module loading'
+ '--readme ': 'Generates a README.md in the parent of the output directory'
+ '-r, --rout ': 'Set output directory for README.md (default: ./)'
help = ->
### Show help message and exit ###
@@ -32,20 +34,28 @@ opts = process.argv[2...process.argv.length]
if opts.length == 0 then help()
outputdir = 'docs'
-for o, idx in opts
- if o == '-o' or o == '--output'
- outputdir = opts[idx + 1]
- opts.splice(idx, 2)
- break
-if '-h' in opts or '--help' in opts
- help()
-if '--commonjs' in opts
- opts.shift()
- parser = new parsers.CommonJSParser()
-else if '--requirejs' in opts
- opts.shift()
- parser = new parsers.RequireJSParser()
-else
+readmedir = './'
+readme = false
+parser = null
+
+while opts[0]? and opts[0].substr(0, 1) == '-'
+ console.log(opts[0])
+ o = opts.shift()
+ switch o
+ when '-h', '--help'
+ help()
+ when '-o', '--output'
+ outputdir = opts.shift()
+ when '--commonjs'
+ parser = new parsers.CommonJSParser()
+ when '--requirejs'
+ parser = new parsers.RequireJSParser()
+ when '--readme'
+ readme = true
+ when '-r', '--rout'
+ readmedir = opts.shift()
+
+if not parser?
parser = new parsers.CommonJSParser()
if opts.length == 0
opts = ['.']
@@ -93,6 +103,9 @@ if sources.length > 0
fs.unlinkSync(target)
rm(outputdir)
fs.mkdirSync(outputdir, '755')
+
+ # Create README.md
+ readmeContents = []
# Iterate over source scripts
source_names = (s.replace(/\.coffee$/, '') for s in sources)
@@ -128,6 +141,9 @@ if sources.length > 0
cls.parent_module = module_path
cls.parent_name = clspath.join('.')
+ # Append to README.md
+ readmeContents.push(documentation.module.docstring)
+
# Convert markdown to html
renderMarkdown(documentation.module)
for c in documentation.module.classes
@@ -155,4 +171,8 @@ if sources.length > 0
# Make index page
index = eco.render(index_template, modules: modules)
fs.writeFile(path.join(outputdir, 'index.html'), index)
+
+ # Write README.md
+ fs.writeFile(path.join(readmedir, 'README.md'), readmeContents.join('\n'))
+

0 comments on commit 8bd9d9f

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