implement builtin sass:math
variables
This commit is contained in:
parent
060641b86d
commit
15f657df6d
@ -7,7 +7,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
error::SassResult,
|
error::SassResult,
|
||||||
parse::Parser,
|
parse::Parser,
|
||||||
value::Value,
|
unit::Unit,
|
||||||
|
value::{Number, Value},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
@ -85,4 +86,13 @@ pub(crate) fn declare(f: &mut Module) {
|
|||||||
f.insert_builtin("percentage", percentage);
|
f.insert_builtin("percentage", percentage);
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
f.insert_builtin("random", random);
|
f.insert_builtin("random", random);
|
||||||
|
|
||||||
|
f.insert_builtin_var(
|
||||||
|
"pi",
|
||||||
|
Value::Dimension(Number::from(std::f64::consts::PI), Unit::None, true),
|
||||||
|
);
|
||||||
|
f.insert_builtin_var(
|
||||||
|
"e",
|
||||||
|
Value::Dimension(Number::from(std::f64::consts::E), Unit::None, true),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,10 @@ impl Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn insert_builtin_var(&mut self, name: &'static str, value: Value) {
|
||||||
|
self.vars.insert(name.into(), value);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_fn(&self, name: Identifier) -> Option<SassFunction> {
|
pub fn get_fn(&self, name: Identifier) -> Option<SassFunction> {
|
||||||
self.functions.get(&name).cloned()
|
self.functions.get(&name).cloned()
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,7 @@ impl<'a> Parser<'a> {
|
|||||||
) -> SassResult<Spanned<IntermediateValue>> {
|
) -> SassResult<Spanned<IntermediateValue>> {
|
||||||
Ok(IntermediateValue::Value(
|
Ok(IntermediateValue::Value(
|
||||||
if matches!(self.toks.peek(), Some(Token { kind: '$', .. })) {
|
if matches!(self.toks.peek(), Some(Token { kind: '$', .. })) {
|
||||||
|
self.toks.next();
|
||||||
let var = self
|
let var = self
|
||||||
.parse_identifier_no_interpolation(false)?
|
.parse_identifier_no_interpolation(false)?
|
||||||
.map_node(|i| i.into());
|
.map_node(|i| i.into());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user