diff --git a/README.md b/README.md index e3fff1e..f4d3300 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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). diff --git a/examples/simple-jsbeautifyrc/.jsbeautifyrc b/examples/simple-jsbeautifyrc/.jsbeautifyrc index 507cb2a..f4b0e8c 100644 --- a/examples/simple-jsbeautifyrc/.jsbeautifyrc +++ b/examples/simple-jsbeautifyrc/.jsbeautifyrc @@ -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 } diff --git a/examples/simple-jsbeautifyrc/test.hbs b/examples/simple-jsbeautifyrc/test.hbs new file mode 100644 index 0000000..1aa5cd7 --- /dev/null +++ b/examples/simple-jsbeautifyrc/test.hbs @@ -0,0 +1,10 @@ +{{#if}} +{{#each}} +{{#if}} +content +{{/if}} +{{#if}} +content +{{/if}} +{{/each}} +{{/if}} diff --git a/lib/atom-beautify.js b/lib/atom-beautify.js index 3438c58..a051e82 100644 --- a/lib/atom-beautify.js +++ b/lib/atom-beautify.js @@ -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, @@ -229,8 +230,14 @@ 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; } @@ -238,6 +245,8 @@ function beautify() { 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': diff --git a/package.json b/package.json index adface9..05cd67b 100644 --- a/package.json +++ b/package.json @@ -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"