Improved Marko v3 support
This commit is contained in:
parent
9197bc3a3c
commit
af9cc40dec
|
@ -31,7 +31,6 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify`
|
|||
- [x] XML
|
||||
- [x] SVG
|
||||
- [x] [Marko](https://github.com/marko-js/marko)
|
||||
- Requires [language-marko](https://github.com/marko-js/atom-language-marko)
|
||||
- [x] CSS, including
|
||||
- [Sass](http://sass-lang.com/)
|
||||
- [Less](http://lesscss.org/)
|
||||
|
|
|
@ -26,7 +26,12 @@ Now your Language is available and can be detected and beautifiers can support i
|
|||
- Prettydiff is a good example of complex options: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/prettydiff.coffee
|
||||
- PHP-CS-Fixer is a good example of a CLI beautifier with arguments: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/php-cs-fixer.coffee#L15-L39
|
||||
- `options` - the key represents the Language's name. The value could be `true` (supports all options), `false` (supports language, with no options), or an `object` whose keys are option keys and values are complex mappings. If you need to use these, let me know. `true` is probably what you want.
|
||||
- The `beautify` function should return a `Promise` (use `@Promise` as shown). The arguments passed are: `text`, the source code from Atom's Text Editor, `language` is a string of the language's name (`JavaScript`), and `options` is an object of all of the options in their form as described by your Language definition (see `Configure the new language` above).
|
||||
- The `beautify` function should return a `Promise` (use `@Promise` as shown). The arguments passed are:
|
||||
- __`text`__ - the source code from Atom's Text Editor
|
||||
- __`language`__ - the language's name (`JavaScript`)
|
||||
- __`options`__ - an object of all of the options in their form as described by your Language definition (see `Configure the new language` above).
|
||||
- __`context`__ - an object with extra information:
|
||||
- __`filePath`__ - The file path associated with the text being beautified (may be null)
|
||||
3. Add beautifier to list of `beautifierNames`: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/index.coffee#L34
|
||||
4. Add test example files in https://github.com/Glavin001/atom-beautify/tree/master/examples
|
||||
- You can put your test in `nested-jsbeautifyrc` directory, https://github.com/Glavin001/atom-beautify/tree/master/examples/nested-jsbeautifyrc
|
||||
|
|
|
@ -108,6 +108,7 @@
|
|||
"jscs": "^3.0.3",
|
||||
"lodash": "^4.8.2",
|
||||
"loophole": "^1.0.0",
|
||||
"marko-prettyprint": "^1.1.0",
|
||||
"node-dir": "^0.1.8",
|
||||
"node-uuid": "^1.4.3",
|
||||
"prettydiff": "^1.16.27",
|
||||
|
|
|
@ -66,6 +66,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
'typescript-formatter'
|
||||
'yapf'
|
||||
'erl_tidy'
|
||||
'marko-beautifier'
|
||||
]
|
||||
|
||||
###
|
||||
|
@ -276,7 +277,11 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
|
||||
# Beautify text with language options
|
||||
@emit "beautify::start"
|
||||
beautifier.beautify(text, language.name, options)
|
||||
|
||||
context =
|
||||
filePath: filePath
|
||||
|
||||
beautifier.beautify(text, language.name, options, context)
|
||||
.then(resolve)
|
||||
.catch(reject)
|
||||
.finally(=>
|
||||
|
|
|
@ -9,7 +9,6 @@ module.exports = class JSBeautify extends Beautifier
|
|||
XML: true
|
||||
Handlebars: true
|
||||
Mustache: true
|
||||
Marko: true
|
||||
JavaScript: true
|
||||
JSON: true
|
||||
CSS:
|
||||
|
@ -41,7 +40,7 @@ module.exports = class JSBeautify extends Beautifier
|
|||
beautifyHTML = require("js-beautify").html
|
||||
text = beautifyHTML(text, options)
|
||||
resolve text
|
||||
when "HTML (Liquid)", "HTML", "XML", "Marko", "Web Form/Control (C#)", "Web Handler (C#)"
|
||||
when "HTML (Liquid)", "HTML", "XML", "Web Form/Control (C#)", "Web Handler (C#)"
|
||||
beautifyHTML = require("js-beautify").html
|
||||
text = beautifyHTML(text, options)
|
||||
@debug("Beautified HTML: #{text}")
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
"use strict"
|
||||
Beautifier = require('./beautifier')
|
||||
|
||||
module.exports = class MarkoBeautifier extends Beautifier
|
||||
name: 'Marko Beautifier'
|
||||
|
||||
options:
|
||||
Marko: true
|
||||
|
||||
beautify: (text, language, options, context) ->
|
||||
|
||||
return new @Promise((resolve, reject) ->
|
||||
markoPrettyprint = require('marko-prettyprint')
|
||||
|
||||
indent_char = options.indent_char || ' '
|
||||
indent_size = options.indent_size || 4
|
||||
|
||||
indent = ''
|
||||
|
||||
for i in [0...indent_size - 1] by 1
|
||||
indent += indent_char
|
||||
|
||||
prettyprintOptions =
|
||||
syntax : options.syntax
|
||||
filename: if context.filePath then context.filePath else require.resolve('marko-prettyprint')
|
||||
|
||||
try
|
||||
resolve(markoPrettyprint(text, prettyprintOptions))
|
||||
catch error
|
||||
# Error occurred
|
||||
reject(error)
|
||||
)
|
|
@ -1,8 +1,15 @@
|
|||
# Get Atom defaults
|
||||
scope = ['text.marko']
|
||||
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
|
||||
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
|
||||
defaultIndentSize = (if softTabs then tabLength else 4)
|
||||
defaultIndentChar = (if softTabs then " " else "\t")
|
||||
defaultIndentWithTabs = not softTabs
|
||||
|
||||
module.exports = {
|
||||
|
||||
name: "Marko"
|
||||
namespace: "marko"
|
||||
fallback: ['html']
|
||||
|
||||
###
|
||||
Supported Grammars
|
||||
|
@ -18,6 +25,22 @@ module.exports = {
|
|||
"marko"
|
||||
]
|
||||
|
||||
options: []
|
||||
options:
|
||||
indent_size:
|
||||
type: 'integer'
|
||||
default: defaultIndentSize
|
||||
minimum: 0
|
||||
description: "Indentation size/length"
|
||||
indent_char:
|
||||
type: 'string'
|
||||
default: defaultIndentChar
|
||||
description: "Indentation character"
|
||||
syntax:
|
||||
type: 'string'
|
||||
default: "html"
|
||||
enum: ["html", "concise"]
|
||||
description: "[html|concise]"
|
||||
|
||||
defaultBeautifier: "Marko Beautifier"
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue