Permalink
Browse files

Moved YUI CSS compressor logic into the LessTask.

  • Loading branch information...
1 parent 7cc744f commit 8952cb0176806837269631f7a2b6607ba0dbc733 @spocke spocke committed Oct 19, 2011
Showing with 429 additions and 24 deletions.
  1. +1 −1 example/build.xml
  2. +25 −18 lib/less.rhino.js
  3. +403 −5 src/com/moxiecode/ant/tasks/LessTask.java
View
@@ -71,7 +71,7 @@
<yuicompress infile="dtds/xhtml1-transitional.dtd.children.compressed.js" outfile="dtds/xhtml1-transitional.dtd.children.compressed.min.js" />
<!-- Run less compiler and compress the output-->
- <less script="test.js" infile="test.less" outfile="test.min.css" compress="true" />
+ <less script="../lib/less.rhino.js" infile="test.less" outfile="test.min.css" compress="true" />
</target>
<!-- Generate JS documentation -->
View
@@ -1,3 +1,5 @@
+var window = {};
+
//
// Stub out `require` in rhino
//
@@ -437,7 +439,7 @@ less.Parser = function Parser(env) {
}
try {
- var css = evaluate.call(this, { frames: frames })
+ var css = evaluate.call(this, { frames: frames, compress: options.compress || false })
.toCSS([], { compress: options.compress || false });
} catch (e) {
lines = input.split('\n');
@@ -551,9 +553,9 @@ less.Parser = function Parser(env) {
// rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
// as represented by this simplified grammar:
//
- // primary ? (ruleset | rule)+
- // ruleset ? selector+ block
- // block ? '{' primary '}'
+ // primary (ruleset | rule)+
+ // ruleset selector+ block
+ // block '{' primary '}'
//
// Only at one point is the primary rule not called from the
// block rule: at the root level.
@@ -1372,6 +1374,11 @@ tree.functions = {
escape: function (str) {
return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
},
+ fullhex: function(color) {
+ // Foces the color to be a full hex value for MS filter: etc
+ color.compress = false;
+ return color;
+ },
'%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
str = quoted.value;
@@ -1391,7 +1398,7 @@ tree.functions = {
} else if (typeof(n) === 'number') {
return Math.round(n);
} else {
- throw {
+ throw {
error: "RuntimeError",
message: "math functions take numbers as parameters"
};
@@ -1490,7 +1497,7 @@ tree.Call.prototype = {
}
} else { // 2.
return new(tree.Anonymous)(this.name +
- "(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
+ "(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
}
},
@@ -1545,12 +1552,14 @@ tree.Color.prototype = {
return i.length === 1 ? '0' + i : i;
}).join('');
- if (env && env.compress) {
+ if (env && env.compress && this.compress !== false) {
color = color.split('');
// Convert color to short format
if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
color = color[0] + color[2] + color[4];
+ } else {
+ color = color.join('');
}
}
@@ -1633,7 +1642,7 @@ tree.Comment.prototype = {
//
tree.Dimension = function (value, unit) {
this.value = parseFloat(value);
- this.unit = unit || null;
+ this.unit = unit || '';
};
tree.Dimension.prototype = {
@@ -1986,6 +1995,7 @@ tree.mixin.Definition.prototype = {
frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env)));
return new(tree.Ruleset)(null, this.rules.slice(0)).eval({
+ compress: env.compress,
frames: [this, frame].concat(this.frames, env.frames)
});
},
@@ -2482,37 +2492,34 @@ function writeFile(filename, content) {
// Command line integration via Rhino
(function (args) {
- name = args[1];
- var output = args[2];
+ name = args[0];
+ var output = args[1];
if (!name) {
print('No files present in the fileset; Check your pattern match in build.xml');
- quit(1);
+ return;
}
path = name.split("/");path.pop();path=path.join("/")
var input = readFile(name);
if (!input) {
print('lesscss: couldn\'t open file ' + name);
- quit(1);
+ return;
}
var result;
var parser = new less.Parser();
- parser.parse(input, function(e, root) {
+ parser.parse(input, function (e, root) {
if (e) {
- quit(1);
+ return;
} else {
- result = root.toCSS({compress: args[0] === "true"});
+ result = root.toCSS();
if (output) {
writeFile(output, result);
- //print("Written to " + output);
} else {
print(result);
}
- quit(0);
}
});
- print("done");
}(arguments));
Oops, something went wrong.

0 comments on commit 8952cb0

Please sign in to comment.