diff --git a/examples/simple-jsbeautifyrc/test.less b/examples/simple-jsbeautifyrc/test.less new file mode 100644 index 0000000..c487c6d --- /dev/null +++ b/examples/simple-jsbeautifyrc/test.less @@ -0,0 +1,32 @@ + a { + line-height: @headerHeight; + +display: block; + padding: 0px 15px; + font-size: 16px; + button { + font-size: 16px; + } + &:link { + color: @white; + +text-decoration: none; + } + &:visited { + color: @white; + + } + &:hover { + color: @orange; + + } + &.green { + color: @green; + +&:hover { + color: @white; + +background-color: @green; + + } + } diff --git a/lib/atom-beautify.js b/lib/atom-beautify.js index 59fadab..f367b8b 100644 --- a/lib/atom-beautify.js +++ b/lib/atom-beautify.js @@ -156,21 +156,21 @@ function findConfig(config, file) { function getConfigOptionsFromSettings(langs) { var config = atom.config.getSettings()['atom-beautify']; var options = {}; - console.log(langs, config); + // console.log(langs, config); // Iterate over keys of the settings _.every(_.keys(config), function (k) { // Check if keys start with a language var p = k.split('_')[0]; var idx = _.indexOf(langs, p); - console.log(k, p, idx); + // console.log(k, p, idx); if (idx >= 0) { // Remove the language prefix and nest in options var lang = langs[idx]; var opt = k.replace(new RegExp('^' + lang + '_'), ''); options[lang] = options[lang] || {}; options[lang][opt] = config[k]; - console.log(lang, opt); + // console.log(lang, opt); } return true; }); diff --git a/lib/langs/less-beautify.js b/lib/langs/less-beautify.js new file mode 100644 index 0000000..f06d755 --- /dev/null +++ b/lib/langs/less-beautify.js @@ -0,0 +1,15 @@ +'use strict'; + +var prettydiff = require('prettydiff'); + +module.exports = function (text, options, callback) { + var args = { + source: text, + lang: 'less', + mode: 'beautify' + }, + output = prettydiff.api(args); + var result = output[0]; + callback(result); + return result; +}; diff --git a/lib/language-options.js b/lib/language-options.js index 377ad7b..b05d285 100644 --- a/lib/language-options.js +++ b/lib/language-options.js @@ -14,6 +14,7 @@ var beautifySQL = require('./langs/sql-beautify'); var beautifyPHP = require('./langs/php-beautify'); var beautifyPython = require('./langs/python-beautify'); var beautifyRuby = require('./langs/ruby-beautify'); +var beautifyLESS = require('./langs/less-beautify'); var NA = require('nodealytics'); var pkg = require('../package.json'); @@ -94,11 +95,13 @@ module.exports = { break; case 'Sass': case 'SCSS': - case 'LESS': case 'CSS': text = beautifyCSS(text, self.getOptions('css', allOptions)); beautifyCompleted(text); break; + case 'LESS': + beautifyLESS(text, self.getOptions('css', allOptions), beautifyCompleted); + break; case 'SQL (Rails)': case 'SQL': text = beautifySQL(text, self.getOptions('sql', allOptions)); @@ -147,7 +150,7 @@ module.exports = { getOptions: function (selection, allOptions) { var self = this; - console.log(selection, allOptions); + // console.log(selection, allOptions); // Reduce all options into correctly merged options. var options = _.reduce(allOptions, function (result, currOptions) { @@ -165,7 +168,7 @@ module.exports = { } } - console.log(containsNested, currOptions); + // console.log(containsNested, currOptions); // Create a flat object of config options if nested format was used if (!containsNested) { @@ -173,7 +176,7 @@ module.exports = { } else { // Merge with selected options // where `selection` could be `html`, `js`, 'css', etc - console.log(selection, currOptions[selection]); + // console.log(selection, currOptions[selection]); _.merge(collectedConfig, currOptions[selection]); } @@ -184,7 +187,7 @@ module.exports = { // 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)); + // console.log('pre-clean', JSON.stringify(options)); //options = cleanOptions(options, knownOpts); //console.log('post-clean', JSON.stringify(options)); diff --git a/package.json b/package.json index 4d3d54d..7e28272 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,8 @@ "strip-json-comments": "^0.1.3", "js-yaml": "^3.0.2", "temp": "^0.8.0", - "nodealytics": "0.0.6" + "nodealytics": "0.0.6", + "prettydiff": "^1.0.23" }, "activationEvents": [ "beautify"