color() function parses color string

This commit is contained in:
Alexis Sellier
2011-12-18 17:29:40 +01:00
parent 6c6cdcb839
commit eadc0d8704
4 changed files with 11 additions and 2 deletions

View File

@@ -170,6 +170,13 @@ tree.functions = {
},
percentage: function(n) {
return new(tree.Dimension)(n.value * 100, '%');
},
color: function (n) {
if (n instanceof tree.Quoted) {
return new(tree.Color)(n.value.slice(1));
} else {
throw { type: "Argument", message: "argument must be a string" };
}
}
};

View File

@@ -25,6 +25,7 @@
rounded: 11;
roundedpx: 3px;
percentage: 20%;
color: #ff0011;
}
#alpha {
alpha: rgba(153, 94, 51, 0.6);

View File

@@ -10,7 +10,7 @@ less.tree.functions.add = function (a, b) {
less.tree.functions.increment = function (a) {
return new(less.tree.Dimension)(a.value + 1);
}
less.tree.functions.color = function (str) {
less.tree.functions._color = function (str) {
if (str.value === "evil red") { return new(less.tree.Color)("600") }
}

View File

@@ -1,6 +1,6 @@
#functions {
@var: 10;
color: color("evil red"); // #660000
color: _color("evil red"); // #660000
width: increment(15);
height: undefined("self");
border-width: add(2, 3);
@@ -29,6 +29,7 @@
rounded: round(@r/3);
roundedpx: round(10px / 3);
percentage: percentage(10px / 50);
color: color("#ff0011");
}
#alpha {