See #713. Update options documentation generator for new settings structure
This commit is contained in:
parent
74526b6821
commit
9d88fe880d
|
@ -4,6 +4,7 @@
|
|||
Handlebars = require('handlebars')
|
||||
Beautifiers = require("../src/beautifiers")
|
||||
fs = require('fs')
|
||||
_ = require('lodash')
|
||||
|
||||
console.log('Generating options...')
|
||||
beautifier = new Beautifiers()
|
||||
|
@ -11,7 +12,8 @@ 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] ?= {}
|
||||
|
@ -20,12 +22,15 @@ for optionName, optionDef of languageOptions
|
|||
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) ->
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -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}}
|
|
@ -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}}
|
||||
|
|
|
@ -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
|
||||
|
|
16049
docs/options.md
16049
docs/options.md
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue