Commit 1154b116 by Aaron Leung

Implemented the 'grayscale' built-in.

parent d2e5b23c
......@@ -119,8 +119,7 @@ namespace Sass {
register_function(darken_sig, darken);
register_function(saturate_sig, saturate);
register_function(desaturate_sig, desaturate);
register_function(adjust_color_sig, adjust_color);
register_function(change_color_sig, change_color);
register_function(grayscale_sig, grayscale);
register_function(invert_sig, invert);
// Opacity Functions
register_function(alpha_sig, alpha);
......@@ -129,6 +128,9 @@ namespace Sass {
register_function(fade_in_sig, fade_in);
register_function(transparentize_sig, transparentize);
register_function(fade_out_sig, fade_out);
// Other Color Functions
register_function(adjust_color_sig, adjust_color);
register_function(change_color_sig, change_color);
// String Functions
register_function(unquote_sig, unquote);
register_function(quote_sig, quote);
......
......@@ -410,6 +410,26 @@ namespace Sass {
new_Node);
}
extern Signature grayscale_sig = "grayscale($color)";
Node grayscale(const Node parameter_names, Environment& bindings, Node_Factory& new_Node) {
Node color(bindings[parameter_names[0].token()]);
if (color.type() != Node::numeric_color) throw_eval_error("argument to 'grayscale' must be a color", color.path(), color.line());
Node hsl_color(rgb_to_hsl(color[0].numeric_value(),
color[1].numeric_value(),
color[2].numeric_value(),
new_Node));
Node result(hsla_impl(hsl_color[0].numeric_value(),
0.0, // desaturate completely
hsl_color[2].numeric_value(),
color[3].numeric_value(),
new_Node));
return new_Node(color.path(), color.line(),
result[0].numeric_value(),
result[1].numeric_value(),
result[2].numeric_value(),
result[3].numeric_value());
}
extern Signature invert_sig = "invert($color)";
Node invert(const Node parameter_names, Environment& bindings, Node_Factory& new_Node) {
Node orig(bindings[parameter_names[0].token()]);
......
......@@ -116,6 +116,9 @@ namespace Sass {
extern Signature desaturate_sig;
Node desaturate(const Node, Environment&, Node_Factory&);
extern Signature grayscale_sig;
Node grayscale(const Node, Environment&, Node_Factory&);
extern Signature invert_sig;
Node invert(const Node, Environment&, Node_Factory&);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment