Put max_args! everywhere
This commit is contained in:
parent
46f2d4c47e
commit
0aac40441d
@ -49,24 +49,28 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha)))
|
Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha)))
|
||||||
});
|
});
|
||||||
decl!(f "hue", |args, _| {
|
decl!(f "hue", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "saturation", |args, _| {
|
decl!(f "saturation", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "lightness", |args, _| {
|
decl!(f "lightness", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "adjust-hue", |args, _| {
|
decl!(f "adjust-hue", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -78,6 +82,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.adjust_hue(degrees)))
|
Ok(Value::Color(color.adjust_hue(degrees)))
|
||||||
});
|
});
|
||||||
decl!(f "lighten", |args, _| {
|
decl!(f "lighten", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -89,6 +94,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.lighten(amount)))
|
Ok(Value::Color(color.lighten(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "darken", |args, _| {
|
decl!(f "darken", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -100,6 +106,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.darken(amount)))
|
Ok(Value::Color(color.darken(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "saturate", |args, _| {
|
decl!(f "saturate", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -111,6 +118,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.saturate(amount)))
|
Ok(Value::Color(color.saturate(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "desaturate", |args, _| {
|
decl!(f "desaturate", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -122,6 +130,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.desaturate(amount)))
|
Ok(Value::Color(color.desaturate(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "grayscale", |args, _| {
|
decl!(f "grayscale", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -129,6 +138,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.desaturate(Number::from(1))))
|
Ok(Value::Color(color.desaturate(Number::from(1))))
|
||||||
});
|
});
|
||||||
decl!(f "complement", |args, _| {
|
decl!(f "complement", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -136,6 +146,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.complement()))
|
Ok(Value::Color(color.complement()))
|
||||||
});
|
});
|
||||||
decl!(f "invert", |args, _| {
|
decl!(f "invert", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
|
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
|
||||||
Value::Dimension(n, _) => n / Number::from(100),
|
Value::Dimension(n, _) => n / Number::from(100),
|
||||||
v => return Err(format!("$weight: {} is not a number.", v).into()),
|
v => return Err(format!("$weight: {} is not a number.", v).into()),
|
||||||
|
@ -7,12 +7,14 @@ use crate::value::Value;
|
|||||||
|
|
||||||
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
||||||
decl!(f "alpha", |args, _| {
|
decl!(f "alpha", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "opacity", |args, _| {
|
decl!(f "opacity", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
|
||||||
Value::Dimension(num, unit) => Ok(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)),
|
Value::Dimension(num, unit) => Ok(Value::Ident(format!("opacity({}{})", num , unit), QuoteKind::None)),
|
||||||
@ -20,6 +22,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "opacify", |args, _| {
|
decl!(f "opacify", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -31,6 +34,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.fade_in(amount)))
|
Ok(Value::Color(color.fade_in(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "fade-in", |args, _| {
|
decl!(f "fade-in", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -42,6 +46,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.fade_in(amount)))
|
Ok(Value::Color(color.fade_in(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "transparentize", |args, _| {
|
decl!(f "transparentize", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
@ -53,6 +58,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
Ok(Value::Color(color.fade_out(amount)))
|
Ok(Value::Color(color.fade_out(amount)))
|
||||||
});
|
});
|
||||||
decl!(f "fade-out", |args, _| {
|
decl!(f "fade-out", |args, _| {
|
||||||
|
max_args!(args, 2);
|
||||||
let color = match arg!(args, 0, "color").eval() {
|
let color = match arg!(args, 0, "color").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
|
@ -155,24 +155,28 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "red", |args, _| {
|
decl!(f "red", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "green", |args, _| {
|
decl!(f "green", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "blue", |args, _| {
|
decl!(f "blue", |args, _| {
|
||||||
|
max_args!(args, 1);
|
||||||
match arg!(args, 0, "color") {
|
match arg!(args, 0, "color") {
|
||||||
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
|
||||||
v => return Err(format!("$color: {} is not a color.", v).into()),
|
v => return Err(format!("$color: {} is not a color.", v).into()),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
decl!(f "mix", |args, _| {
|
decl!(f "mix", |args, _| {
|
||||||
|
max_args!(args, 3);
|
||||||
let color1 = match arg!(args, 0, "color1").eval() {
|
let color1 = match arg!(args, 0, "color1").eval() {
|
||||||
Value::Color(c) => c,
|
Value::Color(c) => c,
|
||||||
v => return Err(format!("$color1: {} is not a color.", v).into()),
|
v => return Err(format!("$color1: {} is not a color.", v).into()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user