Futz with the style

This commit is contained in:
Zanie Blue 2025-09-23 09:42:43 -05:00
parent 25b2974fb0
commit 719d2d0343
5 changed files with 721 additions and 550 deletions

View File

@ -99,12 +99,24 @@ fn generate() -> String {
} }
/// Render an environment variable and its documentation. /// Render an environment variable and its documentation.
fn render(var: &str, doc: &str, since: Option<&str>) -> String { fn render(var: &str, doc: &str, added_in: Option<&str>) -> String {
if let Some(since) = since { let mut output = String::new();
format!("### `{var}`\n<small>Since `{since}`</small>\n\n{doc}\n\n")
} else { output.push_str(&format!("<h3 id=\"{}\">\n", var.to_lowercase(),));
format!("### `{var}`\n\n{doc}\n\n") output.push_str(&format!(
"<a class=\"toclink\" href=\"#{}\"><code>{var}</code></a>",
var.to_lowercase()
));
if let Some(added_in) = added_in {
output.push_str(&format!(
" <small class=\"env-reference\">added in v{added_in}</small>"
));
} }
output.push_str("</h3>\n");
output.push_str("\n\n");
output.push_str(doc);
output.push_str("\n\n");
output
} }
#[cfg(test)] #[cfg(test)]

View File

@ -77,10 +77,10 @@ fn get_env_var_pattern_from_attr(attrs: &[Attribute]) -> Option<String> {
.map(|lit_str| lit_str.value()) .map(|lit_str| lit_str.value())
} }
fn get_since(attrs: &[Attribute]) -> Option<String> { fn get_added_in(attrs: &[Attribute]) -> Option<String> {
attrs attrs
.iter() .iter()
.find(|a| a.path().is_ident("attr_since")) .find(|a| a.path().is_ident("attr_added_in"))
.and_then(|attr| attr.parse_args::<LitStr>().ok()) .and_then(|attr| attr.parse_args::<LitStr>().ok())
.map(|lit_str| lit_str.value()) .map(|lit_str| lit_str.value())
} }
@ -101,15 +101,15 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To
ImplItem::Const(item) if !is_hidden(&item.attrs) => { ImplItem::Const(item) if !is_hidden(&item.attrs) => {
let name = item.ident.to_string(); let name = item.ident.to_string();
let doc = get_doc_comment(&item.attrs); let doc = get_doc_comment(&item.attrs);
let since = get_since(&item.attrs); let added_in = get_added_in(&item.attrs);
Some((name, doc, since)) Some((name, doc, added_in))
} }
ImplItem::Fn(item) if !is_hidden(&item.attrs) => { ImplItem::Fn(item) if !is_hidden(&item.attrs) => {
// Extract the environment variable patterns. // Extract the environment variable patterns.
if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) { if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) {
let doc = get_doc_comment(&item.attrs); let doc = get_doc_comment(&item.attrs);
let since = get_since(&item.attrs); let added_in = get_added_in(&item.attrs);
Some((pattern, doc, since)) Some((pattern, doc, added_in))
} else { } else {
None // Skip if pattern extraction fails. None // Skip if pattern extraction fails.
} }
@ -119,8 +119,8 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To
.collect(); .collect();
let struct_name = &ast.self_ty; let struct_name = &ast.self_ty;
let pairs = constants.iter().map(|(name, doc, since)| { let pairs = constants.iter().map(|(name, doc, added_in)| {
if let Some(s) = since { if let Some(s) = added_in {
quote! { (#name, #doc, Some(#s)) } quote! { (#name, #doc, Some(#s)) }
} else { } else {
quote! { (#name, #doc, None) } quote! { (#name, #doc, None) }
@ -152,6 +152,6 @@ pub fn attr_env_var_pattern(_attr: TokenStream, item: TokenStream) -> TokenStrea
} }
#[proc_macro_attribute] #[proc_macro_attribute]
pub fn attr_since(_attr: TokenStream, item: TokenStream) -> TokenStream { pub fn attr_added_in(_attr: TokenStream, item: TokenStream) -> TokenStream {
item item
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -202,9 +202,8 @@ because the nav is in a hamburger menu anyway
.cli-reference ul { .cli-reference ul {
margin-bottom: 0.1em; margin-bottom: 0.1em;
} }
h3.cli-reference { small.env-reference {
font-size: 1.1em; font-size: 60%;
margin: 0 0 0 0;
} }
/* Styling for anchor link headers */ /* Styling for anchor link headers */