diff --git a/.travis.yml b/.travis.yml index 5c233be..0f28ae6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,5 @@ before_install: - brew install ocaml opam - opam init --auto-setup - opam install --yes ocp-indent - \ No newline at end of file + # Crystal + - brew install crystal-lang diff --git a/README.md b/README.md index df4b4ff..f75b919 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify` - Requires [Elm-Format](https://github.com/avh4/elm-format) - [x] [Erlang](https://github.com/Glavin001/atom-beautify/pull/683) - Requires erlang syntax_tools to be installed +- [x] [Crystal](https://github.com/Glavin001/atom-beautify/pull/900) ## Usage diff --git a/docs/options.md b/docs/options.md index 569d12b..28e353b 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1179,6 +1179,69 @@ Path to uncrustify config file. i.e. uncrustify.cfg (Supported by Uncrustify) } ``` +#### [Crystal](#crystal) + +**Supported Beautifiers**: [`crystal`](#crystal) + +**Description**: + +Options for language Crystal + +##### [Disable Beautifying Language](#disable-beautifying-language) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Disable Crystal Beautification + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Disable Beautifying Language*" and change it to your desired configuration. + +##### [Default Beautifier](#default-beautifier) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Default**: `crystal` + +**Type**: `string` + +**Enum**: `crystal` + +**Description**: + +Default Beautifier to be used for Crystal + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Default Beautifier*" and change it to your desired configuration. + +##### [Beautify On Save](#beautify-on-save) + +**Important**: This option is only configurable from within Atom Beautify's setting panel. + +**Type**: `boolean` + +**Description**: + +Automatically beautify Crystal files on save + +**How to Configure** + +1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to +*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*. +2. Go into *Packages* and search for "*Atom Beautify*" package. +3. Find the option "*Beautify On Save*" and change it to your desired configuration. + #### [C#](#c-) **Supported Beautifiers**: [`Uncrustify`](#uncrustify) 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..b05ff14 --- /dev/null +++ b/src/beautifiers/crystal.coffee @@ -0,0 +1,33 @@ +### +Requires https://github.com/jaspervdj/stylish-haskell +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class Crystal extends Beautifier + name: "crystal" + + options: { + Crystal: true + } + + beautify: (text, language, options) -> + # Seems that Crystal dosen't have Windows support yet. + if @isWindows + @Promise.reject(@commandNotFoundError( + 'crystal' + { + link: "http://crystal-lang.org" + program: "crystal" + }) + ) + else + @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 81f1289..3c15caf 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 afd2dad..4861a1c 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"