See #713. Update options documentation generator for new settings structure

This commit is contained in:
Glavin Wiechert 2016-03-21 13:46:52 -03:00
parent 74526b6821
commit 9d88fe880d
6 changed files with 11004 additions and 5125 deletions

View File

@ -4,6 +4,7 @@
Handlebars = require('handlebars')
Beautifiers = require("../src/beautifiers")
fs = require('fs')
_ = require('lodash')
console.log('Generating options...')
beautifier = new Beautifiers()
@ -11,33 +12,37 @@ languageOptions = beautifier.options
packageOptions = require('../src/config.coffee')
# Build options by Beautifier
beautifierOptions = {}
for optionName, optionDef of languageOptions
for lo, optionGroup of languageOptions
for optionName, optionDef of optionGroup.properties
beautifiers = optionDef.beautifiers ? []
for beautifierName in beautifiers
beautifierOptions[beautifierName] ?= {}
beautifierOptions[beautifierName][optionName] = optionDef
beautifierOptions[beautifierName] ?= {}
beautifierOptions[beautifierName][optionName] = optionDef
console.log('Loading options template...')
optionsTemplatePath = __dirname + '/options-template.md'
optionTemplatePath = __dirname + '/option-template.md'
optionGroupTemplatePath = __dirname + '/option-group-template.md'
optionsPath = __dirname + '/options.md'
optionsTemplate = fs.readFileSync(optionsTemplatePath).toString()
optionGroupTemplate = fs.readFileSync(optionGroupTemplatePath).toString()
optionTemplate = fs.readFileSync(optionTemplatePath).toString()
console.log('Building documentation from template and options...')
Handlebars.registerPartial('option', optionTemplate)
Handlebars.registerPartial('option-group', optionGroupTemplate)
template = Handlebars.compile(optionsTemplate)
linkifyTitle = (title) ->
title = title.toLowerCase()
p = title.split(/[\s,+#;,\/?:@&=+$]+/) # split into parts
sep = "-"
p.join(sep)
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)})"
)
return new Handlebars.SafeString(
"[#{options.fn(this)}](\##{linkifyTitle(title)})"
)
)
exampleConfig = (option) ->
@ -66,10 +71,31 @@ Handlebars.registerHelper('example-config', (key, option, options) ->
return new Handlebars.SafeString(results)
)
sortKeysBy = (obj, comparator) ->
keys = _.sortBy(_.keys(obj), (key) ->
return if comparator then comparator(obj[key], key) else key
)
return _.zipObject(keys, _.map(keys, (key) ->
return obj[key]
))
sortSettings = (settings) ->
# TODO: Process object type options
r = _.mapValues(settings, (op) ->
if op.type is "object" and op.properties
op.properties = sortSettings(op.properties)
return op
)
# Process these settings
r = sortKeysBy(sortKeysBy(r), (op) -> op.order)
# r = _.chain(r).sortBy((op) -> op.key).sortBy((op) -> settings[op.key]?.order).value()
# console.log('sort', settings, r)
return r
context = {
packageOptions: packageOptions
languageOptions: languageOptions
beautifierOptions: beautifierOptions
packageOptions: sortSettings(packageOptions)
languageOptions: sortSettings(languageOptions)
beautifierOptions: sortSettings(beautifierOptions)
}
result = template(context)

View File

@ -0,0 +1,13 @@
#### {{#if title}} {{#linkify title}}{{title}}{{/linkify}} {{else}} {{#linkify @key}}`{{@key}}`{{/linkify}} {{/if}}
{{#if beautifiers}}
**Supported Beautifiers**: {{#each beautifiers}} {{#linkify this}}`{{this}}`{{/linkify}} {{/each}}
{{/if}}
**Description**:
{{{description}}}
{{#each properties}}
{{> option}}
{{/each}}

View File

@ -1,4 +1,4 @@
#### {{#if title}} {{#linkify title}}{{title}}{{/linkify}} {{else}} {{#linkify @key}}`{{@key}}`{{/linkify}} {{/if}}
##### {{#if title}} {{#linkify title}}{{title}}{{/linkify}} {{else}} {{#linkify @key}}`{{@key}}`{{/linkify}} {{/if}}
{{#if beautifiers}}
**Namespace**: `{{language.namespace}}`
@ -26,7 +26,7 @@
{{{description}}}
{{#if beautifiers}}
{{#if language}}
**Example `.jsbeautifyrc` Configuration**
{{example-config this}}

View File

@ -9,7 +9,7 @@ Configurable options for Atom Beautify.
---
{{#each packageOptions}}
{{> option}}
{{> option-group}}
{{/each}}
## Language Options
@ -19,7 +19,7 @@ Supported options for each language.
---
{{#each languageOptions}}
{{> option}}
{{> option-group}}
{{/each}}
## Beautifier Options

File diff suppressed because it is too large Load Diff

View File

@ -112,6 +112,7 @@ module.exports = class Beautifiers extends EventEmitter
type: 'object',
description: "Options for language #{lang.name}"
collapsed: true
beautifiers: []
properties: {}
}
languages[lang.name] ?= lang
@ -164,6 +165,7 @@ module.exports = class Beautifiers extends EventEmitter
# Enable / disable all options
# Add Beautifier support to Language
languages[languageName]?.beautifiers.push(beautifierName)
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
# Check for beautifier's options support
if options is true
@ -187,6 +189,7 @@ module.exports = class Beautifiers extends EventEmitter
# Transformation
if op is true
languages[languageName]?.beautifiers.push(beautifierName)
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
laOp?[field]?.beautifiers.push(beautifierName)
else if typeof op is "string"
@ -198,6 +201,7 @@ module.exports = class Beautifiers extends EventEmitter
# Transformation
languages[languageName]?.beautifiers.push(beautifierName)
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
laOp?[field]?.beautifiers.push(beautifierName)
else if _.isArray(op)
@ -206,6 +210,7 @@ module.exports = class Beautifiers extends EventEmitter
# Add beautifier support to all required fields
languages[languageName]?.beautifiers.push(beautifierName)
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
for f in fields
# Add beautifier to required field
@ -223,7 +228,7 @@ module.exports = class Beautifiers extends EventEmitter
optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})"
else
# optionDef.description = "#{optionDef.description} (Not supported by any beautifiers)"
logger.warn("#{g}'s option '#{optionDef.title} not supported by any beautifiers!")
# logger.warn("#{g}'s option '#{optionDef.title} not supported by any beautifiers!")
unsupportedOptions.push("#{g}.properties.#{o}")
# Delete unsupported options
for p in unsupportedOptions