2015-06-01 12:52:33 -06:00
|
|
|
#!/usr/bin/env coffee
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
Handlebars = require('handlebars')
|
|
|
|
Beautifiers = require("../src/beautifiers")
|
|
|
|
fs = require('fs')
|
|
|
|
|
|
|
|
console.log('Generating options...')
|
|
|
|
beautifier = new Beautifiers()
|
2015-06-01 13:50:09 -06:00
|
|
|
languageOptions = beautifier.options
|
|
|
|
packageOptions = require('../src/config.coffee')
|
2015-06-08 16:05:03 -06:00
|
|
|
# Build options by Beautifier
|
|
|
|
beautifierOptions = {}
|
|
|
|
for optionName, optionDef of languageOptions
|
|
|
|
beautifiers = optionDef.beautifiers ? []
|
|
|
|
for beautifierName in beautifiers
|
|
|
|
beautifierOptions[beautifierName] ?= {}
|
|
|
|
beautifierOptions[beautifierName][optionName] = optionDef
|
2015-06-01 12:52:33 -06:00
|
|
|
|
|
|
|
console.log('Loading options template...')
|
2015-06-01 13:50:09 -06:00
|
|
|
optionsTemplatePath = __dirname + '/options-template.md'
|
|
|
|
optionTemplatePath = __dirname + '/option-template.md'
|
2015-06-01 12:52:33 -06:00
|
|
|
optionsPath = __dirname + '/options.md'
|
2015-06-01 13:50:09 -06:00
|
|
|
optionsTemplate = fs.readFileSync(optionsTemplatePath).toString()
|
|
|
|
optionTemplate = fs.readFileSync(optionTemplatePath).toString()
|
|
|
|
|
2015-06-01 12:52:33 -06:00
|
|
|
console.log('Building documentation from template and options...')
|
2015-06-01 13:50:09 -06:00
|
|
|
Handlebars.registerPartial('option', optionTemplate)
|
|
|
|
template = Handlebars.compile(optionsTemplate)
|
2015-06-09 09:02:52 -06:00
|
|
|
|
|
|
|
linkifyTitle = (title) ->
|
|
|
|
title = title.toLowerCase()
|
|
|
|
p = title.split(/[\s,+#;,\/?:@&=+$]+/) # split into parts
|
|
|
|
sep = "-"
|
|
|
|
p.join(sep)
|
|
|
|
|
|
|
|
Handlebars.registerHelper('linkify', (title, options) ->
|
|
|
|
return new Handlebars.SafeString(
|
|
|
|
"[#{options.fn(this)}](\##{linkifyTitle(title)})"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-06-01 12:52:33 -06:00
|
|
|
context = {
|
2015-06-01 13:50:09 -06:00
|
|
|
packageOptions: packageOptions
|
|
|
|
languageOptions: languageOptions
|
2015-06-08 16:05:03 -06:00
|
|
|
beautifierOptions: beautifierOptions
|
2015-06-01 12:52:33 -06:00
|
|
|
}
|
|
|
|
result = template(context)
|
|
|
|
|
|
|
|
console.log('Writing documentation to file...')
|
|
|
|
fs.writeFileSync(optionsPath, result)
|
|
|
|
|
2015-06-09 09:02:52 -06:00
|
|
|
console.log('Done.')
|