Skip to content

Commit

Permalink
See #282, #284. Move language options out of option of type object
Browse files Browse the repository at this point in the history
See Atom Settings-View bug:
atom/settings-view#386 (comment)
  • Loading branch information
Glavin001 committed May 2, 2015
1 parent a226261 commit 48af4a3
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -185,32 +185,27 @@ module.exports = class Beautifiers
), {})

# Generate Language configurations
langConfigs = {}
# Process all languages
# console.log('languages', languages)
for langName, lang of languages
# console.log(langName, lang)
name = lang.name
beautifiers = lang.beautifiers
langConfigs[name] = {
type: 'object'
properties:
disabled:
title: "Language Config - #{name} - Disable Beautifying Language"
type: 'boolean'
default: false
description: "Disable #{name} Beautification"
default_beautifier:
title: "Language Config - #{name} - Default Beautifier"
type: 'string'
default: beautifiers[0]
description: "Default Beautifier to be used for #{name}"
enum: _.uniq(beautifiers)
optionName = "language_#{lang.namespace}"
# Add Language configurations
flatOptions["#{optionName}_disabled"] = {
title: "Language Config - #{name} - Disable Beautifying Language"
type: 'boolean'
default: false
description: "Disable #{name} Beautification"
}
# Add Language configurations
flatOptions.languages = {
type: 'object'
properties: langConfigs
}

flatOptions["#{optionName}_default_beautifier"] = {
title: "Language Config - #{name} - Default Beautifier"
type: 'string'
default: beautifiers[0]
description: "Default Beautifier to be used for #{name}"
enum: _.uniq(beautifiers)
}
# console.log('flatOptions', flatOptions)
return flatOptions

###
Expand Down Expand Up @@ -238,12 +233,13 @@ module.exports = class Beautifiers
language = languages[0]

# Get language config
langConfig = atom.config.get("atom-beautify.languages")?[language.name]
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled")
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")

# Beautify!
unsupportedGrammar = false
# Check if Language is disabled
if langConfig?.disabled
if langDisabled
return resolve(null)

# Options for Language
Expand All @@ -264,7 +260,6 @@ module.exports = class Beautifiers
unsupportedGrammar = true
else
# Select beautifier from language config preferences
preferredBeautifierName = langConfig.default_beautifier
beautifier = _.find(beautifiers, (beautifier) ->
beautifier.name is preferredBeautifierName
) or beautifiers[0]
Expand Down

0 comments on commit 48af4a3

Please sign in to comment.