refactor template handling
This commit is contained in:
@@ -39,11 +39,11 @@ fn output_rendered_configs(rendered_config: RenderedConfig, outdir: &str, dbg: L
|
||||
.append(true)
|
||||
.open(&merged_config_path)
|
||||
.expect("unable to open");
|
||||
for rendered_template in rendered_config.configs {
|
||||
let template_path = out_path.join(rendered_template.0 + ".tera");
|
||||
for config in rendered_config.configs {
|
||||
let template_path = out_path.join(config.name + ".tera");
|
||||
verb!(dbg, " | {}", &template_path.display());
|
||||
write(&template_path, &rendered_template.1).ok();
|
||||
all_file.write_all(&rendered_template.1.as_bytes()).ok();
|
||||
write(&template_path, &config.data).ok();
|
||||
all_file.write_all(&config.data.as_bytes()).ok();
|
||||
}
|
||||
|
||||
let spec: String = yaml_serde::to_string(&rendered_config.spec).unwrap();
|
||||
|
||||
12
src/tmpls.rs
12
src/tmpls.rs
@@ -12,10 +12,15 @@ struct TemplateConfig {
|
||||
|
||||
pub struct RenderedConfig {
|
||||
pub hostname: String,
|
||||
pub configs: Vec<(String, String)>,
|
||||
pub configs: Vec<Configuration>,
|
||||
pub spec: Value,
|
||||
}
|
||||
|
||||
pub struct Configuration {
|
||||
pub name: String,
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
pub fn process_templates(
|
||||
spec: &Specification,
|
||||
dbg: LogLevel,
|
||||
@@ -89,7 +94,10 @@ pub fn process_templates(
|
||||
eprintln!("[tera] {}", chain);
|
||||
})
|
||||
.unwrap_or_default();
|
||||
configs.push((String::from(&template_name), rendered));
|
||||
configs.push(Configuration {
|
||||
name: String::from(&template_name),
|
||||
data: rendered,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(RenderedConfig {
|
||||
|
||||
Reference in New Issue
Block a user