Fixes #9. Nested options in .jsbeautifyrc are properly handled.

This commit is contained in:
Glavin Wiechert 2014-06-14 19:57:55 -03:00
parent b9d7869a66
commit 54e61a816f
3 changed files with 14 additions and 8 deletions

View File

@ -7,5 +7,6 @@
"preserve_newlines": true, "preserve_newlines": true,
"max_preserve_newlines": 2, "max_preserve_newlines": 2,
"jslint_happy": true, "jslint_happy": true,
"indent_handlebars": true "indent_handlebars": true,
"object": {}
} }

View File

@ -2,14 +2,14 @@
<html> <html>
<head> <head>
<title>Test Page</title> <title>Test Page</title>
</head> </head>
<body> <body>
<h1>Hello</h1> <h1>Hello</h1>
<p> <p>
World! World!
</p> </p>
</body> </body>
</html> </html>

View File

@ -159,6 +159,10 @@ function beautify() {
var softTabs = editor.softTabs; var softTabs = editor.softTabs;
var tabLength = editor.getTabLength(); var tabLength = editor.getTabLength();
// Supported unique configuration keys
// Used for detecting nested configurations in .jsbeautifyrc
var languages = ['js', 'html', 'css', 'sql'];
var defaultOptions = { var defaultOptions = {
'indent_size': softTabs ? tabLength : 1, 'indent_size': softTabs ? tabLength : 1,
'indent_char': softTabs ? ' ' : '\t', 'indent_char': softTabs ? ' ' : '\t',
@ -182,7 +186,7 @@ function beautify() {
encoding: 'utf8' encoding: 'utf8'
}))); })));
} catch (e) { } catch (e) {
console.log('Failed parsing config JSON at '+configPath); console.log('Failed parsing config JSON at ' + configPath);
externalOptions = {}; externalOptions = {};
} }
} else { } else {
@ -218,7 +222,8 @@ function beautify() {
// Check to see if config file uses nested object format to split up js/css/html options // Check to see if config file uses nested object format to split up js/css/html options
for (key in currOptions) { 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; containsNested = true;
break; // Found, break out of loop, no need to continue break; // Found, break out of loop, no need to continue
} }