Current section

Files

Jump to
rbt_weave crates weave-content src html dl.rs
Raw

crates/weave-content/src/html/dl.rs

//! Definition list rendering helpers for entity fields.
use super::countries::{country_name, is_special_scope};
use super::escape::{escape, format_enum};
pub(crate) fn render_dl_field(html: &mut String, label: &str, value: &str) {
if !value.is_empty() {
html.push_str(&format!(
" <span class=\"loom-field\"><strong>{label}:</strong> {}</span>\n",
escape(value)
));
}
}
pub(crate) fn render_dl_field_html(html: &mut String, label: &str, value_html: &str) {
if !value_html.is_empty() {
html.push_str(&format!(
" <span class=\"loom-field\"><strong>{label}:</strong> {value_html}</span>\n"
));
}
}
pub(crate) fn render_dl_opt(html: &mut String, label: &str, value: Option<&String>) {
if let Some(v) = value {
render_dl_field(html, label, v);
}
}
pub(crate) fn render_dl_opt_formatted(html: &mut String, label: &str, value: Option<&String>) {
if let Some(v) = value {
render_dl_field(html, label, &format_enum(v));
}
}
pub(crate) fn render_dl_item(html: &mut String, label: &str, value: &str) {
if !value.is_empty() {
html.push_str(&format!(
" <dt>{label}</dt>\n <dd>{}</dd>\n",
escape(value)
));
}
}
pub(crate) fn render_dl_item_html(html: &mut String, label: &str, value_html: &str) {
if !value_html.is_empty() {
html.push_str(&format!(
" <dt>{label}</dt>\n <dd>{value_html}</dd>\n"
));
}
}
pub(crate) fn render_dl_opt_item(html: &mut String, label: &str, value: Option<&String>) {
if let Some(v) = value {
render_dl_item(html, label, v);
}
}
pub(crate) fn render_dl_countries(html: &mut String, label: &str, values: &[String]) {
if !values.is_empty() {
let linked: Vec<String> = values
.iter()
.map(|code| {
let name = country_name(code);
if is_special_scope(code) {
name
} else {
format!(
"<a href=\"/countries/{}\" class=\"loom-country-link\">{}</a>",
code.to_lowercase(),
name
)
}
})
.collect();
render_dl_field_html(html, label, &linked.join(", "));
}
}
pub(crate) fn render_dl_country_items(html: &mut String, label: &str, values: &[String]) {
if !values.is_empty() {
let linked: Vec<String> = values
.iter()
.map(|code| {
let name = country_name(code);
if is_special_scope(code) {
name
} else {
format!(
"<a href=\"/countries/{}\" class=\"loom-country-link\">{}</a>",
code.to_lowercase(),
name
)
}
})
.collect();
render_dl_item_html(html, label, &linked.join(", "));
}
}
pub(crate) fn render_dl_opt_formatted_item(html: &mut String, label: &str, value: Option<&String>) {
if let Some(v) = value {
render_dl_item(html, label, &format_enum(v));
}
}