From 54e61a816f7fd087822d44c97ed3ab8c7130a845 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sat, 14 Jun 2014 19:57:55 -0300 Subject: [PATCH] Fixes #9. Nested options in .jsbeautifyrc are properly handled. --- examples/simple-jsbeautifyrc/.jsbeautifyrc | 3 ++- examples/simple-jsbeautifyrc/test.html | 10 +++++----- lib/atom-beautify.js | 9 +++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/simple-jsbeautifyrc/.jsbeautifyrc b/examples/simple-jsbeautifyrc/.jsbeautifyrc index f4b0e8c..650b9c1 100644 --- a/examples/simple-jsbeautifyrc/.jsbeautifyrc +++ b/examples/simple-jsbeautifyrc/.jsbeautifyrc @@ -7,5 +7,6 @@ "preserve_newlines": true, "max_preserve_newlines": 2, "jslint_happy": true, - "indent_handlebars": true + "indent_handlebars": true, + "object": {} } diff --git a/examples/simple-jsbeautifyrc/test.html b/examples/simple-jsbeautifyrc/test.html index c6f5bdf..c7b26c9 100644 --- a/examples/simple-jsbeautifyrc/test.html +++ b/examples/simple-jsbeautifyrc/test.html @@ -2,14 +2,14 @@ - Test Page +Test Page -

Hello

-

- World! -

+

Hello

+

+World! +

diff --git a/lib/atom-beautify.js b/lib/atom-beautify.js index d665755..9f47838 100644 --- a/lib/atom-beautify.js +++ b/lib/atom-beautify.js @@ -159,6 +159,10 @@ function beautify() { var softTabs = editor.softTabs; var tabLength = editor.getTabLength(); + // Supported unique configuration keys + // Used for detecting nested configurations in .jsbeautifyrc + var languages = ['js', 'html', 'css', 'sql']; + var defaultOptions = { 'indent_size': softTabs ? tabLength : 1, 'indent_char': softTabs ? ' ' : '\t', @@ -182,7 +186,7 @@ function beautify() { encoding: 'utf8' }))); } catch (e) { - console.log('Failed parsing config JSON at '+configPath); + console.log('Failed parsing config JSON at ' + configPath); externalOptions = {}; } } else { @@ -218,7 +222,8 @@ function beautify() { // Check to see if config file uses nested object format to split up js/css/html options for (key in currOptions) { - if (typeof currOptions[key] === 'object') { + if (_.indexOf(languages, key) >= 0 && // Check if is supported language + typeof currOptions[key] === 'object') { // Check if nested object (more options in value) containsNested = true; break; // Found, break out of loop, no need to continue }