Skip to content

Commit

Permalink
Organize settings/options into groups that will be collapsable
Browse files Browse the repository at this point in the history
Waiting on Atom/settings-view support: atom/settings-view#736
  • Loading branch information
Glavin001 committed Feb 22, 2016
1 parent 5fe5f36 commit f2968b7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 101 deletions.
90 changes: 25 additions & 65 deletions src/beautifiers/index.coffee
Expand Up @@ -105,23 +105,28 @@ module.exports = class Beautifiers extends EventEmitter
langOptions = {}
languages = {} # Hash map of languages with their names
for lang in @languages.languages
langOptions[lang.name] ?= {}
# Use the namespace from language as key prefix
namespace = lang.namespace
langOptions[namespace] ?= {
title: lang.name,
type: 'object',
description: "Options for language #{lang.name}"
collapsed: true
properties: {}
}
languages[lang.name] ?= lang
options = langOptions[lang.name]

options = _.get(langOptions, "#{namespace}.properties")

# Init field for supported beautifiers
lang.beautifiers = []


# Process all language options
for field, op of lang.options
if not op.title?
op.title = _plus.uncamelcase(field).split('.')
.map(_plus.capitalize).join(' ')
op.title = "#{lang.name} - #{op.title}"


# Init field for supported beautifiers
op.beautifiers = []

Expand All @@ -138,11 +143,10 @@ module.exports = class Beautifiers extends EventEmitter
for beautifier in beautifiers
beautifierName = beautifier.name


# Iterate over supported languages
for languageName, options of beautifier.options
laOp = langOptions[languageName]

namespace = languages[languageName].namespace
laOp = _.get(langOptions, "#{namespace}.properties")

# Is a valid Language name
if typeof options is "boolean"
Expand All @@ -151,7 +155,6 @@ module.exports = class Beautifiers extends EventEmitter
# Add Beautifier support to Language
languages[languageName]?.beautifiers.push(beautifierName)


# Check for beautifier's options support
if options is true

Expand Down Expand Up @@ -191,7 +194,6 @@ module.exports = class Beautifiers extends EventEmitter
# Complex Function
[fields..., fn] = op


# Add beautifier support to all required fields
languages[languageName]?.beautifiers.push(beautifierName)
for f in fields
Expand All @@ -203,89 +205,47 @@ module.exports = class Beautifiers extends EventEmitter
# Unsupported
logger.warn("Unsupported option:", beautifierName, languageName, field, op, langOptions)

# Prefix language's options with namespace
for langName, ops of langOptions

# Get language with name
lang = languages[langName]


# Use the namespace from language as key prefix
prefix = lang.namespace


# logger.verbose(langName, lang, prefix, ops)
# Iterate over all language options and rename fields
for field, op of ops

# Rename field
delete ops[field]
ops["#{prefix}_#{field}"] = op

# Flatten Options per language to array of all options
allOptions = _.values(langOptions)


# logger.verbose('allOptions', allOptions)
# Flatten array of objects to single object for options
flatOptions = _.reduce(allOptions, ((result, languageOptions, language) ->

# Iterate over fields (keys) in Language's Options
# and merge them into single result
# logger.verbose('language options', language, languageOptions, result)
return _.reduce(languageOptions, ((result, optionDef, optionName) ->

# TODO: Add supported beautifiers to option description
# logger.verbose('optionDef', optionDef, optionName)
# Improve descriptions to each language option
for g,group of langOptions
for o,optionDef of group.properties
if optionDef.beautifiers.length > 0

# optionDef.title = "
optionDef.description = "#{optionDef.description} (Supported by #{optionDef.beautifiers.join(', ')})"
else

# optionDef.title = "(DEPRECATED)
optionDef.description = "#{optionDef.description} (Not supported by any beautifiers)"
if result[optionName]?
logger.warn("Duplicate option detected: ", optionName, optionDef)
result[optionName] = optionDef
return result
), result)
), {})


# Generate Language configurations
# logger.verbose('languages', languages)
for langName, lang of languages

