Closes #54. Switch to using Pretty Diff for LESS support.

Fixes #53. Fixes #52.
This commit is contained in:
Glavin Wiechert 2014-08-01 20:06:24 -04:00
parent 04a23a03f2
commit 5bff9ebc48
5 changed files with 60 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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;
});

View File

@ -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;
};

View File

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

View File

@ -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"