Close #27. Add commands for beautifying with specific language
This commit is contained in:
parent
5da5b2be51
commit
346bf3c1af
|
@ -207,12 +207,17 @@ fs.writeFileSync(readmePath, readmeResult)
|
|||
|
||||
console.log('Updating package.json')
|
||||
# Add Language keywords
|
||||
ls = _.map(Object.keys(languagesMap), (a)->a.toLowerCase())
|
||||
languageNames = _.map(Object.keys(languagesMap), (a)->a.toLowerCase())
|
||||
|
||||
# Add Beautifier keywords
|
||||
bs = _.map(Object.keys(beautifiersMap), (a)->a.toLowerCase())
|
||||
keywords = _.union(pkg.keywords, ls, bs)
|
||||
beautifierNames = _.map(Object.keys(beautifiersMap), (a)->a.toLowerCase())
|
||||
keywords = _.union(pkg.keywords, languageNames, beautifierNames)
|
||||
pkg.keywords = keywords
|
||||
|
||||
# Add Language-specific beautify commands
|
||||
beautifyLanguageCommands = _.map(languageNames, (languageName) -> "atom-beautify:beautify-language-#{languageName}")
|
||||
pkg.activationCommands["atom-workspace"] = _.union(pkg.activationCommands["atom-workspace"], beautifyLanguageCommands)
|
||||
|
||||
fs.writeFileSync(path.resolve(__dirname,'../package.json'), JSON.stringify(pkg, undefined, 2))
|
||||
|
||||
console.log('Done.')
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Test Page</title>
|
||||
<script>
|
||||
function hello() {
|
||||
return "world";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello</h1>
|
||||
<p>
|
||||
World!
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Test Page</title>
|
||||
<script>
|
||||
function hello() {
|
||||
return "world";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Hello</h1>
|
||||
<p>
|
||||
World!
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
67
package.json
67
package.json
|
@ -189,7 +189,72 @@
|
|||
"atom-beautify:beautify-editor",
|
||||
"atom-beautify:migrate-settings",
|
||||
"core:save",
|
||||
"core:save-as"
|
||||
"core:save-as",
|
||||
"atom-beautify:beautify-language-apex",
|
||||
"atom-beautify:beautify-language-arduino",
|
||||
"atom-beautify:beautify-language-bash",
|
||||
"atom-beautify:beautify-language-c#",
|
||||
"atom-beautify:beautify-language-c",
|
||||
"atom-beautify:beautify-language-clojure",
|
||||
"atom-beautify:beautify-language-coffeescript",
|
||||
"atom-beautify:beautify-language-coldfusion",
|
||||
"atom-beautify:beautify-language-c++",
|
||||
"atom-beautify:beautify-language-crystal",
|
||||
"atom-beautify:beautify-language-css",
|
||||
"atom-beautify:beautify-language-csv",
|
||||
"atom-beautify:beautify-language-d",
|
||||
"atom-beautify:beautify-language-ejs",
|
||||
"atom-beautify:beautify-language-elm",
|
||||
"atom-beautify:beautify-language-erb",
|
||||
"atom-beautify:beautify-language-erlang",
|
||||
"atom-beautify:beautify-language-gherkin",
|
||||
"atom-beautify:beautify-language-glsl",
|
||||
"atom-beautify:beautify-language-go",
|
||||
"atom-beautify:beautify-language-golang template",
|
||||
"atom-beautify:beautify-language-fortran",
|
||||
"atom-beautify:beautify-language-handlebars",
|
||||
"atom-beautify:beautify-language-haskell",
|
||||
"atom-beautify:beautify-language-html",
|
||||
"atom-beautify:beautify-language-jade",
|
||||
"atom-beautify:beautify-language-java",
|
||||
"atom-beautify:beautify-language-javascript",
|
||||
"atom-beautify:beautify-language-json",
|
||||
"atom-beautify:beautify-language-jsx",
|
||||
"atom-beautify:beautify-language-latex",
|
||||
"atom-beautify:beautify-language-less",
|
||||
"atom-beautify:beautify-language-lua",
|
||||
"atom-beautify:beautify-language-markdown",
|
||||
"atom-beautify:beautify-language-marko",
|
||||
"atom-beautify:beautify-language-mustache",
|
||||
"atom-beautify:beautify-language-nginx",
|
||||
"atom-beautify:beautify-language-nunjucks",
|
||||
"atom-beautify:beautify-language-objective-c",
|
||||
"atom-beautify:beautify-language-ocaml",
|
||||
"atom-beautify:beautify-language-pawn",
|
||||
"atom-beautify:beautify-language-perl",
|
||||
"atom-beautify:beautify-language-php",
|
||||
"atom-beautify:beautify-language-puppet",
|
||||
"atom-beautify:beautify-language-python",
|
||||
"atom-beautify:beautify-language-r",
|
||||
"atom-beautify:beautify-language-riot.js",
|
||||
"atom-beautify:beautify-language-ruby",
|
||||
"atom-beautify:beautify-language-rust",
|
||||
"atom-beautify:beautify-language-sass",
|
||||
"atom-beautify:beautify-language-scss",
|
||||
"atom-beautify:beautify-language-spacebars",
|
||||
"atom-beautify:beautify-language-sql",
|
||||
"atom-beautify:beautify-language-svg",
|
||||
"atom-beautify:beautify-language-swig",
|
||||
"atom-beautify:beautify-language-tss",
|
||||
"atom-beautify:beautify-language-twig",
|
||||
"atom-beautify:beautify-language-typescript",
|
||||
"atom-beautify:beautify-language-ux markup",
|
||||
"atom-beautify:beautify-language-vala",
|
||||
"atom-beautify:beautify-language-vue",
|
||||
"atom-beautify:beautify-language-visualforce",
|
||||
"atom-beautify:beautify-language-xml",
|
||||
"atom-beautify:beautify-language-xtemplate",
|
||||
"atom-beautify:beautify-language-yaml"
|
||||
],
|
||||
".tree-view .file .name": [
|
||||
"atom-beautify:beautify-file"
|
||||
|
|
|
@ -274,14 +274,14 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
logger.error(error)
|
||||
|
||||
|
||||
beautify : (text, allOptions, grammar, filePath, {onSave} = {}) ->
|
||||
beautify : (text, allOptions, grammar, filePath, {onSave, language} = {}) ->
|
||||
return Promise.all(allOptions)
|
||||
.then((allOptions) =>
|
||||
return new Promise((resolve, reject) =>
|
||||
logger.info('beautify', text, allOptions, grammar, filePath, onSave)
|
||||
logger.info('beautify', text, allOptions, grammar, filePath, onSave, language)
|
||||
logger.verbose(allOptions)
|
||||
|
||||
language = @getLanguage(grammar, filePath)
|
||||
language ?= @getLanguage(grammar, filePath)
|
||||
|
||||
# Check if unsupported language
|
||||
if !language
|
||||
|
|
|
@ -73,7 +73,7 @@ showError = (error) ->
|
|||
atom.notifications?.addError(error.message, {
|
||||
stack, detail, dismissable : true})
|
||||
|
||||
beautify = ({editor, onSave}) ->
|
||||
beautify = ({ editor, onSave, language }) ->
|
||||
return new Promise((resolve, reject) ->
|
||||
|
||||
plugin.checkUnsupportedOptions()
|
||||
|
@ -177,7 +177,7 @@ beautify = ({editor, onSave}) ->
|
|||
|
||||
# Finally, beautify!
|
||||
try
|
||||
beautifier.beautify(text, allOptions, grammarName, editedFilePath, onSave : onSave)
|
||||
beautifier.beautify(text, allOptions, grammarName, editedFilePath, onSave: onSave, language: language)
|
||||
.then(beautifyCompleted)
|
||||
.catch(beautifyCompleted)
|
||||
catch e
|
||||
|
@ -604,6 +604,17 @@ plugin.migrateSettings = ->
|
|||
)
|
||||
atom.notifications.addSuccess("Successfully migrated options: #{unsupportedOptions.join(', ')}")
|
||||
|
||||
plugin.addLanguageCommands = ->
|
||||
languages = beautifier.languages.languages
|
||||
logger.verbose("languages", languages)
|
||||
for language in languages
|
||||
((language) =>
|
||||
@subscriptions.add atom.commands.add("atom-workspace", "atom-beautify:beautify-language-#{language.name.toLowerCase()}", () ->
|
||||
logger.verbose("Beautifying language", language)
|
||||
beautify({ language })
|
||||
)
|
||||
)(language)
|
||||
|
||||
plugin.config = _.merge(require('./config.coffee'), defaultLanguageOptions)
|
||||
plugin.activate = ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
|
@ -613,6 +624,7 @@ plugin.activate = ->
|
|||
@subscriptions.add atom.commands.add ".tree-view .file .name", "atom-beautify:beautify-file", beautifyFile
|
||||
@subscriptions.add atom.commands.add ".tree-view .directory .name", "atom-beautify:beautify-directory", beautifyDirectory
|
||||
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:migrate-settings", plugin.migrateSettings
|
||||
@addLanguageCommands()
|
||||
|
||||
plugin.deactivate = ->
|
||||
@subscriptions.dispose()
|
||||
|
|
Loading…
Reference in New Issue