From 2a6ec38fd49da7ef8722c80ae4c1f63f7ffd761d Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 8 Feb 2020 18:55:48 -0500 Subject: [PATCH] Special case builtin function `opacity(number)` --- src/builtin/color.rs | 2 ++ tests/color.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/builtin/color.rs b/src/builtin/color.rs index f4e41c7..1d845d4 100644 --- a/src/builtin/color.rs +++ b/src/builtin/color.rs @@ -6,6 +6,7 @@ use num_rational::BigRational; use super::Builtin; use crate::color::Color; +use crate::common::QuoteKind; use crate::units::Unit; use crate::value::{Number, Value}; @@ -42,6 +43,7 @@ pub(crate) fn register(f: &mut BTreeMap) { decl!(f "opacity", |args, _| { match arg!(args, 0, "color") { Value::Color(c) => Some(Value::Dimension(Number::new(BigRational::new(BigInt::from(c.alpha()), BigInt::from(255))), Unit::None)), + Value::Dimension(num, unit) => Some(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)), _ => todo!("non-color given to builtin function `opacity()`") } }); diff --git a/tests/color.rs b/tests/color.rs index ff23f69..02397a7 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -56,3 +56,11 @@ test!( "a {\n color: alpha(red);\n}\n", "a {\n color: 1;\n}\n" ); +test!( + opacity_function_number, + "a {\n color: opacity(1);\n}\n" +); +test!( + opacity_function_number_unit, + "a {\n color: opacity(1px);\n}\n" +);