use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct FileContext {
pub structs: Vec<StructContext>,
pub features: Vec<FeatureContext>,
}
#[derive(Debug, Serialize)]
pub struct StructContext {
pub name: String,
pub fields: Vec<StructFieldContext>,
}
#[derive(Debug, Serialize)]
pub struct StructFieldContext {
pub name: String,
pub type_name: String,
}
#[derive(Debug, Serialize)]
pub struct FeatureContext {
pub name: String,
pub id: u32,
pub interface_name: String,
pub defaults_name: String,
pub variable_ids_name: String,
pub fn_name: String,
pub variables: Vec<VariableContext>,
}
#[derive(Debug, Serialize)]
pub struct VariableContext {
pub name: String,
pub type_name: String,
pub default_value: String,
pub id: u32,
}
pub fn render(template_str: &str, context: &FileContext) -> String {
let mut env = minijinja::Environment::new();
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
env.add_template("output", template_str)
.expect("template parse error: this is a bug in the embedded template");
let tmpl = env.get_template("output").unwrap();
tmpl.render(context)
.expect("template render error: this is a bug in the template or context")
}