Skip to content

Commit

Permalink
Closes #31. Add CoffeeScript support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Aug 4, 2014
1 parent 6594a96 commit 3c9836f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ Atom Package: https://atom.io/packages/atom-beautify
- Beautifies to [PEP 8](http://legacy.python.org/dev/peps/pep-0008/).
- [x] [Ruby](https://github.com/donaldpipowitch/atom-beautify/issues/25)
- Requires [RBeautify](https://github.com/erniebrodeur/ruby-beautify)
- [x] [CoffeeScript](https://github.com/donaldpipowitch/atom-beautify/issues/31)

### Coming Soon

- [ ] CoffeeScript, see https://github.com/donaldpipowitch/atom-beautify/issues/31
### Road Map

- [ ] [TypeScript support](https://github.com/Glavin001/atom-beautify/issues/49)
- [ ] [Java support](https://github.com/Glavin001/atom-beautify/issues/45)
- [ ] [Perl support](https://github.com/Glavin001/atom-beautify/issues/33)

## Usage

Expand Down
10 changes: 10 additions & 0 deletions examples/simple-jsbeautifyrc/test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
hello derek how is it going?
for c, i in "Hello World!"
k = 1+1- 2>=3<= 4>5 <6

for c, i in "Hello World"
k = (a,b)-> if b? return a

f = b()[0]
for c, i in "Hello World"
f(b())
17 changes: 17 additions & 0 deletions lib/langs/coffeescript-beautify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var CF = require('coffee-formatter');
module.exports = function (text, options, callback) {
var lines = text.split('\n');
var resultArr = [];
for (var i = 0, len = lines.length; i < len; i++) {
var curr = lines[i];
var p = CF.formatTwoSpaceOperator(curr);
p = CF.formatOneSpaceOperator(p);
p = CF.shortenSpaces(p);
resultArr.push(p);
}
var result = resultArr.join('\n');
callback(result);
return result;
};
7 changes: 6 additions & 1 deletion lib/language-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ var beautifyPHP = require('./langs/php-beautify');
var beautifyPython = require('./langs/python-beautify');
var beautifyRuby = require('./langs/ruby-beautify');
var beautifyLESS = require('./langs/less-beautify');
var beautifyCoffeeScript = require('./langs/coffeescript-beautify');
// Misc
var Analytics = require('analytics-node');
var pkg = require('../package.json');

module.exports = {

// Supported unique configuration keys
// Used for detecting nested configurations in .jsbeautifyrc
languages: ['js', 'html', 'css', 'sql', 'php', 'python', 'ruby'],
languages: ['js', 'html', 'css', 'sql', 'php', 'python', 'ruby','coffeescript'],

// Default options per language
defaultLanguageOptions: {
Expand Down Expand Up @@ -81,6 +83,9 @@ module.exports = {
text = beautifyJS(text, self.getOptions('js', allOptions));
beautifyCompleted(text);
break;
case 'CoffeeScript':
beautifyCoffeeScript(text, self.getOptions('js', allOptions), beautifyCompleted);
break;
case 'Handlebars':
// jshint ignore: start
allOptions.push({
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"sql",
"php",
"python",
"ruby"
"ruby",
"coffeescript"
],
"engines": {
"atom": ">0.50.0"
Expand All @@ -75,7 +76,8 @@
"temp": "^0.8.0",
"prettydiff": "^1.0.23",
"node-uuid": "^1.4.1",
"analytics-node": "^1.0.2"
"analytics-node": "^1.0.2",
"coffee-formatter": "git+https://github.com/Glavin001/Coffee-Formatter.git"
},
"activationEvents": [
"beautify"
Expand Down

0 comments on commit 3c9836f

Please sign in to comment.