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)
|
.append(true)
|
||||||
.open(&merged_config_path)
|
.open(&merged_config_path)
|
||||||
.expect("unable to open");
|
.expect("unable to open");
|
||||||
for rendered_template in rendered_config.configs {
|
for config in rendered_config.configs {
|
||||||
let template_path = out_path.join(rendered_template.0 + ".tera");
|
let template_path = out_path.join(config.name + ".tera");
|
||||||
verb!(dbg, " | {}", &template_path.display());
|
verb!(dbg, " | {}", &template_path.display());
|
||||||
write(&template_path, &rendered_template.1).ok();
|
write(&template_path, &config.data).ok();
|
||||||
all_file.write_all(&rendered_template.1.as_bytes()).ok();
|
all_file.write_all(&config.data.as_bytes()).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
let spec: String = yaml_serde::to_string(&rendered_config.spec).unwrap();
|
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 struct RenderedConfig {
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
pub configs: Vec<(String, String)>,
|
pub configs: Vec<Configuration>,
|
||||||
pub spec: Value,
|
pub spec: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Configuration {
|
||||||
|
pub name: String,
|
||||||
|
pub data: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn process_templates(
|
pub fn process_templates(
|
||||||
spec: &Specification,
|
spec: &Specification,
|
||||||
dbg: LogLevel,
|
dbg: LogLevel,
|
||||||
@@ -89,7 +94,10 @@ pub fn process_templates(
|
|||||||
eprintln!("[tera] {}", chain);
|
eprintln!("[tera] {}", chain);
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
configs.push((String::from(&template_name), rendered));
|
configs.push(Configuration {
|
||||||
|
name: String::from(&template_name),
|
||||||
|
data: rendered,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RenderedConfig {
|
Ok(RenderedConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user