-var util = require('util');
+/**
+ * Clean-css - https://github.com/GoalSmashers/clean-css
+ * Released under the terms of MIT license
+ *
+ * Copyright (C) 2011-2012 GoalSmashers.com
+ */
var CleanCSS = {
colors: {
specialComments: [],
contentBlocks: []
};
- var replace = function(pattern, replacement) {
+ var replace = function() {
if (typeof arguments[0] == 'function')
arguments[0]();
else
replace(/content :/g, 'content:');
// restore spaces inside IE filters (IE 7 issue)
- replace(/progid:[^(]+\(([^\)]+)/g, function(match, contents) {
+ replace(/progid:[^(]+\(([^\)]+)/g, function(match) {
return match.replace(/,/g, ', ');
});
// replace standard colors with hex values (only if color name is longer then hex value)
replace(/(color|background):(\w+)/g, function(match, property, colorName) {
- if (CleanCSS.colors[colorName]) return property + ':' + CleanCSS.colors[colorName];
- else return match;
+ if (CleanCSS.colors[colorName])
+ return property + ':' + CleanCSS.colors[colorName];
+ else
+ return match;
});
// replace #f00 with red as it's shorter
// replace font weight with numerical value
replace(/font\-weight:(\w+)/g, function(match, weight) {
- if (weight == 'normal') return 'font-weight:400';
- else if (weight == 'bold') return 'font-weight:700';
+ if (weight == 'normal')
+ return 'font-weight:400';
+ else if (weight == 'bold')
+ return 'font-weight:700';
else return match;
});
// empty elements
if (options.removeEmpty)
- replace(/[^}]+?{}/g, '');
+ replace(/[^\}]+?\{\}/g, '');
// move first charset to the beginning
if (data.indexOf('charset') > 0)
replace(/calc\([^\}]+\}/g, function(match) {
return match.replace(/\+/g, ' + ');
});
- replace(/__CSSCOMMENT__/g, function(i) {
+ replace(/__CSSCOMMENT__/g, function() {
switch (options.keepSpecialComments) {
case '*':
return context.specialComments.shift();
for (; nextEnd < data.length; ) {
nextStart = data.indexOf('/*', nextEnd);
nextEnd = data.indexOf('*/', nextStart);
- if (nextStart == -1 || nextEnd == -1) break;
+ if (nextStart == -1 || nextEnd == -1)
+ break;
tempData.push(data.substring(cursor, nextStart));
if (data[nextStart + 2] == '!') {
var tempData = [],
nextStart = 0,
nextEnd = 0,
- tempStart = 0,
cursor = 0,
matchedParenthesis = null;
if (matchedParenthesis) {
min = data.indexOf(matchedParenthesis, pos);
- if (min == -1) min = max;
+ if (min == -1)
+ min = max;
} else {
var next1 = data.indexOf("'", pos);
var next2 = data.indexOf('"', pos);
- if (next1 == -1) next1 = max;
- if (next2 == -1) next2 = max;
+ if (next1 == -1)
+ next1 = max;
+ if (next2 == -1)
+ next2 = max;
min = next1 > next2 ? next2 : next1;
}
- if (min == max) return -1;
+ if (min == max)
+ return -1;
if (matchedParenthesis) {
matchedParenthesis = null;
return min;
} else {
// 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;
+ if (/[^:\s]/.test(data.substring(pos, min)))
+ return -1;
+
matchedParenthesis = data.charAt(min);
return min + 1;
}
for (; nextEnd < data.length; ) {
nextStart = data.indexOf('content', nextEnd);
- if (nextStart == -1) break;
+ if (nextStart == -1)
+ break;
nextStart = nextParenthesis(nextStart + 7);
nextEnd = nextParenthesis(nextStart);
- if (nextStart == -1 || nextEnd == -1) break;
+ if (nextStart == -1 || nextEnd == -1)
+ break;
tempData.push(data.substring(cursor, nextStart - 1));
tempData.push('__CSSCONTENT__');
}
}),
'help': binaryContext('-h', {
- 'should output help': function(error, stdout, stderr) {
+ 'should output help': function(error, stdout) {
assert.equal(/usage:/.test(stdout), true);
}
}),
'should give no output': function(error, stdout) {
assert.equal(stdout, '');
},
- 'should minimize': function(stdout) {
+ 'should minimize': function() {
var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(lineBreak, '');
assert.equal(minimized, target);