Implement Vue Beautifier

This commit is contained in:
Aidi Stan 2016-08-16 01:33:06 +08:00
parent 06773e35df
commit 7ebc41be64
6 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<template>
<base-view>
<div slot="page-body" class="row">
Your content here!
</div>
</base-view>
</template>
<script>
export default {
data: function() {
return {
text: 'Hello, world!'
}
}
}
</script>
<style lang="sass">
nav {
ul {
margin:0 padding: 0;
}
li {
display: inline-block;
}
a {
display: block;
}
}
</style>
<style lang="scss">
nav {
ul {
margin: 0;
padding: 0;
}
li {
display: inline-block;
}
a {
display: block;
}
}
</style>

View File

@ -0,0 +1,45 @@
<template>
<base-view>
<div slot="page-body" class="row">
Your content here!
</div>
</base-view>
</template>
<script>
export default {
data: function() {
return {
text: 'Hello, world!'
}
}
}
</script>
<style lang="sass">
nav {
ul {
margin: 0
padding: 0
}
li {
display: inline-block
}
a {
display: block
}
}
</style>
<style lang="scss">
nav {
ul {
margin: 0;
padding: 0;
}
li { display: inline-block; }
a {
display: block;
}
}
</style>

View File

@ -66,6 +66,7 @@ module.exports = class Beautifiers extends EventEmitter
'stylish-haskell' 'stylish-haskell'
'tidy-markdown' 'tidy-markdown'
'typescript-formatter' 'typescript-formatter'
'vue-beautifier'
'yapf' 'yapf'
'erl_tidy' 'erl_tidy'
'marko-beautifier' 'marko-beautifier'

View File

@ -0,0 +1,49 @@
"use strict"
Beautifier = require('./beautifier')
prettydiff = require("prettydiff")
_ = require('lodash')
module.exports = class VueBeautifier extends Beautifier
name: "Vue Beautifier"
options:
Vue: true
beautify: (text, language, options) ->
return new @Promise((resolve, reject) ->
regexp = /(<(template|script|style)[^>]*>)((\s|\S)*?)<\/\2>/gi
resolve(text.replace(regexp, (match, begin, type, text) ->
lang = /lang\s*=\s*['"](\w+)["']/.exec(begin)?[1]
switch type
when "template"
switch lang
when "pug", "jade"
match.replace(text, "\n" + require("pug-beautify")(text, options) + "\n")
when undefined
match.replace(text, "\n" + require("js-beautify").html(text, options) + "\n")
else
match
when "script"
match.replace(text, "\n" + require("js-beautify")(text, options) + "\n")
when "style"
switch lang
when "sass", "scss"
options = _.merge options,
source: text
lang: "scss"
mode: "beautify"
match.replace(text, prettydiff.api(options)[0])
when "less"
options = _.merge options,
source: text
lang: "less"
mode: "beautify"
match.replace(text, prettydiff.api(options)[0])
when undefined
match.replace(text, "\n" + require("js-beautify").css(text, options) + "\n")
else
match
))
)

View File

@ -64,6 +64,7 @@ module.exports = class Languages
"twig" "twig"
"typescript" "typescript"
"vala" "vala"
"vue"
"visualforce" "visualforce"
"xml" "xml"
"xtemplate" "xtemplate"

23
src/languages/vue.coffee Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
name: "Vue"
namespace: "vue"
fallback: ['html']
###
Supported Grammars
###
grammars: [
"Vue Component"
]
###
Supported extensions
###
extensions: [
"vue"
]
defaultBeautifier: "Vue Beautifier"
}