From b41daabaa677a39a2d7c1427c295daeda463be3e Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 8 Jun 2015 18:34:56 -0300 Subject: [PATCH] Closes #297, #265. Add missing Pretty Diff options for CSS/SCSS/Sass/LESS --- docs/options.md | 88 ++++++++++++++++++- .../sass/expected/insert-lines.scss | 7 ++ .../sass/original/insert-lines.scss | 6 ++ src/beautifiers/js-beautify.coffee | 8 +- src/beautifiers/prettydiff.coffee | 16 +++- src/languages/css.coffee | 30 ++++++- src/languages/javascript.coffee | 2 + 7 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 examples/nested-jsbeautifyrc/sass/expected/insert-lines.scss create mode 100644 examples/nested-jsbeautifyrc/sass/original/insert-lines.scss diff --git a/docs/options.md b/docs/options.md index bf9d82f..d32202c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -143,7 +143,7 @@ Add a newline between multiple selectors (Supported by JS Beautify) **Description**: -Add a newline between CSS rules (Supported by JS Beautify) +Add a newline between CSS rules (Supported by JS Beautify, Pretty Diff) ### CSS - Preserve newlines **Key**: `css_preserve_newlines` @@ -153,6 +153,57 @@ Add a newline between CSS rules (Supported by JS Beautify) **Description**: Retain empty lines. Consecutive empty lines will be converted to a single empty line. (Supported by JS Beautify, Pretty Diff) +### CSS - Wrap line length + +**Key**: `css_wrap_line_length` + +**Type**: `integer` + +**Description**: + +Maximum amount of characters per line (0 = disable) (Supported by JS Beautify, Pretty Diff) +### CSS - Indent comments + +**Key**: `css_indent_comments` + +**Default**: `true` + +**Type**: `boolean` + +**Description**: + +Determines whether comments should be indented. (Supported by Pretty Diff) +### CSS - Force indentation + +**Key**: `css_force_indentation` + +**Type**: `boolean` + +**Description**: + +if indentation should be forcefully applied tomarkup even if it disruptively adds unintended whitespace to the documents rendered output (Supported by Pretty Diff) +### CSS - Convert quotes + +**Key**: `css_convert_quotes` + +**Default**: `none` + +**Type**: `string` + +**Enum**: `none` `double` `single` + +**Description**: + +Convert the quote characters delimiting strings from either double or single quotes to the other. (Supported by Pretty Diff) +### CSS - Align assignments + +**Key**: `css_align_assignments` + +**Type**: `boolean` + +**Description**: + +If lists of assignments or properties should be vertically aligned for faster and easier reading. (Supported by Pretty Diff) ### D - Config Path **Key**: `d_configPath` @@ -247,7 +298,7 @@ Indentation character (Supported by JS Beautify, Pretty Diff) **Description**: -Maximum characters per line (0 disables) (Supported by JS Beautify) +Maximum characters per line (0 disables) (Supported by JS Beautify, Pretty Diff) ### HTML - Wrap attributes **Key**: `html_wrap_attributes` @@ -489,7 +540,7 @@ Decode printable characters encoded in xNN notation (Supported by JS Beautify) **Description**: -Wrap lines at next opportunity after N characters (Supported by JS Beautify) +Wrap lines at next opportunity after N characters (Supported by JS Beautify, Pretty Diff) ### JavaScript - End with newline **Key**: `js_end_with_newline` @@ -1695,6 +1746,37 @@ Default Beautifier to be used for TSS **Description**: Automatically beautify TSS files on save +### Language Config - Twig - Disable Beautifying Language + +**Key**: `language_twig_disabled` + +**Type**: `boolean` + +**Description**: + +Disable Twig Beautification +### Language Config - Twig - Default Beautifier + +**Key**: `language_twig_default_beautifier` + +**Default**: `Pretty Diff` + +**Type**: `string` + +**Enum**: `Pretty Diff` + +**Description**: + +Default Beautifier to be used for Twig +### Language Config - Twig - Beautify On Save + +**Key**: `language_twig_beautify_on_save` + +**Type**: `boolean` + +**Description**: + +Automatically beautify Twig files on save ### Language Config - TypeScript - Disable Beautifying Language **Key**: `language_typescript_disabled` diff --git a/examples/nested-jsbeautifyrc/sass/expected/insert-lines.scss b/examples/nested-jsbeautifyrc/sass/expected/insert-lines.scss new file mode 100644 index 0000000..f4da8db --- /dev/null +++ b/examples/nested-jsbeautifyrc/sass/expected/insert-lines.scss @@ -0,0 +1,7 @@ +body { + background: red; +} + +h1 { + font-size: 16px; +} \ No newline at end of file diff --git a/examples/nested-jsbeautifyrc/sass/original/insert-lines.scss b/examples/nested-jsbeautifyrc/sass/original/insert-lines.scss new file mode 100644 index 0000000..4bf8ef5 --- /dev/null +++ b/examples/nested-jsbeautifyrc/sass/original/insert-lines.scss @@ -0,0 +1,6 @@ +body { + background: red; +} +h1 { + font-size: 16px; +} \ No newline at end of file diff --git a/src/beautifiers/js-beautify.coffee b/src/beautifiers/js-beautify.coffee index 9deca26..24da418 100644 --- a/src/beautifiers/js-beautify.coffee +++ b/src/beautifiers/js-beautify.coffee @@ -11,7 +11,13 @@ module.exports = class JSBeautify extends Beautifier Marko: true JavaScript: true JSON: true - CSS: true + CSS: + indent_size: true + indent_char: true + selector_separator_newline: true + newline_between_rules: true + preserve_newlines: true + wrap_line_length: true } beautify: (text, language, options) -> diff --git a/src/beautifiers/prettydiff.coffee b/src/beautifiers/prettydiff.coffee index 13c06b6..4db3b05 100644 --- a/src/beautifiers/prettydiff.coffee +++ b/src/beautifiers/prettydiff.coffee @@ -8,12 +8,24 @@ module.exports = class PrettyDiff extends Beautifier _: inchar: "indent_char" insize: "indent_size" - alphasort: (alphasort) -> - alphasort or false + objsort: (objsort) -> + objsort or false preserve: ['preserve_newlines', (preserve_newlines) -> if (preserve_newlines is true ) then \ "all" else "none" ] + cssinsertlines: "newline_between_rules" + comments: ["indent_comments", (indent_comments) -> + if (indent_comments is true) then \ + "indent" else "noindent" + ] + force: "force_indentation" + quoteConvert: "convert_quotes" + vertical: ['align_assignments', (align_assignments) -> + if (align_assignments is true ) then \ + "all" else "none" + ] + wrap: "wrap_line_length" # Apply language-specific options CSV: true ERB: true diff --git a/src/languages/css.coffee b/src/languages/css.coffee index b4c994f..6e37f03 100644 --- a/src/languages/css.coffee +++ b/src/languages/css.coffee @@ -1,5 +1,5 @@ # Get Atom defaults -tabLength = atom?.config.get('editor.tabLength') ? 4 +tabLength = atom?.config.get('editor.tabLength') ? 4 softTabs = atom?.config.get('editor.softTabs') ? true defaultIndentSize = (if softTabs then tabLength else 1) defaultIndentChar = (if softTabs then " " else "\t") @@ -50,6 +50,32 @@ module.exports = { type: 'boolean' default: false description: "Retain empty lines. "+ - "Consecutive empty lines will be converted to a single empty line." + "Consecutive empty lines will be converted to \ + a single empty line." + wrap_line_length: + type: 'integer' + default: 0 + description: "Maximum amount of characters per line (0 = disable)" + indent_comments: + type: 'boolean' + default: true + description: "Determines whether comments should be indented." + force_indentation: + type: 'boolean' + default: false + description: "if indentation should be forcefully applied to\ + markup even if it disruptively adds unintended whitespace \ + to the documents rendered output" + convert_quotes: + type: 'string' + default: "none" + description: "Convert the quote characters delimiting strings \ + from either double or single quotes to the other." + enum: ["none", "double", "single"] + align_assignments: + type: 'boolean' + default: false + description: "If lists of assignments or properties should be \ + vertically aligned for faster and easier reading." } \ No newline at end of file diff --git a/src/languages/javascript.coffee b/src/languages/javascript.coffee index f7f48e5..df270f9 100644 --- a/src/languages/javascript.coffee +++ b/src/languages/javascript.coffee @@ -24,6 +24,8 @@ module.exports = { "js" ] + defaultBeautifier: "JS Beautify" + ### ###