Skip to content

Commit a5cd4ed

Browse files
committed
feat: add supported CSS property docs
1 parent 4c8589f commit a5cd4ed

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

float-pigment-css-macro/src/style_syntax.rs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use proc_macro2::TokenStream;
22
use quote::*;
33
use rustc_hash::FxHashMap;
4+
use std::fmt::Write;
45
use std::ops::RangeInclusive;
56
use syn::parse::*;
67
use syn::punctuated::Punctuated;
@@ -851,11 +852,58 @@ impl ToTokens for StyleSyntaxDefinition {
851852
}
852853
});
853854

854-
// a pub mod for docs
855-
let mod_doc = format!("!!! TODO");
855+
// the supported property list
856+
let mut supported_properties: Vec<_> = items.iter().filter(|x| x.name.is_some()).collect();
857+
supported_properties.sort_by(|a, b| {
858+
let a = a.name.as_ref().unwrap();
859+
let b = b.name.as_ref().unwrap();
860+
a.cmp(b)
861+
});
862+
let supported_property_count = supported_properties.len();
863+
let supported_property_names = supported_properties.iter().map(|x| x.name.as_ref().unwrap());
864+
let mut style_doc = String::new();
865+
writeln!(&mut style_doc, "The supported CSS property names.\n").unwrap();
866+
writeln!(&mut style_doc, "This list is sorted, so it is safe to do binary search on it.\n").unwrap();
867+
writeln!(&mut style_doc, "Note that this is just a simple list of basic parsing rules.\n").unwrap();
868+
writeln!(&mut style_doc, "* Some properties in this list are shorthand properties that cannot be found in the [Property] enum.").unwrap();
869+
writeln!(&mut style_doc, "* Parsing rules of some properties are slightly different from the web standard.").unwrap();
870+
writeln!(&mut style_doc, "\nSee the table below for more information about all supported properties.\n").unwrap();
871+
writeln!(&mut style_doc, "| Property Name | Related Property Variant | Major Value Options |").unwrap();
872+
writeln!(&mut style_doc, "| ---- | ---- | ---- |").unwrap();
873+
let table_list_a = supported_properties
874+
.iter()
875+
.filter(|x| !x.name.as_ref().unwrap().starts_with("-"));
876+
let table_list_b = supported_properties
877+
.iter()
878+
.filter(|x| x.name.as_ref().unwrap().starts_with("-"));
879+
for x in table_list_a.chain(table_list_b) {
880+
let name = x.name.as_ref().unwrap();
881+
let non_standard = name.starts_with("-");
882+
let name_col = if non_standard { format!("*`{}`*", name) } else { format!("`{}`", name) };
883+
let mut doc_col = String::new();
884+
let mut options_col = vec![];
885+
if let StyleSyntaxValueItem::Assign(variant, v) = &x.value {
886+
doc_col = format!("[Property::{}]", variant);
887+
if let StyleSyntaxValueItem::Branch(branches) = &**v {
888+
for item in branches {
889+
if let StyleSyntaxValueItem::Convert(v, _) = item {
890+
if let StyleSyntaxValueItem::MatchIdent(s) = &**v {
891+
options_col.push(format!("`{}`", s));
892+
}
893+
}
894+
}
895+
}
896+
}
897+
options_col.sort();
898+
writeln!(&mut style_doc, "| {} | {} | {} |", name_col, doc_col, options_col.join("<br>")).unwrap();
899+
}
856900
tokens.append_all(quote! {
857-
#[doc = #mod_doc]
858-
pub mod style_properties {}
901+
#[doc = #style_doc]
902+
pub const SUPPORTED_CSS_PROPERTY_NAMES: [&'static str; #supported_property_count] = [
903+
#(
904+
#supported_property_names,
905+
)*
906+
];
859907
});
860908
}
861909
}

float-pigment-css-macro/src/value_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ impl Parse for PropertyValueType {
3939
Unset,
4040
Var(Box<StrRef>),
4141
VarInShorthand(Box<StrRef>, Box<StrRef>),
42-
Invalid0,
42+
#[doc(hidden)] Invalid0,
4343
}
4444
"#;
4545
let mut new_variants = parse_str::<ItemEnum>(s)?.variants;
4646
for i in new_variants.len()..PRESERVE_GLOBAL_VALUE_RANGE {
4747
let mut empty_slot = new_variants.last().unwrap().clone();
4848
empty_slot.ident = Ident::new(&format!("Invalid{:X}", i), empty_slot.ident.span());
49+
empty_slot.attrs.push(parse_quote!(#[doc(hidden)]));
4950
new_variants.push(empty_slot);
5051
}
5152
new_variants

float-pigment-css/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//!
2222
//! The supported media features can be found in [MediaQueryStatus] docs.
2323
//!
24-
//! The supported style properties can be found in [style_properties](crate::property::style_properties) module docs.
24+
//! The supported style properties can be found in [SUPPORTED_CSS_PROPERTY_NAMES](crate::property::SUPPORTED_CSS_PROPERTY_NAMES) docs.
2525
//!
2626
//! ### The Binary Format
2727
//!

0 commit comments

Comments
 (0)