|
1 | 1 | use proc_macro2::TokenStream; |
2 | 2 | use quote::*; |
3 | 3 | use rustc_hash::FxHashMap; |
| 4 | +use std::fmt::Write; |
4 | 5 | use std::ops::RangeInclusive; |
5 | 6 | use syn::parse::*; |
6 | 7 | use syn::punctuated::Punctuated; |
@@ -851,11 +852,58 @@ impl ToTokens for StyleSyntaxDefinition { |
851 | 852 | } |
852 | 853 | }); |
853 | 854 |
|
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 | + } |
856 | 900 | 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 | + ]; |
859 | 907 | }); |
860 | 908 | } |
861 | 909 | } |
|
0 commit comments