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.
fn render(var: &str, doc: &str, since: Option<&str>) -> String {
if let Some(since) = since {
format!("### `{var}`\n<small>Since `{since}`</small>\n\n{doc}\n\n")
} else {
format!("### `{var}`\n\n{doc}\n\n")
fn render(var: &str, doc: &str, added_in: Option<&str>) -> String {
let mut output = String::new();
output.push_str(&format!("<h3 id=\"{}\">\n", var.to_lowercase(),));
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)]

View File

@ -77,10 +77,10 @@ fn get_env_var_pattern_from_attr(attrs: &[Attribute]) -> Option<String> {
.map(|lit_str| lit_str.value())
}
fn get_since(attrs: &[Attribute]) -> Option<String> {
fn get_added_in(attrs: &[Attribute]) -> Option<String> {
attrs
.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())
.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) => {
let name = item.ident.to_string();
let doc = get_doc_comment(&item.attrs);
let since = get_since(&item.attrs);
Some((name, doc, since))
let added_in = get_added_in(&item.attrs);
Some((name, doc, added_in))
}
ImplItem::Fn(item) if !is_hidden(&item.attrs) => {
// Extract the environment variable patterns.
if let Some(pattern) = get_env_var_pattern_from_attr(&item.attrs) {
let doc = get_doc_comment(&item.attrs);
let since = get_since(&item.attrs);
Some((pattern, doc, since))
let added_in = get_added_in(&item.attrs);
Some((pattern, doc, added_in))
} else {
None // Skip if pattern extraction fails.
}
@ -119,8 +119,8 @@ pub fn attribute_env_vars_metadata(_attr: TokenStream, input: TokenStream) -> To
.collect();
let struct_name = &ast.self_ty;
let pairs = constants.iter().map(|(name, doc, since)| {
if let Some(s) = since {
let pairs = constants.iter().map(|(name, doc, added_in)| {
if let Some(s) = added_in {
quote! { (#name, #doc, Some(#s)) }
} else {
quote! { (#name, #doc, None) }
@ -152,6 +152,6 @@ pub fn attr_env_var_pattern(_attr: TokenStream, item: TokenStream) -> TokenStrea
}
#[proc_macro_attribute]
pub fn attr_since(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn attr_added_in(_attr: TokenStream, item: TokenStream) -> TokenStream {
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 {
margin-bottom: 0.1em;
}
h3.cli-reference {
font-size: 1.1em;
margin: 0 0 0 0;
small.env-reference {
font-size: 60%;
}
/* Styling for anchor link headers */