pub fn validate_template<T: Serialize>(
template: &str,
data: &T,
theme: &Theme,
) -> Result<(), Box<dyn Error>>Expand description
Validates a template for unknown style tags.
This function renders the template (performing variable substitution) and then checks for any style tags that are not defined in the theme. Use this during development or CI to catch typos in templates.
§Arguments
template- A minijinja template stringdata- Any serializable data to pass to the templatetheme- Theme definitions that define valid style names
§Returns
Returns Ok(()) if all style tags in the template are defined in the theme.
Returns Err with the list of unknown tags if any are found.
§Example
use standout_render::{validate_template, Theme};
use console::Style;
use serde::Serialize;
#[derive(Serialize)]
struct Data { name: String }
let theme = Theme::new().add("title", Style::new().bold());
// Valid template passes
let result = validate_template(
"[title]{{ name }}[/title]",
&Data { name: "Hello".into() },
&theme,
);
assert!(result.is_ok());
// Unknown tag fails validation
let result = validate_template(
"[unknown]{{ name }}[/unknown]",
&Data { name: "Hello".into() },
&theme,
);
assert!(result.is_err());