From 27db1e3286b6ee0ff1fd6e248f9fa9e9ca9af07f Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 31 Dec 2012 23:47:56 +0100 Subject: [PATCH] Updated README.md, History.md, and License formatting. Added new CLI options. By @XhmikosR. * switch back to code blocks instead of inline code * remove the closing hashes from paragraphs since they are not needed * break a couple long lines * cli: accept more synonym switches like --empty and --keepbreaks * README.md: document the command line switches. This fixes issue #41. * LICENSE: break the lines --- History.md | 2 +- LICENSE | 20 +++++++++++--- README.md | 75 ++++++++++++++++++++++++++++++++++++---------------- bin/cleancss | 18 ++++++++----- lib/clean.js | 21 ++++++++------- 5 files changed, 92 insertions(+), 44 deletions(-) diff --git a/History.md b/History.md index 1848659b..9d0e891b 100644 --- a/History.md +++ b/History.md @@ -41,7 +41,7 @@ * Added removing URLs quotation if possible. * Rewrote breaks processing. -* Added `keepBreaks`/`-b` option to keep breaks in minimized file. +* Added `keepBreaks`/`-b` option to keep line breaks in the minimized file. * Reformatted lib/clean.js so it's easier to follow the rules. * Minimized test data is now minimized with line breaks so it's easier to compare the changes line by line. diff --git a/LICENSE b/LICENSE index 2db6c0f0..cda28ec8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,19 @@ -Copyright (c) 2011-2012 GoalSmashers.com +Copyright (C) 2011-2012 GoalSmashers.com -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 72d7085a..67c1239b 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,91 @@ [![build status](https://secure.travis-ci.org/GoalSmashers/clean-css.png)](http://travis-ci.org/GoalSmashers/clean-css) -## What is clean-css? ## + +## What is clean-css? Clean-css is a [node.js](http://nodejs.org/) library for minifying CSS files. It does the same job as YUI Compressor's CSS minifier, but much faster thanks to many speed optimizations and node.js' V8 engine. -## Usage ## -### What are the requirements? ### +## Usage + +### What are the requirements? ``` -node 0.6.0+ on *nix (fully tested on OS X 10.6+ and CentOS) +node 0.6.0+ on UN*X (fully tested on OS X 10.6+ and CentOS) node 0.8.0+ on Windows ``` -### How to install clean-css? ### +### How to install clean-css? + +``` +npm install clean-css +``` + +### How to use clean-css CLI? + +Clean-css accepts the following command line arguments: + +``` +cleancss [options] -o +``` -`npm install clean-css` +* `-e`, `-empty`, `-removeempty` Remove empty declarations (e.g. `.class {}`) +* `-b`, `-keepbreaks`, `-keeplinebreaks` Keep line breaks +* `--s0` Remove all special comments (i.e. `/*! special comment */`) +* `--s1` Remove all special comments but the first one -### How to use clean-css CLI? ### +#### Examples: To minify a **public.css** file into **public-min.css** do: -`cleancss -o public-min.css public.css` +``` +cleancss -o public-min.css public.css +``` To minify the same **public.css** into the standard output skip the `-o` parameter: -`cleancss public.css` +``` +cleancss public.css +``` -More likely you would like to concatenate a couple of files. Iif you are on a *nix system: +More likely you would like to concatenate a couple of files. +If you are on a Unix-like system: -`cat one.css two.css three.css | cleancss -o merged-and-minified.css` +``` +cat one.css two.css three.css | cleancss -o merged-and-minified.css +``` -or on Windows: +On Windows: -`type one.css two.css three.css | cleancss -o merged-and-minified.css` +``` +type one.css two.css three.css | cleancss -o merged-and-minified.css +``` Or even gzip the result at once: -`cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz` +``` +cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz +``` -### How to use clean-css programmatically? ### +### How to use clean-css programmatically? -```javascript +```js var cleanCSS = require('clean-css'); var source = "a{font-weight:bold;}"; var minimized = cleanCSS.process(source); ``` -Process method accepts a hash as a second parameter, i.e., `cleanCSS.process(source, options)` -with the following options available: +Process method accepts a hash as a second parameter, i.e., +`cleanCSS.process(source, options)` with the following options available: * `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one, `0` for removing all * `keepBreaks` - whether to keep line breaks (default is false) * `removeEmpty` - whether to remove empty elements (default is false) -* `debug` - turns on debug mode measuring time spent on cleaning up (run `npm run bench` to see example) +* `debug` - turns on debug mode measuring time spent on cleaning up + (run `npm run bench` to see example) -### What are the clean-css' dev commands? ### +### What are the clean-css' dev commands? First clone the source, then run: @@ -64,7 +93,7 @@ First clone the source, then run: * `npm run check` to check JS sources with [JSHint](https://github.com/jshint/jshint/) * `npm test` for the test suite -### How do you preserve a comment block? ### +### How do you preserve a comment block? Use the `/*!` notation instead of the standard one `/*`: @@ -75,7 +104,7 @@ Use the `/*!` notation instead of the standard one `/*`: ``` -## Acknowledgments ## +## Acknowledgments * Vincent Voyer ([@vvo](https://github.com/vvo)) for a patch with better empty element regex and for inspiring us to do many performance improvements @@ -88,6 +117,6 @@ Use the `/*!` notation instead of the standard one `/*`: (option to remove special comments and strip out URLs quotation) and pointing out numerous improvements (JSHint, media queries). -## License ## +## License Clean-css is released under the [MIT License](http://opensource.org/licenses/MIT). diff --git a/bin/cleancss b/bin/cleancss index 2136b7a8..ab842a5b 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -13,12 +13,18 @@ var options = { var cleanOptions = {}; var fromStdin = !process.env['__DIRECT__'] && process.stdin.readable; -if (argv.o) options.target = argv.o; -if (argv._) options.source = argv._[0]; -if (argv.e) cleanOptions.removeEmpty = true; -if (argv.b) cleanOptions.keepBreaks = true; -if (argv.s1) cleanOptions.keepSpecialComments = 1; -if (argv.s0) cleanOptions.keepSpecialComments = 0; +if (argv.o) + options.target = argv.o; +if (argv._) + options.source = argv._[0]; +if (argv.e || argv.empty || argv.removeempty) + cleanOptions.removeEmpty = true; +if (argv.b || argv.keepbreaks || argv.keeplinebreaks) + cleanOptions.keepBreaks = true; +if (argv.s1) + cleanOptions.keepSpecialComments = 1; +if (argv.s0) + cleanOptions.keepSpecialComments = 0; if (argv.v) { var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json')); diff --git a/lib/clean.js b/lib/clean.js index 19d42624..3abec66d 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -118,7 +118,7 @@ var CleanCSS = { // trailing semicolons replace(/;\}/g, '}'); - // strip quotation in animations & font names + // strip quotation in animation & font names replace(/(animation|animation\-name|font|font\-family):([^;}]+)/g, function(match, propertyName, fontDef) { return propertyName + ':' + fontDef.replace(/['"]([\w\-]+)['"]/g, '$1'); }); @@ -163,7 +163,7 @@ var CleanCSS = { return prefix + '#' + color; }); - // replace color name with hex values if shorter (or other way around) + // replace color name with hex values if shorter (or the other way around) ['toHex', 'toName'].forEach(function(type) { var pattern = "(" + Object.keys(CleanCSS.colors[type]).join('|') + ")"; var colorSwitcher = function(match, prefix, colorValue, suffix) { @@ -183,7 +183,7 @@ var CleanCSS = { return match; }); - // IE shorter filters but only if single (IE 7 issue) + // IE shorter filters, but only if single (IE 7 issue) replace(/progid:DXImageTransform\.Microsoft\.(Alpha|Chroma)(\([^\)]+\))([;}'"])/g, function(match, filter, args, suffix) { return filter.toLowerCase() + args + suffix; }); @@ -292,7 +292,7 @@ var CleanCSS = { return data.trim(); }, - // Strips special comments (/*! ... */) by replacing them by __CSSCOMMENT__ marker + // Strip special comments (/*! ... */) by replacing them by __CSSCOMMENT__ marker // for further restoring. Plain comments are removed. It's done by scanning datq using // String#indexOf scanning instead of regexps to speed up the process. _stripComments: function(context, data) { @@ -321,9 +321,9 @@ var CleanCSS = { data; }, - // Strips content tags by replacing them by __CSSCONTENT__ marker - // for further restoring. It's done via string scanning instead of - // regexps to speed up the process. + // Strip content tags by replacing them by the __CSSCONTENT__ + // marker for further restoring. It's done via string scanning + // instead of regexps to speed up the process. _stripContent: function(context, data) { var tempData = [], nextStart = 0, @@ -331,8 +331,8 @@ var CleanCSS = { cursor = 0, matchedParenthesis = null; - // Finds either first (matchedParenthesis == null) or second matching parenthesis - // so we can determine boundaries of content block. + // Find either first (matchedParenthesis == null) or second matching + // parenthesis so that we can determine boundaries of content block. var nextParenthesis = function(pos) { var min, max = data.length; @@ -359,7 +359,8 @@ var CleanCSS = { matchedParenthesis = null; return min; } else { - // check if there's anything else between pos and min that doesn't match ':' or whitespace + // check if there's anything else between pos and min + // that doesn't match ':' or whitespace if (/[^:\s]/.test(data.substring(pos, min))) return -1; -- 2.34.1