alias sass:list
builtin functions
This commit is contained in:
parent
d6126110e9
commit
21e096247e
@ -11,7 +11,7 @@ use crate::{
|
||||
value::{Number, Value},
|
||||
};
|
||||
|
||||
fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
Ok(Value::Dimension(
|
||||
Number::from(args.get_err(0, "list")?.as_list().len()),
|
||||
@ -20,7 +20,7 @@ fn length(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
))
|
||||
}
|
||||
|
||||
fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(2)?;
|
||||
let mut list = args.get_err(0, "list")?.as_list();
|
||||
let n = match args.get_err(1, "n")? {
|
||||
@ -61,7 +61,7 @@ fn nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
Ok(Value::String(
|
||||
match args.get_err(0, "list")? {
|
||||
@ -73,7 +73,7 @@ fn list_separator(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Val
|
||||
))
|
||||
}
|
||||
|
||||
fn set_nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn set_nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(3)?;
|
||||
let (mut list, sep, brackets) = match args.get_err(0, "list")? {
|
||||
Value::List(v, sep, b) => (v, sep, b),
|
||||
@ -120,7 +120,7 @@ fn set_nth(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
Ok(Value::List(list, sep, brackets))
|
||||
}
|
||||
|
||||
fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(3)?;
|
||||
let (mut list, sep, brackets) = match args.get_err(0, "list")? {
|
||||
Value::List(v, sep, b) => (v, sep, b),
|
||||
@ -158,7 +158,7 @@ fn append(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
Ok(Value::List(list, sep, brackets))
|
||||
}
|
||||
|
||||
fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(4)?;
|
||||
let (mut list1, sep1, brackets) = match args.get_err(0, "list1")? {
|
||||
Value::List(v, sep, brackets) => (v, sep, brackets),
|
||||
@ -225,7 +225,7 @@ fn join(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
Ok(Value::List(list1, sep, brackets))
|
||||
}
|
||||
|
||||
fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
Ok(Value::bool(match args.get_err(0, "list")? {
|
||||
Value::List(.., brackets) => match brackets {
|
||||
@ -236,7 +236,7 @@ fn is_bracketed(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value
|
||||
}))
|
||||
}
|
||||
|
||||
fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(2)?;
|
||||
let list = args.get_err(0, "list")?.as_list();
|
||||
let value = args.get_err(1, "value")?;
|
||||
@ -247,7 +247,7 @@ fn index(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
Ok(Value::Dimension(index, Unit::None, true))
|
||||
}
|
||||
|
||||
fn zip(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
pub(crate) fn zip(args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
let lists = args
|
||||
.get_variadic()?
|
||||
.into_iter()
|
||||
|
@ -1,4 +1,4 @@
|
||||
mod functions;
|
||||
pub(crate) mod modules;
|
||||
|
||||
pub(crate) use functions::{math, meta, selector, Builtin, GLOBAL_FUNCTIONS};
|
||||
pub(crate) use functions::{list, math, meta, selector, Builtin, GLOBAL_FUNCTIONS};
|
||||
|
@ -1,5 +1,22 @@
|
||||
use crate::{
|
||||
args::CallArgs, builtin::modules::Module, error::SassResult, parse::Parser, value::Value,
|
||||
args::CallArgs,
|
||||
builtin::{
|
||||
list::{append, index, is_bracketed, join, length, list_separator, nth, set_nth, zip},
|
||||
modules::Module,
|
||||
},
|
||||
error::SassResult,
|
||||
parse::Parser,
|
||||
value::Value,
|
||||
};
|
||||
|
||||
pub(crate) fn declare(_f: &mut Module) {}
|
||||
pub(crate) fn declare(f: &mut Module) {
|
||||
f.insert_builtin("append", append);
|
||||
f.insert_builtin("index", index);
|
||||
f.insert_builtin("is-bracketed", is_bracketed);
|
||||
f.insert_builtin("join", join);
|
||||
f.insert_builtin("length", length);
|
||||
f.insert_builtin("separator", list_separator);
|
||||
f.insert_builtin("nth", nth);
|
||||
f.insert_builtin("set-nth", set_nth);
|
||||
f.insert_builtin("zip", zip);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user