From 0df1d8a5df8dafaf65b5aaa1af6bec2991b52221 Mon Sep 17 00:00:00 2001 From: Mark Tofan Date: Thu, 7 Apr 2016 00:00:20 +0300 Subject: [PATCH] Added support for Crystal language --- .../crystal/expected/test.cr | 49 +++++++++++++++++++ .../crystal/original/test.cr | 49 +++++++++++++++++++ src/beautifiers/crystal.coffee | 23 +++++++++ src/beautifiers/index.coffee | 1 + src/languages/crystal.coffee | 22 +++++++++ src/languages/index.coffee | 1 + 6 files changed, 145 insertions(+) create mode 100644 examples/nested-jsbeautifyrc/crystal/expected/test.cr create mode 100644 examples/nested-jsbeautifyrc/crystal/original/test.cr create mode 100644 src/beautifiers/crystal.coffee create mode 100644 src/languages/crystal.coffee diff --git a/examples/nested-jsbeautifyrc/crystal/expected/test.cr b/examples/nested-jsbeautifyrc/crystal/expected/test.cr new file mode 100644 index 0000000..f6d421c --- /dev/null +++ b/examples/nested-jsbeautifyrc/crystal/expected/test.cr @@ -0,0 +1,49 @@ +# A unicorn is a **legendary animal** (see the `Legendary` module) that has been +# described since antiquity as a beast with a large, spiraling horn projecting +# from its forhead. +# +# To create a unicorn: +# +# ``` +# unicorn = Unicorn.new +# unicorn.speak +# ``` +# +# The above produces: +# +# ```text +# "I'm a unicorn" +# ``` +# +# Check the number of horns with `#horns`. +class Unicorn + include Legendary + + # Creates a unicorn with the specified number of *horns*. + def initialize(@horns = 1) + raise "Not a unicorn" if @horns != 1 + end + + # Returns the number of horns this unicorn has + # + # ``` + # Unicorn.new.horns # => 1 + # ``` + def horns + @horns + end + + # ditto + def number_of_horns + horns + end + + # Makes the unicorn speak to STDOUT + def speak + puts "I'm a unicorn" + end + + # :nodoc: + class Helper + end +end diff --git a/examples/nested-jsbeautifyrc/crystal/original/test.cr b/examples/nested-jsbeautifyrc/crystal/original/test.cr new file mode 100644 index 0000000..e4605d6 --- /dev/null +++ b/examples/nested-jsbeautifyrc/crystal/original/test.cr @@ -0,0 +1,49 @@ +# A unicorn is a **legendary animal** (see the `Legendary` module) that has been + # described since antiquity as a beast with a large, spiraling horn projecting + # from its forhead. +# +# To create a unicorn: +# + # ``` + # unicorn = Unicorn.new + # unicorn.speak + # ``` +# +# The above produces: +# + # ```text + # "I'm a unicorn" +# ``` + # +# Check the number of horns with `#horns`. +class Unicorn + include Legendary + + # Creates a unicorn with the specified number of *horns*. +def initialize(@horns = 1) +raise "Not a unicorn" if @horns != 1 +end + + # Returns the number of horns this unicorn has + # + # ``` + # Unicorn.new.horns # => 1 + # ``` + def horns + @horns + end + + # ditto + def number_of_horns + horns + end + +# Makes the unicorn speak to STDOUT + def speak +puts "I'm a unicorn" + end + + # :nodoc: + class Helper + end +end diff --git a/src/beautifiers/crystal.coffee b/src/beautifiers/crystal.coffee new file mode 100644 index 0000000..0962fbc --- /dev/null +++ b/src/beautifiers/crystal.coffee @@ -0,0 +1,23 @@ +### +Requires https://github.com/jaspervdj/stylish-haskell +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class Crystal extends Beautifier + name: "crystal" + + options: { + Crystal: false + } + + beautify: (text, language, options) -> + @run("crystal", [ + 'tool' + 'format' + tempFile = @tempFile("temp", text) + ], {ignoreReturnCode: true}) + .then(=> + @readFile(tempFile) + ) diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index c88f4b5..138c8d1 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -38,6 +38,7 @@ module.exports = class Beautifiers extends EventEmitter 'coffee-formatter' 'coffee-fmt' 'clang-format' + 'crystal' 'dfmt' 'elm-format' 'htmlbeautifier' diff --git a/src/languages/crystal.coffee b/src/languages/crystal.coffee new file mode 100644 index 0000000..61fbe28 --- /dev/null +++ b/src/languages/crystal.coffee @@ -0,0 +1,22 @@ +module.exports = { + + name: "Crystal" + namespace: "crystal" + + ### + Supported Grammars + ### + grammars: [ + "Crystal" + ] + + ### + Supported extensions + ### + extensions: [ + "cr" + ] + + options: [] + +} diff --git a/src/languages/index.coffee b/src/languages/index.coffee index b6980eb..59269c4 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -19,6 +19,7 @@ module.exports = class Languages "coffeescript" "coldfusion" "cpp" + "crystal" "css" "csv" "d"