Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Elm #700

Merged
merged 9 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ before_install:
- brew install haskell-stack
- stack setup
- stack install stylish-haskell
# Elm
- curl -L -o /tmp/elm-format.tgz https://github.com/avh4/elm-format/releases/download/0.1-alpha2/elm-format-0.1-alpha2-mac-x64.tgz
- tar xvzf /tmp/elm-format.tgz -C /usr/local/bin
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dev
- Add [elm-format](https://github.com/avh4/elm-format) beautifier for the Elm language.
- Add [clang-format](http://clang.llvm.org/docs/ClangFormat.html) beautifier for C/C++/Obj-C languages.
- Add [yapf](http://github.com/google/yapf) beautifier for Python.

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify`
- [x] [TypeScript](https://github.com/Glavin001/atom-beautify/issues/49)
- [x] [Haskell](https://github.com/Glavin001/atom-beautify/issues/628)
- Requires [stylish-haskell](https://github.com/jaspervdj/stylish-haskell)
- [x] [Elm](https://github.com/Glavin001/atom-beautify/pull/700)
- Requires [Elm-Format](https://github.com/avh4/elm-format)

## Usage

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ build_script:

- cd %APPVEYOR_BUILD_FOLDER%
# Install languages to Atom
- apm install language-marko language-html-swig language-svg
- apm install language-marko language-html-swig language-svg language-elm
# Show current PATH
- echo %PATH%
# Run tests on package
Expand Down
55 changes: 55 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,61 @@ Automatically beautify EJS files on save
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Language Config - EJS - Beautify On Save*" and change it to your desired configuration.

#### [Language Config - Elm - Disable Beautifying Language](#language-config---elm---disable-beautifying-language)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Disable Elm 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 "*Language Config - Elm - Disable Beautifying Language*" and change it to your desired configuration.

#### [Language Config - Elm - Default Beautifier](#language-config---elm---default-beautifier)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Default**: `elm-format`

**Type**: `string`

**Enum**: `elm-format`

**Description**:

Default Beautifier to be used for Elm

**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 "*Language Config - Elm - Default Beautifier*" and change it to your desired configuration.

#### [Language Config - Elm - Beautify On Save](#language-config---elm---beautify-on-save)

**Important**: This option is only configurable from within Atom Beautify's setting panel.

**Type**: `boolean`

**Description**:

Automatically beautify Elm 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 "*Language Config - Elm - Beautify On Save*" and change it to your desired configuration.

#### [Language Config - ERB - Disable Beautifying Language](#language-config---erb---disable-beautifying-language)

**Important**: This option is only configurable from within Atom Beautify's setting panel.
Expand Down
9 changes: 9 additions & 0 deletions examples/nested-jsbeautifyrc/elm/expected/test.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Main (..) where


addThings x y =
x + y


main =
addThings 4 5
3 changes: 3 additions & 0 deletions examples/nested-jsbeautifyrc/elm/original/test.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addThings x y = x + y

main = addThings 4 5
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
{
"name": "Daniel Bayley",
"url": "https://github.com/danielbayley"
},
{
"name": "Murphy Randle",
"url": "https://github.com/splodingsocks"
}
],
"engines": {
Expand Down Expand Up @@ -156,7 +160,8 @@
"marko",
"go",
"golang",
"svg"
"svg",
"elm"
],
"devDependencies": {
"coffee-script": "^1.9.3",
Expand Down
4 changes: 2 additions & 2 deletions src/beautifiers/beautifier.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ module.exports = class Beautifier
###
Create temporary file
###
tempFile: (name = "atom-beautify-temp", contents = "") ->
tempFile: (name = "atom-beautify-temp", contents = "", ext = "") ->
return new Promise((resolve, reject) =>
# create temp file
temp.open(name, (err, info) =>
temp.open({prefix: name, suffix: ext}, (err, info) =>
@debug('tempFile', name, err, info)
return reject(err) if err
fs.write(info.fd, contents, (err) ->
Expand Down
24 changes: 24 additions & 0 deletions src/beautifiers/elm-format.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
###
Requires https://github.com/avh4/elm-format
###
"use strict"
Beautifier = require('./beautifier')

module.exports = class ElmFormat extends Beautifier
name: "elm-format"

options: {
Elm: true
}

beautify: (text, language, options) ->
tempfile = @tempFile("input", text, ".elm")
.then (name) =>
@run("elm-format", [
'--yes',
name
],
{ help: { link: 'https://github.com/avh4/elm-format' } }
)
.then () =>
@readFile(name)
1 change: 1 addition & 0 deletions src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = class Beautifiers extends EventEmitter
'coffee-formatter'
'coffee-fmt'
'clang-format'
'elm-format'
'htmlbeautifier'
'csscomb'
'gherkin'
Expand Down
22 changes: 22 additions & 0 deletions src/languages/elm.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {

name: "Elm"
namespace: "elm"

###
Supported Grammars
###
grammars: [
"Elm"
]

###
Supported extensions
###
extensions: [
"elm"
]

options: []

}
1 change: 1 addition & 0 deletions src/languages/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = class Languages
"csv"
"d"
"ejs"
"elm"
"erb"
"gherkin"
"go"
Expand Down