# logger.verbose(langName, lang)
name = lang.name
namespace = lang.namespace
beautifiers = lang.beautifiers
optionName = "language_#{lang.namespace}"

optionName = "language_#{namespace}"

# Add Language configurations
flatOptions["#{optionName}_disabled"] = {
_.set(langOptions, "#{namespace}.disabled", {
title : "Language Config - #{name} - Disable Beautifying Language"
type : 'boolean'
default : false
description : "Disable #{name} Beautification"
}
flatOptions["#{optionName}_default_beautifier"] = {
})
_.set(langOptions, "#{namespace}.default_beautifier", {
title : "Language Config - #{name} - Default Beautifier"
type : 'string'
default : lang.defaultBeautifier ? beautifiers[0]
description : "Default Beautifier to be used for #{name}"
enum : _.uniq(beautifiers)
}
flatOptions["#{optionName}_beautify_on_save"] = {
})
_.set(langOptions, "#{namespace}.beautify_on_save", {
title : "Language Config - #{name} - Beautify On Save"
type : 'boolean'
default : false
description : "Automatically beautify #{name} files on save"
}
})

# logger.verbose('flatOptions', flatOptions)
return flatOptions
# logger.verbose('langOptions', langOptions)
return langOptions


###
Expand Down
78 changes: 42 additions & 36 deletions src/config.coffee
@@ -1,37 +1,43 @@
module.exports = {
analytics :
title: 'Anonymous Analytics'
type : 'boolean'
default : true
description : "There is [Segment.io](https://segment.io/) which forwards data to [Google
Analytics](http://www.google.com/analytics/) to track what languages are being
used the most, as well as other stats. Everything is anonymized and no personal
information, such as source code, is sent.
See https://github.com/Glavin001/atom-beautify/issues/47 for more details."
_analyticsUserId :
title: 'Analytics User Id'
type : 'string'
default : ""
description : "Unique identifier for this user for tracking usage analytics"
_loggerLevel :
title: "Logger Level"
type : 'string'
default : 'warn'
description : 'Set the level for the logger'
enum : ['verbose', 'debug', 'info', 'warn', 'error']
beautifyEntireFileOnSave :
title: "Beautify Entire File On Save"
type : 'boolean'
default : true
description : "When beautifying on save, use the entire file, even if there is selected text in the editor"
muteUnsupportedLanguageErrors :
title: "Mute Unsupported Language Errors"
type : 'boolean'
default : false
description : "Do not show \"Unsupported Language\" errors when they occur"
muteAllErrors :
title: "Mute All Errors"
type : 'boolean'
default : false
description : "Do not show any/all errors when they occur"
}
_general:
title: 'General'
type: 'object'
collapsed: true
description: 'General options for Atom Beautify'
properties:
analytics :
title: 'Anonymous Analytics'
type : 'boolean'
default : true
description : "There is [Segment.io](https://segment.io/) which forwards data to [Google
Analytics](http://www.google.com/analytics/) to track what languages are being
used the most, as well as other stats. Everything is anonymized and no personal
information, such as source code, is sent.
See https://github.com/Glavin001/atom-beautify/issues/47 for more details."
_analyticsUserId :
title: 'Analytics User Id'
type : 'string'
default : ""
description : "Unique identifier for this user for tracking usage analytics"
_loggerLevel :
title: "Logger Level"
type : 'string'
default : 'warn'
description : 'Set the level for the logger'
enum : ['verbose', 'debug', 'info', 'warn', 'error']
beautifyEntireFileOnSave :
title: "Beautify Entire File On Save"
type : 'boolean'
default : true
description : "When beautifying on save, use the entire file, even if there is selected text in the editor"
muteUnsupportedLanguageErrors :
title: "Mute Unsupported Language Errors"
type : 'boolean'
default : false
description : "Do not show \"Unsupported Language\" errors when they occur"
muteAllErrors :
title: "Mute All Errors"
type : 'boolean'
default : false
description : "Do not show any/all errors when they occur"
}

1 comment on commit f2968b7

@Glavin001
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.