Skip to content

Commit

Permalink
Closes #13. Add Handlebars support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Jun 13, 2014
1 parent 58a375f commit b530eda
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# [atom-beautify](https://github.com/donaldpipowitch/atom-beautify)

[Beautify](https://github.com/einars/js-beautify) HTML, CSS and JavaScript in Atom.
[Beautify](https://github.com/einars/js-beautify) HTML (including Handlebars), CSS and JavaScript in Atom.

*Attention*: A different package with a similar name exist. Maybe you want to visit this one: [Beautifier](https://atom.io/packages/atom-beautifier).

## Usage

Open the [Command Palette](https://github.com/atom/command-palette), and type `Beautify`.
This will beautify JS, HTML or CSS files.
This will beautify JS, HTML (including Handlebars), or CSS files.
XML is supported as an experimental feature.

It will only beautify selected text, if a selection is found - if not, the whole file will be beautified.
Expand All @@ -32,6 +32,8 @@ Edit your `.jsbeautifyrc` file in any of the following locations:

You can see examples of both way inside [`examples/`](https://github.com/donaldpipowitch/atom-beautify/tree/master/examples)

*Comments are supported in `.jsbeautifyrc` thanks to [strip-json-comments](https://github.com/sindresorhus/strip-json-comments).*

## Contributing

[See all contributors on GitHub](https://github.com/donaldpipowitch/atom-beautify/graphs/contributors).
Expand Down
4 changes: 3 additions & 1 deletion examples/simple-jsbeautifyrc/.jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"indent_size": 2,
"indent_char": " ",
"other": " ",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": true
"jslint_happy": true,
"indent_handlebars": true
}
10 changes: 10 additions & 0 deletions examples/simple-jsbeautifyrc/test.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#if}}
{{#each}}
{{#if}}
content
{{/if}}
{{#if}}
content
{{/if}}
{{/each}}
{{/if}}
13 changes: 11 additions & 2 deletions lib/atom-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var knownOpts = {
'indent_char': String,
'indent_level': Number,
'indent_with_tabs': Boolean,
'indent_handlebars': Boolean,
'preserve_newlines': Boolean,
'max_preserve_newlines': Number,
'space_in_paren': Boolean,
Expand Down Expand Up @@ -229,15 +230,23 @@ function beautify() {

}, {}, selection);

// Clean
options = cleanOptions(options, knownOpts);

// TODO: Clean.
// There is a bug in nopt
// See https://github.com/npm/nopt/issues/38#issuecomment-45971505
//console.log('pre-clean', JSON.stringify(options));
//options = cleanOptions(options, knownOpts);
//console.log('post-clean', JSON.stringify(options));

return options;
}

switch (editor.getGrammar().name) {
case 'JavaScript':
text = beautifyJS(text, getOptions('js', allOptions));
break;
case 'Handlebars':
defaultOptions.indent_handlebars = true; // jshint ignore: line
case 'HTML (Liquid)':
case 'HTML':
case 'XML':
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"dependencies": {
"emissary": "^1.0.0",
"extend": "^1.2.1",
"js-beautify": "~1.4.2",
"nopt": "^2.2.1",
"js-beautify": "~1.5.1",
"nopt": "^3.0.0",
"lodash": "2.4.1",
"shelljs": "^0.3.0",
"strip-json-comments": "^0.1.3"
Expand Down

0 comments on commit b530eda

Please sign in to comment.