diff --git a/examples/nested-jsbeautifyrc/vue/expected/test.vue b/examples/nested-jsbeautifyrc/vue/expected/test.vue new file mode 100644 index 0000000..02613e9 --- /dev/null +++ b/examples/nested-jsbeautifyrc/vue/expected/test.vue @@ -0,0 +1,46 @@ + + + + + + + diff --git a/examples/nested-jsbeautifyrc/vue/original/test.vue b/examples/nested-jsbeautifyrc/vue/original/test.vue new file mode 100644 index 0000000..ebe0be6 --- /dev/null +++ b/examples/nested-jsbeautifyrc/vue/original/test.vue @@ -0,0 +1,45 @@ + + + + + + + diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 0d29b66..94715dc 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -66,6 +66,7 @@ module.exports = class Beautifiers extends EventEmitter 'stylish-haskell' 'tidy-markdown' 'typescript-formatter' + 'vue-beautifier' 'yapf' 'erl_tidy' 'marko-beautifier' diff --git a/src/beautifiers/vue-beautifier.coffee b/src/beautifiers/vue-beautifier.coffee new file mode 100644 index 0000000..bdfc661 --- /dev/null +++ b/src/beautifiers/vue-beautifier.coffee @@ -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 + )) + ) diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 027488b..36c17eb 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -64,6 +64,7 @@ module.exports = class Languages "twig" "typescript" "vala" + "vue" "visualforce" "xml" "xtemplate" diff --git a/src/languages/vue.coffee b/src/languages/vue.coffee new file mode 100644 index 0000000..bc1137e --- /dev/null +++ b/src/languages/vue.coffee @@ -0,0 +1,23 @@ +module.exports = { + + name: "Vue" + namespace: "vue" + fallback: ['html'] + + ### + Supported Grammars + ### + grammars: [ + "Vue Component" + ] + + ### + Supported extensions + ### + extensions: [ + "vue" + ] + + defaultBeautifier: "Vue Beautifier" + +}