From 3e0c012e0abd73c54f6a912046863b566ad343bf Mon Sep 17 00:00:00 2001 From: Lucas Green Date: Wed, 9 May 2012 01:08:26 -0700 Subject: [PATCH 1/4] Added: red() green() and blue() functions --- lib/less/functions.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index 6eb34bac8..aee81b51a 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -41,6 +41,15 @@ tree.functions = { lightness: function (color) { return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%'); }, + red: function (color) { + return new(tree.Dimension)(parseInt(color.toARGB().substr(3, 2), 16)); + }, + green: function (color) { + return new(tree.Dimension)(parseInt(color.toARGB().substr(5, 2), 16)); + }, + blue: function (color) { + return new(tree.Dimension)(parseInt(color.toARGB().substr(7, 2), 16)); + }, alpha: function (color) { return new(tree.Dimension)(color.toHSL().a); }, @@ -225,4 +234,4 @@ function clamp(val) { return Math.min(1, Math.max(0, val)); } -})(require('./tree')); +})(require('./tree')); \ No newline at end of file From a7f518e952a68158f8b5d0fcd0cffec92bdb79f4 Mon Sep 17 00:00:00 2001 From: Lucas Green Date: Wed, 9 May 2012 01:09:37 -0700 Subject: [PATCH 2/4] Added: test for new red() green() and blue() functions --- test/less/functions.less | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/less/functions.less b/test/less/functions.less index c111f7e56..ef81b6fc8 100644 --- a/test/less/functions.less +++ b/test/less/functions.less @@ -26,6 +26,9 @@ hue: hue(hsl(98, 12%, 95%)); saturation: saturation(hsl(98, 12%, 95%)); lightness: lightness(hsl(98, 12%, 95%)); + red: red(#f00); + green: green(#0f0); + blue: blue(#00f); rounded: round(@r/3); roundedpx: round(10px / 3); percentage: percentage(10px / 50); @@ -46,4 +49,4 @@ #alpha { alpha: darken(hsla(25, 50%, 50%, 0.6), 10%); -} +} \ No newline at end of file From d1c96d384e2213836d7678acb5e5d7330e7d9572 Mon Sep 17 00:00:00 2001 From: Lucas Green Date: Wed, 9 May 2012 01:10:24 -0700 Subject: [PATCH 3/4] Added: expected results for red() green() and blue() function tests --- test/css/functions.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/css/functions.css b/test/css/functions.css index a0f9bd03c..42d980189 100644 --- a/test/css/functions.css +++ b/test/css/functions.css @@ -22,6 +22,9 @@ hue: 98; saturation: 12%; lightness: 95%; + red: 255; + green: 255; + blue: 255; rounded: 11; roundedpx: 3px; percentage: 20%; @@ -40,4 +43,4 @@ } #alpha { alpha: rgba(153, 94, 51, 0.6); -} +} \ No newline at end of file From 4d082e7a068fd78767a99b54112ab694a5f13ac5 Mon Sep 17 00:00:00 2001 From: Lucas Green Date: Tue, 15 May 2012 10:37:00 -0700 Subject: [PATCH 4/4] Cleaned out uneccessary string conversion. --- lib/less/functions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/less/functions.js b/lib/less/functions.js index aee81b51a..6d57e17ab 100644 --- a/lib/less/functions.js +++ b/lib/less/functions.js @@ -42,13 +42,13 @@ tree.functions = { return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%'); }, red: function (color) { - return new(tree.Dimension)(parseInt(color.toARGB().substr(3, 2), 16)); + return new(tree.Dimension)(color.rgb[0]); }, green: function (color) { - return new(tree.Dimension)(parseInt(color.toARGB().substr(5, 2), 16)); + return new(tree.Dimension)(color.rgb[1]); }, blue: function (color) { - return new(tree.Dimension)(parseInt(color.toARGB().substr(7, 2), 16)); + return new(tree.Dimension)(color.rgb[2]); }, alpha: function (color) { return new(tree.Dimension)(color.toHSL().a); @@ -234,4 +234,4 @@ function clamp(val) { return Math.min(1, Math.max(0, val)); } -})(require('./tree')); \ No newline at end of file +})(require('./tree'));