Skip to content

Commit

Permalink
Closes #54. Switch to using Pretty Diff for LESS support.
Browse files Browse the repository at this point in the history
Fixes #53. Fixes #52.
  • Loading branch information
Glavin001 committed Aug 2, 2014
1 parent 04a23a0 commit 5bff9eb
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
32 changes: 32 additions & 0 deletions examples/simple-jsbeautifyrc/test.less
Original file line number Diff line number Diff line change
@@ -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;

}
}
6 changes: 3 additions & 3 deletions lib/atom-beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
15 changes: 15 additions & 0 deletions lib/langs/less-beautify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var prettydiff = require('prettydiff');

module.exports = function (text, options, callback) {
var args = {
source: text,
lang: 'less',

This comment has been minimized.

Copy link
@seaside98

seaside98 Aug 2, 2014

This Stack Overflow question suggests that the lang parameter takes a number instead of a string. Since it is using 'auto' and not 'less', that would probably be worth checking. Per #54

This comment has been minimized.

Copy link
@seaside98

seaside98 Aug 2, 2014

And if that doesn't work, the web interface uses 'css' instead of 'less'.

<select ... >
    <option xmlns="http://www.w3.org/1999/xhtml" selected="selected" value="auto">Auto Detect</option>
    <option xmlns="http://www.w3.org/1999/xhtml" value="css">CSS</option>
    ...
    <option xmlns="http://www.w3.org/1999/xhtml" value="css">SCSS (SASS)</option>
</select>
mode: 'beautify'
},
output = prettydiff.api(args);
var result = output[0];
callback(result);
return result;
};
13 changes: 8 additions & 5 deletions lib/language-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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) {
Expand All @@ -165,15 +168,15 @@ module.exports = {
}
}

console.log(containsNested, currOptions);
// console.log(containsNested, currOptions);

// Create a flat object of config options if nested format was used
if (!containsNested) {
_.merge(collectedConfig, currOptions);
} 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]);
}

Expand All @@ -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));

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5bff9eb

Please sign in to comment.