Merge pull request #956 from patrick-steele-idem/marko-v3

Marko v3
This commit is contained in:
Glavin Wiechert 2016-06-07 10:54:14 -03:00
commit aae09ea463
11 changed files with 89 additions and 29 deletions

View File

@ -31,7 +31,6 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify`
- [x] XML - [x] XML
- [x] SVG - [x] SVG
- [x] [Marko](https://github.com/marko-js/marko) - [x] [Marko](https://github.com/marko-js/marko)
- Requires [language-marko](https://github.com/marko-js/atom-language-marko)
- [x] CSS, including - [x] CSS, including
- [Sass](http://sass-lang.com/) - [Sass](http://sass-lang.com/)
- [Less](http://lesscss.org/) - [Less](http://lesscss.org/)

View File

@ -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 - 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 - 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. - `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 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 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 - You can put your test in `nested-jsbeautifyrc` directory, https://github.com/Glavin001/atom-beautify/tree/master/examples/nested-jsbeautifyrc

View File

@ -1,8 +1,6 @@
<if test="data.items"> <if(data.items)>
<for each="item in data.items"> <for(item in data.items)>
<div>${item.name}</div> <div>${item.name}</div>
</for> </for>
</if> </if>
<else> <else>content</else>
content
</else>

View File

@ -1,8 +1,6 @@
<if test="data.items"> <if(data.items)>
<for each="item in data.items"> <for(item in data.items)>
<div>${item.name}</div> <div>${item.name}</div>
</for> </for>
</if> </if>
<else> <else>content</else>
content
</else>

View File

@ -1,6 +1,2 @@
<if test="${data.items}"> <if(data.items)>content</if>
content <else>content</else>
</if>
<else>
content
</else>

View File

@ -1,6 +1,4 @@
<if test="${data.items}"> if(data.items)
content - content
</if> else
<else> - content
content
</else>

View File

@ -82,6 +82,10 @@
{ {
"name": "Frederic Delbos", "name": "Frederic Delbos",
"url": "https://github.com/fdelbos" "url": "https://github.com/fdelbos"
},
{
"name": "Patrick Steele-Idem",
"url": "https://github.com/psteeleidem"
} }
], ],
"engines": { "engines": {
@ -108,6 +112,7 @@
"jscs": "^3.0.3", "jscs": "^3.0.3",
"lodash": "^4.8.2", "lodash": "^4.8.2",
"loophole": "^1.0.0", "loophole": "^1.0.0",
"marko-prettyprint": "^1.1.0",
"node-dir": "^0.1.8", "node-dir": "^0.1.8",
"node-uuid": "^1.4.3", "node-uuid": "^1.4.3",
"prettydiff": "^1.16.27", "prettydiff": "^1.16.27",

View File

@ -66,6 +66,7 @@ module.exports = class Beautifiers extends EventEmitter
'typescript-formatter' 'typescript-formatter'
'yapf' 'yapf'
'erl_tidy' 'erl_tidy'
'marko-beautifier'
] ]
### ###
@ -276,7 +277,11 @@ module.exports = class Beautifiers extends EventEmitter
# Beautify text with language options # Beautify text with language options
@emit "beautify::start" @emit "beautify::start"
beautifier.beautify(text, language.name, options)
context =
filePath: filePath
beautifier.beautify(text, language.name, options, context)
.then(resolve) .then(resolve)
.catch(reject) .catch(reject)
.finally(=> .finally(=>

View File

@ -9,7 +9,6 @@ module.exports = class JSBeautify extends Beautifier
XML: true XML: true
Handlebars: true Handlebars: true
Mustache: true Mustache: true
Marko: true
JavaScript: true JavaScript: true
JSON: true JSON: true
CSS: CSS:
@ -41,7 +40,7 @@ module.exports = class JSBeautify extends Beautifier
beautifyHTML = require("js-beautify").html beautifyHTML = require("js-beautify").html
text = beautifyHTML(text, options) text = beautifyHTML(text, options)
resolve text 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 beautifyHTML = require("js-beautify").html
text = beautifyHTML(text, options) text = beautifyHTML(text, options)
@debug("Beautified HTML: #{text}") @debug("Beautified HTML: #{text}")

View File

@ -0,0 +1,33 @@
"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]
indent += indent_char
prettyprintOptions =
syntax : options.syntax
filename: if context.filePath then context.filePath else require.resolve('marko-prettyprint')
indent: indent
try
resolve(markoPrettyprint(text, prettyprintOptions))
catch error
# Error occurred
reject(error)
)

View File

@ -1,3 +1,11 @@
# 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 = { module.exports = {
name: "Marko" name: "Marko"
@ -18,6 +26,22 @@ module.exports = {
"marko" "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"
} }