Skip to content

Commit

Permalink
Renames noAdvanced option into advanced.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubpawlowicz committed Oct 10, 2014
1 parent 5f79864 commit 83373ed
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Breaks 2.x compatibility for using CleanCSS as a function.
* Reworks minification to tokenize first then minify.
See [changes](https://github.com/jakubpawlowicz/clean-css/compare/b06f37d...dd8c14a).
* Renames `noAdvanced` option into `advanced`.
* Speeds up advanced processing by shortening optimize loop.
* Fixed issue [#360](https://github.com/GoalSmashers/clean-css/issues/360) - adds 7 extra CSS colors.

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Node.js 0.8.0+ (tested on CentOS, Ubuntu, OS X 10.6+, and Windows 7+)
npm install clean-css
```

### How to upgrade clean-css from 2.x to 3.x?

#### Command-line interface (CLI) - no breaking changes.

#### Module interface

* `noAdvanced` became `advanced` - make sure to reverse the value;

### How to upgrade clean-css from 1.x to 2.x?

#### Command-line interface (CLI)
Expand Down Expand Up @@ -121,13 +129,13 @@ var minimized = new CleanCSS().minify(source);
CleanCSS constructor accepts a hash as a parameter, i.e.,
`new CleanCSS(options).minify(source)` with the following options available:

* `advanced` - set to false to disable advanced optimizations - selector & property merging, reduction, etc.
* `benchmark` - turns on benchmarking mode measuring time spent on cleaning up (run `npm run bench` to see example)
* `compatibility` - Force compatibility mode to `ie7` or `ie8`. Defaults to not set.
* `debug` - set to true to get minification statistics under `stats` property (see `test/custom-test.js` for examples)
* `inliner` - a hash of options for `@import` inliner, see test/protocol-imports-test.js for examples
* `keepBreaks` - whether to keep line breaks (default is false)
* `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one only, `0` for removing all
* `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc.
* `noAggressiveMerging` - set to true to disable aggressive merging of properties.
* `noRebase` - whether to skip URLs rebasing
* `processImport` - whether to process `@import` rules
Expand Down
2 changes: 1 addition & 1 deletion bin/cleancss
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (commands.skipImport)
if (commands.skipRebase)
cleanOptions.noRebase = true;
if (commands.skipAdvanced)
cleanOptions.noAdvanced = true;
cleanOptions.advanced = false;
if (commands.skipAggressiveMerging)
cleanOptions.noAggressiveMerging = true;
if (commands.compatibility)
Expand Down
4 changes: 2 additions & 2 deletions lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ var CleanCSS = module.exports = function CleanCSS(options) {
options = options || {};

this.options = {
advanced: options.advanced === undefined ? true : false,
benchmark: options.benchmark,
compatibility: options.compatibility,
debug: options.debug,
inliner: options.inliner,
keepBreaks: options.keepBreaks || false,
keepSpecialComments: 'keepSpecialComments' in options ? options.keepSpecialComments : '*',
noAdvanced: options.noAdvanced,
noAggressiveMerging: options.noAggressiveMerging,
noRebase: options.noRebase,
processImport: undefined === options.processImport ? true : false,
Expand Down Expand Up @@ -118,7 +118,7 @@ function minify(data) {
var urlRebase = new UrlRebase(options, context);
var selectorsOptimizer = new SelectorsOptimizer({
keepBreaks: options.keepBreaks,
noAdvanced: options.noAdvanced,
advanced: options.advanced,
compatibility: options.compatibility,
aggressiveMerging: !options.noAggressiveMerging,
roundingPrecision: options.roundingPrecision
Expand Down
2 changes: 1 addition & 1 deletion lib/selectors/optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SelectorsOptimizer.prototype.process = function (data) {
var tokens = new Tokenizer(this.context).toTokens(data);

new SimpleOptimizer(this.options).optimize(tokens);
if (!this.options.noAdvanced)
if (this.options.advanced)
new AdvancedOptimizer(this.options, this.context).optimize(tokens);

return rebuild(tokens, this.options.keepBreaks, false).trim();
Expand Down
7 changes: 4 additions & 3 deletions test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var CleanCSS = require('../index');
var lineBreak = process.platform == 'win32' ? '\r\n' : '\n';
var cssContext = function(groups, options) {
var context = {};

var clean = function(expectedCss) {
return function(css) {
var minifiedCss = new CleanCSS(options).minify(css);
Expand Down Expand Up @@ -1460,19 +1461,19 @@ title']{display:block}",
'@import url(//fonts.googleapis.com/css?family=Domine:700);body h1{font-family:Domine}'
],
'no empty body': '@import url(//fonts.googleapis.com/css?family=Domine:700);body{color:red}body h1{font-family:Domine}'
}, { processImport: false, noAdvanced: true }),
}, { processImport: false, advanced: false }),
'duplicate selectors with disabled advanced processing': cssContext({
'of a duplicate selector': [
'a,a{color:red}',
'a{color:red}'
]
}, { noAdvanced: true }),
}, { advanced: false }),
'line breaks with disabled advanced processing': cssContext({
'should be applied': [
'a{color:red}p{display:block}',
'a{color:red}' + lineBreak + 'p{display:block}'
]
}, { noAdvanced: true, keepBreaks: true }),
}, { advanced: false, keepBreaks: true }),
'invalid data tokenization': cssContext({
'extra top-level closing brace': [
'a{color:red}}p{width:auto}',
Expand Down
6 changes: 3 additions & 3 deletions test/selectors/optimizer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ vows.describe(SelectorsOptimizer)
'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}',
'a{margin:0}.one{color:red}a,p{color:red;padding:0}'
]
}, { noAdvanced: false, aggressiveMerging: true })
}, { advanced: true, aggressiveMerging: true })
)
.addBatch(
optimizerContext('advanced on & aggressive merging off', {
Expand All @@ -160,7 +160,7 @@ vows.describe(SelectorsOptimizer)
'a{padding:10px;margin:0;color:red}.one{color:red}a,p{color:red;padding:0}',
'a{padding:10px;margin:0}.one{color:red}a,p{color:red;padding:0}'
]
}, { noAdvanced: false, aggressiveMerging: false })
}, { advanced: true, aggressiveMerging: false })
)
.addBatch(
optimizerContext('advanced off', {
Expand All @@ -184,7 +184,7 @@ vows.describe(SelectorsOptimizer)
'a{color:red;display:block}.one{font-size:12px}a{color:#fff;margin:2px}',
'a{color:red;display:block}.one{font-size:12px}a{color:#fff;margin:2px}'
]
}, { noAdvanced: true })
}, { advanced: false })
)
.addBatch(
optimizerContext('@charset', {
Expand Down

0 comments on commit 83373ed

Please sign in to comment.