improve rgb(a)/hsl(a) 1 arg errors
This commit is contained in:
parent
98a99684b7
commit
2698e8257b
@ -19,7 +19,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
let mut channels = match arg!(args, 0, "channels") {
|
let mut channels = match arg!(args, 0, "channels") {
|
||||||
Value::List(v, _) => v,
|
Value::List(v, _) => v,
|
||||||
_ => return Err("Missing element $green.".into()),
|
_ => return Err("Missing argument $channels.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if channels.len() > 3 {
|
if channels.len() > 3 {
|
||||||
@ -32,19 +32,19 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
|
|
||||||
let luminance = match channels.pop() {
|
let luminance = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
||||||
Some(v) => return Err(format!("$luminance: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$luminance: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $luminance.".into()),
|
None => return Err("Missing element $luminance.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let saturation = match channels.pop() {
|
let saturation = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
||||||
Some(v) => return Err(format!("$saturation: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$saturation: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $saturation.".into()),
|
None => return Err("Missing element $saturation.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let hue = match channels.pop() {
|
let hue = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n,
|
Some(Value::Dimension(n, _)) => n,
|
||||||
Some(v) => return Err(format!("$hue: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$hue: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $hue.".into()),
|
None => return Err("Missing element $hue.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
let mut channels = match arg!(args, 0, "channels") {
|
let mut channels = match arg!(args, 0, "channels") {
|
||||||
Value::List(v, _) => v,
|
Value::List(v, _) => v,
|
||||||
_ => return Err("Missing element $green.".into()),
|
_ => return Err("Missing argument $channels.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if channels.len() > 3 {
|
if channels.len() > 3 {
|
||||||
@ -110,19 +110,19 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
|
|
||||||
let luminance = match channels.pop() {
|
let luminance = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
||||||
Some(v) => return Err(format!("$luminance: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$luminance: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $luminance.".into()),
|
None => return Err("Missing element $luminance.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let saturation = match channels.pop() {
|
let saturation = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
Some(Value::Dimension(n, _)) => n / Number::from(100),
|
||||||
Some(v) => return Err(format!("$saturation: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$saturation: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $saturation.".into()),
|
None => return Err("Missing element $saturation.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let hue = match channels.pop() {
|
let hue = match channels.pop() {
|
||||||
Some(Value::Dimension(n, _)) => n,
|
Some(Value::Dimension(n, _)) => n,
|
||||||
Some(v) => return Err(format!("$hue: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$hue: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $hue.".into()),
|
None => return Err("Missing element $hue.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
let mut channels = match arg!(args, 0, "channels") {
|
let mut channels = match arg!(args, 0, "channels") {
|
||||||
Value::List(v, _) => v,
|
Value::List(v, _) => v,
|
||||||
_ => return Err("Missing element $green.".into()),
|
_ => return Err("Missing argument $channels.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if channels.len() > 3 {
|
if channels.len() > 3 {
|
||||||
@ -34,7 +34,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$blue: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$blue: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $blue.".into()),
|
None => return Err("Missing element $blue.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$green: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$green: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $green.".into()),
|
None => return Err("Missing element $green.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$red: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$red: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $red.".into()),
|
None => return Err("Missing element $red.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
let mut channels = match arg!(args, 0, "channels") {
|
let mut channels = match arg!(args, 0, "channels") {
|
||||||
Value::List(v, _) => v,
|
Value::List(v, _) => v,
|
||||||
_ => return Err("Missing element $green.".into()),
|
_ => return Err("Missing argument $channels.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if channels.len() > 3 {
|
if channels.len() > 3 {
|
||||||
@ -156,7 +156,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$blue: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$blue: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $blue.".into()),
|
None => return Err("Missing element $blue.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$green: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$green: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $green.".into()),
|
None => return Err("Missing element $green.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Some(Value::Dimension(n, Unit::Percent)) => {
|
Some(Value::Dimension(n, Unit::Percent)) => {
|
||||||
(n / Number::from(100)) * Number::from(255)
|
(n / Number::from(100)) * Number::from(255)
|
||||||
}
|
}
|
||||||
Some(v) => return Err(format!("$red: {} is not a color", v).into()),
|
Some(v) => return Err(format!("$red: {} is not a number", v).into()),
|
||||||
None => return Err("Missing element $red.".into()),
|
None => return Err("Missing element $red.".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user