implement builtin function global-var-exists
This commit is contained in:
parent
785c824cd8
commit
b91683b02e
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||
|
||||
use super::{Builtin, GLOBAL_FUNCTIONS};
|
||||
use crate::common::QuoteKind;
|
||||
use crate::scope::global_var_exists;
|
||||
use crate::unit::Unit;
|
||||
use crate::value::Value;
|
||||
|
||||
@ -89,6 +90,16 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
||||
}
|
||||
}),
|
||||
);
|
||||
f.insert(
|
||||
"global-variable-exists".to_owned(),
|
||||
Box::new(|args, _| {
|
||||
max_args!(args, 1);
|
||||
match arg!(args, 0, "name") {
|
||||
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
|
||||
v => Err(format!("$name: {} is not a string.", v).into()),
|
||||
}
|
||||
}),
|
||||
);
|
||||
f.insert(
|
||||
"mixin-exists".to_owned(),
|
||||
Box::new(|args, scope| {
|
||||
|
@ -14,6 +14,10 @@ pub(crate) fn get_global_var(s: &str) -> SassResult<Value> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn global_var_exists(v: &str) -> bool {
|
||||
GLOBAL_SCOPE.with(|scope| scope.borrow().var_exists(v))
|
||||
}
|
||||
|
||||
pub(crate) fn get_global_fn(s: &str) -> SassResult<Function> {
|
||||
GLOBAL_SCOPE.with(|scope| match scope.borrow().functions().get(s) {
|
||||
Some(v) => Ok(v.clone()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user