add unit function. Fixes #307

This commit is contained in:
Luke Page
2012-11-27 08:21:21 +00:00
parent dddda0b0d3
commit eabd8ac1ca
3 changed files with 8 additions and 0 deletions

View File

@@ -209,6 +209,9 @@ tree.functions = {
str = str.replace(/%%/g, '%');
return new(tree.Quoted)('"' + str + '"', str);
},
unit: function (val, unit) {
return new(tree.Dimension)(val.value, unit ? unit.toCSS() : "");
},
round: function (n, f) {
var fraction = typeof(f) === "undefined" ? 0 : f.value;
if (n instanceof tree.Dimension) {

View File

@@ -42,6 +42,8 @@
format-multiple: "hello earth 2";
format-url-encode: "red is %23ff0000";
eformat: rgb(32, 128, 64);
unitless: 12;
unit: 14em;
hue: 98;
saturation: 12%;
lightness: 95%;

View File

@@ -46,6 +46,9 @@
format-multiple: %("hello %s %d", "earth", 2);
format-url-encode: %('red is %A', #ff0000);
eformat: e(%("rgb(%d, %d, %d)", @r, 128, 64));
unitless: unit(12px);
unit: unit(13px + 1px, em);
hue: hue(hsl(98, 12%, 95%));
saturation: saturation(hsl(98, 12%, 95%));