More error messages!
This commit is contained in:
parent
402d36133c
commit
bbf0cd7e51
@ -9,20 +9,20 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "alpha", |args, _| {
|
||||
match arg!(args, 0, "color") {
|
||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||
_ => todo!("non-color given to builtin function `alpha()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "opacity", |args, _| {
|
||||
match arg!(args, 0, "color") {
|
||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||
Value::Dimension(num, unit) => Ok(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)),
|
||||
_ => todo!("non-color given to builtin function `opacity()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
}
|
||||
});
|
||||
decl!(f "opacify", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
_ => todo!("non-color given to builtin function `opacify()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
let amount = match arg!(args, 1, "amount").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
@ -34,7 +34,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "fade-in", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
_ => todo!("non-color given to builtin function `fade-in()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
let amount = match arg!(args, 1, "amount").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
@ -46,7 +46,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "transparentize", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
_ => todo!("non-color given to builtin function `transparentize()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
let amount = match arg!(args, 1, "amount").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
@ -58,7 +58,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "fade-out", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
_ => todo!("non-color given to builtin function `fade-out()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
let amount = match arg!(args, 1, "amount").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
|
@ -30,7 +30,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "change-color", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c,
|
||||
_ => todo!("non-color given to builtin function `change-color()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
|
||||
opt_arg!(args, alpha, "alpha");
|
||||
@ -68,7 +68,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "adjust-color", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c.clone(),
|
||||
_ => todo!("non-color given to builtin function `adjust-color()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
|
||||
opt_arg!(args, alpha, "alpha");
|
||||
@ -122,7 +122,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "scale-color", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c.clone(),
|
||||
_ => todo!("non-color given to builtin function `scale-color()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
|
||||
opt_arg!(args, alpha, "alpha");
|
||||
@ -176,7 +176,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
decl!(f "ie-hex-str", |args, _| {
|
||||
let color = match arg!(args, 0, "color").eval() {
|
||||
Value::Color(c) => c.clone(),
|
||||
_ => todo!("non-color given to builtin function `ie-hex-str()`")
|
||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||
};
|
||||
Ok(Value::Ident(color.to_ie_hex_str(), QuoteKind::None))
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
if args.len() == 1 {
|
||||
let mut channels = match arg!(args, 0, "channels").eval() {
|
||||
Value::List(v, _) => v,
|
||||
_ => todo!("missing element $green")
|
||||
_ => return Err("Missing argument $channels.".into())
|
||||
};
|
||||
|
||||
assert_eq!(channels.len(), 3_usize);
|
||||
@ -18,19 +18,22 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
let blue = match channels.pop() {
|
||||
Some(Value::Dimension(n, Unit::None)) => n,
|
||||
Some(Value::Dimension(n, Unit::Percent)) => n / Number::from(100),
|
||||
_ => todo!("$blue: ___ is not a color")
|
||||
Some(v) => return Err(format!("$blue: {} is not a color", v).into()),
|
||||
None => return Err("Missing element $blue.".into()),
|
||||
};
|
||||
|
||||
let green = match channels.pop() {
|
||||
Some(Value::Dimension(n, Unit::None)) => n,
|
||||
Some(Value::Dimension(n, Unit::Percent)) => n / Number::from(100),
|
||||
_ => todo!("$green: ___ is not a color")
|
||||
Some(v) => return Err(format!("$green: {} is not a color", v).into()),
|
||||
None => return Err("Missing element $green.".into()),
|
||||
};
|
||||
|
||||
let red = match channels.pop() {
|
||||
Some(Value::Dimension(n, Unit::None)) => n,
|
||||
Some(Value::Dimension(n, Unit::Percent)) => n / Number::from(100),
|
||||
_ => todo!("$red: ___ is not a color")
|
||||
Some(v) => return Err(format!("$red: {} is not a color", v).into()),
|
||||
None => return Err("Missing element $red.".into()),
|
||||
};
|
||||
|
||||
let color = Color::from_rgba(red, green, blue, Number::from(1));
|
||||
@ -52,7 +55,8 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||
let red = match arg!(args, 0, "red").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
Value::Dimension(n, Unit::Percent) => (n / Number::from(100)) * Number::from(255),
|
||||
_ => todo!("expected either unitless or % number for alpha"),
|
||||
v @ Value::Dimension(..) => return Err(format!("Expected {} to have no units or \"%\".", v).into()),
|
||||
v => return Err(format!("$red: {} is not a number.", v).into()),
|
||||
};
|
||||
let green = match arg!(args, 1, "green").eval() {
|
||||
Value::Dimension(n, Unit::None) => n,
|
||||
|
Loading…
x
Reference in New Issue
Block a user