UNPKG

1.38 kBPlain TextView Raw
1#!/usr/bin/env coffee
2path = require 'path'
3fs = require 'fs'
4jade = require 'jade'
5_ = require 'underscore'
6md = require('node-markdown').Markdown
7
8paths =
9 bin: __dirname
10 root: path.join __dirname, '..'
11 docs: path.join __dirname, '../docs'
12 srcs: path.join __dirname, '../docs/doc_files'
13 jade: path.join __dirname, '../docs/templates'
14
15# Hash to store any variable needed in our template
16locals = {}
17
18# Create a hash of title => html for every doc source file
19docFiles = {}
20sources = fs.readdirSync paths.srcs
21for file in sources.sort()
22 source = fs.readFileSync(path.join(paths.srcs, file)).toString()
23 title = source.split("\n")[0].replace(/#/g, '').trim()
24
25 link = "<a name=\"#{file}\"><hr /></a>"
26 docFiles[title] =
27 ref: file
28 source: [link, md source].join "\n"
29locals.docs = _(docFiles).chain().values().map((val)-> val.source).value().join "\n"
30
31# Create a table of contents array
32toc = []
33for title, docObj of docFiles
34 toc.push "<li><a href=\"##{docObj.ref}\">#{title}</a></li>"
35locals.toc = "<ul>" + toc.join("\n") + "</ul>"
36
37# Compile the contents of the jade doc files
38layout = fs.readFileSync path.join paths.jade, 'index.jade'
39compiled = jade.compile layout
40
41# Parse the template with our auto-generated docs and toc, and write it to `index.html`
42index = compiled locals
43fs.writeFileSync path.join(paths.root, 'index.html'), index