Put max_args! everywhere

This commit is contained in:
ConnorSkees 2020-02-16 12:35:03 -05:00
parent 46f2d4c47e
commit 0aac40441d
3 changed files with 21 additions and 0 deletions

View File

@ -49,24 +49,28 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
Ok(Value::Color(Color::from_hsla(hue, saturation, luminance, alpha)))
});
decl!(f "hue", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.hue(), Unit::Deg)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "saturation", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.saturation(), Unit::Percent)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "lightness", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.lightness(), Unit::Percent)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "adjust-hue", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "lighten", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "darken", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "saturate", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "desaturate", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "grayscale", |args, _| {
max_args!(args, 1);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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))))
});
decl!(f "complement", |args, _| {
max_args!(args, 1);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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()))
});
decl!(f "invert", |args, _| {
max_args!(args, 2);
let weight = match arg!(args, 1, "weight"=Value::Dimension(Number::from(100), Unit::Percent)) {
Value::Dimension(n, _) => n / Number::from(100),
v => return Err(format!("$weight: {} is not a number.", v).into()),

View File

@ -7,12 +7,14 @@ use crate::value::Value;
pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
decl!(f "alpha", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "opacity", |args, _| {
max_args!(args, 1);
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)),
@ -20,6 +22,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
}
});
decl!(f "opacify", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "fade-in", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "transparentize", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
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)))
});
decl!(f "fade-out", |args, _| {
max_args!(args, 2);
let color = match arg!(args, 0, "color").eval() {
Value::Color(c) => c,
v => return Err(format!("$color: {} is not a color.", v).into()),

View File

@ -155,24 +155,28 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
}
});
decl!(f "red", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.red(), Unit::None)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "green", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.green(), Unit::None)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "blue", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.blue(), Unit::None)),
v => return Err(format!("$color: {} is not a color.", v).into()),
}
});
decl!(f "mix", |args, _| {
max_args!(args, 3);
let color1 = match arg!(args, 0, "color1").eval() {
Value::Color(c) => c,
v => return Err(format!("$color1: {} is not a color.", v).into()),