const METADATA: &[&str] = &[
"status",
"date",
"keywords",
"category",
"edition",
"organization",
"copyright",
"fixed-point",
"head",
"diff",
"spec",
"standards",
"findings",
"axis",
"severity",
"kind",
"where",
"source",
];
const PAGE_PREFIX: &str = "page-";
pub fn displayed_as(name: &str) -> Option<&str> {
if let Some(rest) = name.strip_prefix(PAGE_PREFIX) {
return (!rest.is_empty()).then_some(rest);
}
METADATA.contains(&name).then_some(name)
}
pub fn label_for(name: &str) -> String {
let spaced = name.replace(['-', '_'], " ");
let mut characters = spaced.chars();
match characters.next() {
Some(first) => first.to_uppercase().collect::<String>() + characters.as_str(),
None => spaced,
}
}
pub fn is_list(name: &str) -> bool {
matches!(name, "tags" | "keywords" | "standards")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_allowlisted_attribute_is_shown_under_its_own_name() {
assert_eq!(displayed_as("keywords"), Some("keywords"));
}
#[test]
fn an_antora_attribute_is_shown_with_the_prefix_dropped() {
assert_eq!(displayed_as("page-tags"), Some("tags"));
}
#[test]
fn an_attribute_nobody_listed_is_not_shown() {
assert_eq!(displayed_as("sectnums"), None);
assert_eq!(displayed_as("page-"), None);
}
#[test]
fn a_label_reads_as_a_sentence() {
assert_eq!(label_for("last-reviewed"), "Last reviewed");
assert_eq!(label_for("fixed_point"), "Fixed point");
}
}