style: Move represents_keyword to the css attributes.

Bug: 1457635
Reviewed-by: xidorn
MozReview-Commit-ID: 21yuU4h34AQ
This commit is contained in:
Emilio Cobos Álvarez 2018-04-29 04:48:47 +02:00
parent a375baf84b
commit c508d8576d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
8 changed files with 24 additions and 69 deletions

View file

@ -140,13 +140,13 @@ fn derive_struct_fields<'a>(
values.push(value.to_string());
}
}
if info_attrs.represents_keyword {
let css_attrs = cg::parse_field_attrs::<CssFieldAttrs>(field);
if css_attrs.represents_keyword {
let ident = field.ident.as_ref()
.expect("only named field should use represents_keyword");
values.push(cg::to_css_identifier(ident.as_ref()));
return None;
}
let css_attrs = cg::parse_field_attrs::<CssFieldAttrs>(field);
if let Some(if_empty) = css_attrs.if_empty {
values.push(if_empty);
}
@ -176,6 +176,5 @@ struct ValueInfoVariantAttrs {
#[darling(attributes(value_info), default)]
#[derive(Default, FromField)]
struct ValueInfoFieldAttrs {
represents_keyword: bool,
other_values: Option<String>,
}

View file

@ -189,6 +189,15 @@ fn derive_single_field_expr(
writer.item(&item)?;
}
}
} else if attrs.represents_keyword {
let ident =
field.ast().ident.as_ref().expect("Unnamed field with represents_keyword?");
let ident = cg::to_css_identifier(ident.as_ref());
quote! {
if *#field {
writer.raw_item(#ident)?;
}
}
} else {
if attrs.field_bound {
let ty = &field.ast().ty;
@ -236,5 +245,6 @@ pub struct CssFieldAttrs {
pub field_bound: bool,
pub iterable: bool,
pub skip: bool,
pub represents_keyword: bool,
pub skip_if: Option<Path>,
}