mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Introduce #[css(if_empty = "…", iterable)]
This commit is contained in:
parent
92f116a95c
commit
90b23963b7
4 changed files with 48 additions and 80 deletions
|
@ -150,6 +150,20 @@ fn derive_single_field_expr(
|
|||
where_clause: &mut WhereClause,
|
||||
) -> Tokens {
|
||||
if attrs.iterable {
|
||||
if let Some(if_empty) = attrs.if_empty {
|
||||
return quote! {
|
||||
{
|
||||
let mut iter = #field.iter().peekable();
|
||||
if iter.peek().is_none() {
|
||||
writer.item(&::style_traits::values::Verbatim(#if_empty))?;
|
||||
} else {
|
||||
for item in iter {
|
||||
writer.item(&item)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
quote! {
|
||||
for item in #field.iter() {
|
||||
writer.item(&item)?;
|
||||
|
@ -186,6 +200,7 @@ pub struct CssVariantAttrs {
|
|||
#[darling(attributes(css), default)]
|
||||
#[derive(Default, FromField)]
|
||||
struct CssFieldAttrs {
|
||||
if_empty: Option<String>,
|
||||
ignore_bound: bool,
|
||||
iterable: bool,
|
||||
skip: bool,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue