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')
|
Handlebars = require('handlebars')
|
||||||
Beautifiers = require("../src/beautifiers")
|
Beautifiers = require("../src/beautifiers")
|
||||||
fs = require('fs')
|
fs = require('fs')
|
||||||
|
_ = require('lodash')
|
||||||
|
|
||||||
console.log('Generating options...')
|
console.log('Generating options...')
|
||||||
beautifier = new Beautifiers()
|
beautifier = new Beautifiers()
|
||||||
|
@ -11,7 +12,8 @@ languageOptions = beautifier.options
|
||||||
packageOptions = require('../src/config.coffee')
|
packageOptions = require('../src/config.coffee')
|
||||||
# Build options by Beautifier
|
# Build options by Beautifier
|
||||||
beautifierOptions = {}
|
beautifierOptions = {}
|
||||||
for optionName, optionDef of languageOptions
|
for lo, optionGroup of languageOptions
|
||||||
|
for optionName, optionDef of optionGroup.properties
|
||||||
beautifiers = optionDef.beautifiers ? []
|
beautifiers = optionDef.beautifiers ? []
|
||||||
for beautifierName in beautifiers
|
for beautifierName in beautifiers
|
||||||
beautifierOptions[beautifierName] ?= {}
|
beautifierOptions[beautifierName] ?= {}
|
||||||
|
@ -20,12 +22,15 @@ for optionName, optionDef of languageOptions
|
||||||
console.log('Loading options template...')
|
console.log('Loading options template...')
|
||||||
optionsTemplatePath = __dirname + '/options-template.md'
|
optionsTemplatePath = __dirname + '/options-template.md'
|
||||||
optionTemplatePath = __dirname + '/option-template.md'
|
optionTemplatePath = __dirname + '/option-template.md'
|
||||||
|
optionGroupTemplatePath = __dirname + '/option-group-template.md'
|
||||||
optionsPath = __dirname + '/options.md'
|
optionsPath = __dirname + '/options.md'
|
||||||
optionsTemplate = fs.readFileSync(optionsTemplatePath).toString()
|
optionsTemplate = fs.readFileSync(optionsTemplatePath).toString()
|
||||||
|
optionGroupTemplate = fs.readFileSync(optionGroupTemplatePath).toString()
|
||||||
optionTemplate = fs.readFileSync(optionTemplatePath).toString()
|
optionTemplate = fs.readFileSync(optionTemplatePath).toString()
|
||||||
|
|
||||||
console.log('Building documentation from template and options...')
|
console.log('Building documentation from template and options...')
|
||||||
Handlebars.registerPartial('option', optionTemplate)
|
Handlebars.registerPartial('option', optionTemplate)
|
||||||
|
Handlebars.registerPartial('option-group', optionGroupTemplate)
|
||||||
template = Handlebars.compile(optionsTemplate)
|
template = Handlebars.compile(optionsTemplate)
|
||||||
|
|
||||||
linkifyTitle = (title) ->
|
linkifyTitle = (title) ->
|
||||||
|
@ -66,10 +71,31 @@ Handlebars.registerHelper('example-config', (key, option, options) ->
|
||||||
return new Handlebars.SafeString(results)
|
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 = {
|
context = {
|
||||||
packageOptions: packageOptions
|
packageOptions: sortSettings(packageOptions)
|
||||||
languageOptions: languageOptions
|
languageOptions: sortSettings(languageOptions)
|
||||||
beautifierOptions: beautifierOptions
|
beautifierOptions: sortSettings(beautifierOptions)
|
||||||
}
|
}
|
||||||
result = template(context)
|
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}}
|
{{#if beautifiers}}
|
||||||
**Namespace**: `{{language.namespace}}`
|
**Namespace**: `{{language.namespace}}`
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
{{{description}}}
|
{{{description}}}
|
||||||
|
|
||||||
{{#if beautifiers}}
|
{{#if language}}
|
||||||
**Example `.jsbeautifyrc` Configuration**
|
**Example `.jsbeautifyrc` Configuration**
|
||||||
|
|
||||||
{{example-config this}}
|
{{example-config this}}
|
||||||
|
|
|
@ -9,7 +9,7 @@ Configurable options for Atom Beautify.
|
||||||
---
|
---
|
||||||
|
|
||||||
{{#each packageOptions}}
|
{{#each packageOptions}}
|
||||||
{{> option}}
|
{{> option-group}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
## Language Options
|
## Language Options
|
||||||
|
@ -19,7 +19,7 @@ Supported options for each language.
|
||||||
---
|
---
|
||||||
|
|
||||||
{{#each languageOptions}}
|
{{#each languageOptions}}
|
||||||
{{> option}}
|
{{> option-group}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
## Beautifier Options
|
## 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',
|
type: 'object',
|
||||||
description: "Options for language #{lang.name}"
|
description: "Options for language #{lang.name}"
|
||||||
collapsed: true
|
collapsed: true
|
||||||
|
beautifiers: []
|
||||||
properties: {}
|
properties: {}
|
||||||
}
|
}
|
||||||
languages[lang.name] ?= lang
|
languages[lang.name] ?= lang
|
||||||
|
@ -164,6 +165,7 @@ module.exports = class Beautifiers extends EventEmitter
|
||||||
# Enable / disable all options
|
# Enable / disable all options
|
||||||
# Add Beautifier support to Language
|
# Add Beautifier support to Language
|
||||||
languages[languageName]?.beautifiers.push(beautifierName)
|
languages[languageName]?.beautifiers.push(beautifierName)
|
||||||
|
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
|
||||||
|
|
||||||
# Check for beautifier's options support
|
# Check for beautifier's options support
|
||||||
if options is true
|
if options is true
|
||||||
|
@ -187,6 +189,7 @@ module.exports = class Beautifiers extends EventEmitter
|
||||||
# Transformation
|
# Transformation
|
||||||
if op is true
|
if op is true
|
||||||
languages[languageName]?.beautifiers.push(beautifierName)
|
languages[languageName]?.beautifiers.push(beautifierName)
|
||||||
|
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
|
||||||
laOp?[field]?.beautifiers.push(beautifierName)
|
laOp?[field]?.beautifiers.push(beautifierName)
|
||||||
else if typeof op is "string"
|
else if typeof op is "string"
|
||||||
|
|
||||||
|
@ -198,6 +201,7 @@ module.exports = class Beautifiers extends EventEmitter
|
||||||
|
|
||||||
# Transformation
|
# Transformation
|
||||||
languages[languageName]?.beautifiers.push(beautifierName)
|
languages[languageName]?.beautifiers.push(beautifierName)
|
||||||
|
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
|
||||||
laOp?[field]?.beautifiers.push(beautifierName)
|
laOp?[field]?.beautifiers.push(beautifierName)
|
||||||
else if _.isArray(op)
|
else if _.isArray(op)
|
||||||
|
|
||||||
|
@ -206,6 +210,7 @@ module.exports = class Beautifiers extends EventEmitter
|
||||||
|
|
||||||
# Add beautifier support to all required fields
|
# Add beautifier support to all required fields
|
||||||
languages[languageName]?.beautifiers.push(beautifierName)
|
languages[languageName]?.beautifiers.push(beautifierName)
|
||||||
|
_.get(langOptions, "#{namespace}.beautifiers")?.push(beautifierName)
|
||||||
for f in fields
|
for f in fields
|
||||||
|
|
||||||
# Add beautifier to required field
|
# Add beautifier to required field
|
||||||
|
@ -223,7 +228,7 @@ module.exports = class Beautifiers extends EventEmitter
|
||||||
optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})"
|
optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})"
|
||||||
else
|
else
|
||||||
# optionDef.description = "#{optionDef.description} (Not supported by any beautifiers)"
|
# 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}")
|
unsupportedOptions.push("#{g}.properties.#{o}")
|
||||||
# Delete unsupported options
|
# Delete unsupported options
|
||||||
for p in unsupportedOptions
|
for p in unsupportedOptions
|
||||||
|
|
Loading…
Reference in New Issue