Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

issues/40: it is now possible to turn off structure minimization

  • Loading branch information...
commit 426212d1013e90b586f3decdf8893eab1c47ca19 1 parent 2ed5e66
@anotherquiz anotherquiz authored
View
4 README.md
@@ -63,6 +63,7 @@ Sample (`test.js`):
Output (`> node test.js`):
.test{color:#fff}
+Use `csso.justDoIt(css, true)` to turn structure minimization off.
## 3.3. From the command line
@@ -80,6 +81,9 @@ Usage:
csso -i <in_filename> -o <out_filename>
csso --input <in_filename> --output <out_filename>
minimizes the CSS in <in_filename> and outputs the result to <out_filename>
+ csso -off
+ csso --restructure-off
+ turns structure minimization off
csso -h
csso --help
shows usage information
View
4 README.ru.md
@@ -63,6 +63,7 @@ CSSO (CSS Optimizer) является минимизатором CSS, выпол
Вывод (`> node test.js`):
.test{color:#fff}
+Используйте `csso.justDoIt(css, true)`, если требуется выключить структурную минимизацию.
## 3.3. Через командную строку
@@ -80,6 +81,9 @@ CSSO (CSS Optimizer) является минимизатором CSS, выпол
csso -i <in_имя_файла> -o <out_имя_файла>
csso --input <in_имя_файла> --output <out_имя_файла>
минимизирует CSS из <in_имя_файла> и записывает результат в <out_имя_файла>
+ csso -off
+ csso --restructure-off
+ turns structure minimization off
csso -h
csso --help
показывает этот текст
View
6 USAGE
@@ -7,6 +7,9 @@ Usage:
csso -i <in_filename> -o <out_filename>
csso --input <in_filename> --output <out_filename>
minimizes the CSS in <in_filename> and outputs the result to <out_filename>
+ csso -off
+ csso --restructure-off
+ turns structure minimization off
csso -h
csso --help
shows usage information
@@ -23,6 +26,9 @@ Usage:
csso -i <in_имя_файла> -o <out_имя_файла>
csso --input <in_имя_файла> --output <out_имя_файла>
минимизирует CSS из <in_имя_файла> и записывает результат в <out_имя_файла>
+ csso -off
+ csso --restructure-off
+ выключает структурную минимизацию
csso -h
csso --help
показывает этот текст
View
40 lib/compressor.js
@@ -335,7 +335,7 @@ CSSOCompressor.prototype.process = function(rules, token, container, i, path) {
return x1;
};
-CSSOCompressor.prototype.compress = function(tree) {
+CSSOCompressor.prototype.compress = function(tree, ro) {
this.init();
this.info = typeof tree[0] !== 'string';
@@ -348,22 +348,24 @@ CSSOCompressor.prototype.compress = function(tree) {
x = this.walk(this.crules, x, '/0');
x = this.walk(this.prules, x, '/0');
ls = translator.translate(cleanInfo(x)).length;
- xs = this.copyArray(x);
-
- this.disjoin(x);
- x = this.walk(this.msrules, x, '/0');
- x = this.walk(this.csrules, x, '/0');
- x = this.walk(this.rbrules, x, '/0');
- do {
- l0 = l1;
- x0 = this.copyArray(x);
- x = this.walk(this.rjrules, x, '/0');
- x = this.walk(this.rrrules, x, '/0');
- l1 = translator.translate(cleanInfo(x)).length;
- x1 = this.copyArray(x);
- } while (l0 > l1);
- if (ls < l0 && ls < l1) x = xs;
- else if (l0 < l1) x = x0;
+
+ if (!ro) { // restructure ON
+ xs = this.copyArray(x);
+ this.disjoin(x);
+ x = this.walk(this.msrules, x, '/0');
+ x = this.walk(this.csrules, x, '/0');
+ x = this.walk(this.rbrules, x, '/0');
+ do {
+ l0 = l1;
+ x0 = this.copyArray(x);
+ x = this.walk(this.rjrules, x, '/0');
+ x = this.walk(this.rrrules, x, '/0');
+ l1 = translator.translate(cleanInfo(x)).length;
+ x1 = this.copyArray(x);
+ } while (l0 > l1);
+ if (ls < l0 && ls < l1) x = xs;
+ else if (l0 < l1) x = x0;
+ }
x = this.walk(this.frules, x, '/0');
@@ -1093,6 +1095,6 @@ CSSOCompressor.prototype.pathUp = function(path) {
var translator = require('./translator.js').translator(),
cleanInfo = require('./util.js').cleanInfo;
-exports.compress = function(tree) {
- return new CSSOCompressor().compress(tree);
+exports.compress = function(tree, ro) {
+ return new CSSOCompressor().compress(tree, ro);
};
View
8 lib/csso.js
@@ -7,7 +7,8 @@ var args = process.argv.slice(2),
opts = args.length ? getOpts(args, [
'-v', '--version',
'-h', '--help',
- '-dp', '--parser'
+ '-dp', '--parser',
+ '-off', '--restructure-off'
], [
'-r', '--rule',
'-i', '--input',
@@ -16,6 +17,7 @@ var args = process.argv.slice(2),
single = opts && opts.single,
pairs = opts && opts.pairs,
other = opts && opts.other,
+ ro = single && single.contains(['-off', '--restructure-off']),
inFile = (pairs && (pairs['-i'] || pairs['--input'])) || (other && other[0]),
outFile = (pairs && (pairs['-o'] || pairs['--output'])) || (other && other[1]),
rule = pairs && (pairs['-r'] || pairs['--rule']) || 'stylesheet';
@@ -29,8 +31,8 @@ if (single && single.contains(['-v', '--version'])) {
if (single.contains(['-dp', '--parser'])) csso.printTree(csso.parse(src, rule));
else {
- if (!outFile) print(csso.justDoIt(src));
- else fs.writeFileSync(outFile, csso.justDoIt(src));
+ if (!outFile) print(csso.justDoIt(src, ro));
+ else fs.writeFileSync(outFile, csso.justDoIt(src, ro));
}
}
View
4 lib/cssoapi.js
@@ -15,6 +15,6 @@ var translate = exports.translate = translator.translate;
var compress = exports.compress = compressor.compress;
-exports.justDoIt = function(src) {
- return translate(cleanInfo(compress(parse(src, 'stylesheet'))));
+exports.justDoIt = function(src, ro) {
+ return translate(cleanInfo(compress(parse(src, 'stylesheet'), ro)));
};
View
4 src/compressor.node.js
@@ -1,6 +1,6 @@
var translator = require('./translator.js').translator(),
cleanInfo = require('./util.js').cleanInfo;
-exports.compress = function(tree) {
- return new CSSOCompressor().compress(tree);
+exports.compress = function(tree, ro) {
+ return new CSSOCompressor().compress(tree, ro);
};
View
36 src/compressor.shared.js
@@ -219,7 +219,7 @@ CSSOCompressor.prototype.process = function(rules, token, container, i, path) {
return x1;
};
-CSSOCompressor.prototype.compress = function(tree) {
+CSSOCompressor.prototype.compress = function(tree, ro) {
this.init();
this.info = typeof tree[0] !== 'string';
@@ -232,22 +232,24 @@ CSSOCompressor.prototype.compress = function(tree) {
x = this.walk(this.crules, x, '/0');
x = this.walk(this.prules, x, '/0');
ls = translator.translate(cleanInfo(x)).length;
- xs = this.copyArray(x);
-
- this.disjoin(x);
- x = this.walk(this.msrules, x, '/0');
- x = this.walk(this.csrules, x, '/0');
- x = this.walk(this.rbrules, x, '/0');
- do {
- l0 = l1;
- x0 = this.copyArray(x);
- x = this.walk(this.rjrules, x, '/0');
- x = this.walk(this.rrrules, x, '/0');
- l1 = translator.translate(cleanInfo(x)).length;
- x1 = this.copyArray(x);
- } while (l0 > l1);
- if (ls < l0 && ls < l1) x = xs;
- else if (l0 < l1) x = x0;
+
+ if (!ro) { // restructure ON
+ xs = this.copyArray(x);
+ this.disjoin(x);
+ x = this.walk(this.msrules, x, '/0');
+ x = this.walk(this.csrules, x, '/0');
+ x = this.walk(this.rbrules, x, '/0');
+ do {
+ l0 = l1;
+ x0 = this.copyArray(x);
+ x = this.walk(this.rjrules, x, '/0');
+ x = this.walk(this.rrrules, x, '/0');
+ l1 = translator.translate(cleanInfo(x)).length;
+ x1 = this.copyArray(x);
+ } while (l0 > l1);
+ if (ls < l0 && ls < l1) x = xs;
+ else if (l0 < l1) x = x0;
+ }
x = this.walk(this.frules, x, '/0');
View
36 web/csso.web.js
@@ -1247,7 +1247,7 @@ CSSOCompressor.prototype.process = function(rules, token, container, i, path) {
return x1;
};
-CSSOCompressor.prototype.compress = function(tree) {
+CSSOCompressor.prototype.compress = function(tree, ro) {
this.init();
this.info = typeof tree[0] !== 'string';
@@ -1260,22 +1260,24 @@ CSSOCompressor.prototype.compress = function(tree) {
x = this.walk(this.crules, x, '/0');
x = this.walk(this.prules, x, '/0');
ls = translator.translate(cleanInfo(x)).length;
- xs = this.copyArray(x);
-
- this.disjoin(x);
- x = this.walk(this.msrules, x, '/0');
- x = this.walk(this.csrules, x, '/0');
- x = this.walk(this.rbrules, x, '/0');
- do {
- l0 = l1;
- x0 = this.copyArray(x);
- x = this.walk(this.rjrules, x, '/0');
- x = this.walk(this.rrrules, x, '/0');
- l1 = translator.translate(cleanInfo(x)).length;
- x1 = this.copyArray(x);
- } while (l0 > l1);
- if (ls < l0 && ls < l1) x = xs;
- else if (l0 < l1) x = x0;
+
+ if (!ro) { // restructure ON
+ xs = this.copyArray(x);
+ this.disjoin(x);
+ x = this.walk(this.msrules, x, '/0');
+ x = this.walk(this.csrules, x, '/0');
+ x = this.walk(this.rbrules, x, '/0');
+ do {
+ l0 = l1;
+ x0 = this.copyArray(x);
+ x = this.walk(this.rjrules, x, '/0');
+ x = this.walk(this.rrrules, x, '/0');
+ l1 = translator.translate(cleanInfo(x)).length;
+ x1 = this.copyArray(x);
+ } while (l0 > l1);
+ if (ls < l0 && ls < l1) x = xs;
+ else if (l0 < l1) x = x0;
+ }
x = this.walk(this.frules, x, '/0');
Please sign in to comment.
Something went wrong with that request. Please try again.