From eadd7c504152536c149cf7cc07e45ae8eb100640 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 28 Jul 2021 03:09:03 -0400 Subject: [PATCH] support special fns to single channel rgb/rgba/hsl/hsla --- src/builtin/functions/color/hsl.rs | 20 +++++++++++++++++++- src/builtin/functions/color/rgb.rs | 20 +++++++++++++++++++- tests/media.rs | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/builtin/functions/color/hsl.rs b/src/builtin/functions/color/hsl.rs index c3fab2e..fb742eb 100644 --- a/src/builtin/functions/color/hsl.rs +++ b/src/builtin/functions/color/hsl.rs @@ -6,7 +6,7 @@ use num_traits::One; use crate::{ args::CallArgs, color::Color, - common::QuoteKind, + common::{Brackets, ListSeparator, QuoteKind}, error::SassResult, parse::Parser, unit::Unit, @@ -35,6 +35,24 @@ fn inner_hsl(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas .into()); } + if channels.iter().any(Value::is_special_function) { + let channel_sep = if channels.len() < 3 { + ListSeparator::Space + } else { + ListSeparator::Comma + }; + + return Ok(Value::String( + format!( + "{}({})", + name, + Value::List(channels, channel_sep, Brackets::None) + .to_css_string(args.span(), false)? + ), + QuoteKind::None, + )); + } + let lightness = match channels.pop() { Some(Value::Dimension(Some(n), ..)) => n / Number::from(100), Some(Value::Dimension(None, ..)) => todo!(), diff --git a/src/builtin/functions/color/rgb.rs b/src/builtin/functions/color/rgb.rs index 948d4b3..9917d8a 100644 --- a/src/builtin/functions/color/rgb.rs +++ b/src/builtin/functions/color/rgb.rs @@ -5,7 +5,7 @@ use num_traits::One; use crate::{ args::CallArgs, color::Color, - common::QuoteKind, + common::{Brackets, ListSeparator, QuoteKind}, error::SassResult, parse::Parser, unit::Unit, @@ -37,6 +37,24 @@ fn inner_rgb(name: &'static str, mut args: CallArgs, parser: &mut Parser) -> Sas .into()); } + if channels.iter().any(Value::is_special_function) { + let channel_sep = if channels.len() < 3 { + ListSeparator::Space + } else { + ListSeparator::Comma + }; + + return Ok(Value::String( + format!( + "{}({})", + name, + Value::List(channels, channel_sep, Brackets::None) + .to_css_string(args.span(), false)? + ), + QuoteKind::None, + )); + } + let blue = match channels.pop() { Some(Value::Dimension(Some(n), Unit::None, _)) => n, Some(Value::Dimension(Some(n), Unit::Percent, _)) => { diff --git a/tests/media.rs b/tests/media.rs index 0231868..617299a 100644 --- a/tests/media.rs +++ b/tests/media.rs @@ -233,7 +233,7 @@ test!( "@media (max-width: 0px) {\n a {\n color: red;\n }\n}\n\na {\n color: red;\n}\n" ); test!( - #[ignore = "we move to top of media"] + #[ignore = "we move to top of media"] plain_import_inside_media_is_not_moved_to_top, r#"@media foo { a {