Skip to content

Commit 4292c9a

Browse files
committed
refactor: [#238] standardize renderer constants to use three-part pattern
All template renderers now consistently use three constants: - TEMPLATE_FILE: Source template filename (e.g., 'inventory.yml.tera') - OUTPUT_FILE: Rendered output filename (e.g., 'inventory.yml') - TEMPLATE_DIR: Template directory path (e.g., 'ansible') Updated renderers: - InventoryRenderer: Added ANSIBLE_TEMPLATE_DIR constant - VariablesRenderer: Added ANSIBLE_TEMPLATE_DIR constant - DockerComposeRenderer: Already had all three constants - EnvRenderer: Added DOCKER_COMPOSE_TEMPLATE_DIR constant - PrometheusConfigRenderer: Split PROMETHEUS_TEMPLATE_PATH into three constants - TrackerConfigRenderer: Split TRACKER_TEMPLATE_PATH into three constants - CloudInitRenderer: Already had all three constants Benefits: - Consistent pattern across all renderers (same responsibility, same structure) - Easier to understand template source and destination paths - More maintainable when adding new renderers - Clear separation of concerns (filename vs directory path) All tests passing (1509 tests).
1 parent 8638430 commit 4292c9a

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

src/infrastructure/templating/ansible/template/renderer/inventory.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ impl InventoryRenderer {
9898
/// Output filename for the rendered inventory file
9999
const INVENTORY_OUTPUT_FILE: &'static str = "inventory.yml";
100100

101+
/// Directory path for Ansible templates
102+
const ANSIBLE_TEMPLATE_DIR: &'static str = "ansible";
103+
101104
/// Creates a new inventory template renderer
102105
///
103106
/// # Arguments
@@ -191,7 +194,11 @@ impl InventoryRenderer {
191194
///
192195
/// * `String` - The complete template path for inventory.yml.tera
193196
fn build_template_path() -> String {
194-
format!("ansible/{}", Self::INVENTORY_TEMPLATE_FILE)
197+
format!(
198+
"{}/{}",
199+
Self::ANSIBLE_TEMPLATE_DIR,
200+
Self::INVENTORY_TEMPLATE_FILE
201+
)
195202
}
196203
}
197204

src/infrastructure/templating/ansible/template/renderer/variables.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ impl VariablesRenderer {
9999
/// Output filename for the rendered variables file
100100
const VARIABLES_OUTPUT_FILE: &'static str = "variables.yml";
101101

102+
/// Directory path for Ansible templates
103+
const ANSIBLE_TEMPLATE_DIR: &'static str = "ansible";
104+
102105
/// Creates a new variables template renderer
103106
///
104107
/// # Arguments
@@ -192,7 +195,7 @@ impl VariablesRenderer {
192195
///
193196
/// * `String` - The complete template path for variables.yml.tera
194197
fn build_template_path() -> String {
195-
format!("ansible/{}", Self::VARIABLES_TEMPLATE_FILE)
198+
format!("{}/{}", Self::ANSIBLE_TEMPLATE_DIR, Self::VARIABLES_TEMPLATE_FILE)
196199
}
197200
}
198201

src/infrastructure/templating/docker_compose/template/renderer/env.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ impl EnvRenderer {
9898
/// Output filename for the rendered .env file
9999
const ENV_OUTPUT_FILE: &'static str = ".env";
100100

101+
/// Directory path for Docker Compose templates
102+
const DOCKER_COMPOSE_TEMPLATE_DIR: &'static str = "docker-compose";
103+
101104
/// Creates a new .env template renderer
102105
///
103106
/// # Arguments
@@ -191,7 +194,7 @@ impl EnvRenderer {
191194
///
192195
/// * `String` - The complete template path for env.tera
193196
fn build_template_path() -> String {
194-
format!("docker-compose/{}", Self::ENV_TEMPLATE_FILE)
197+
format!("{}/{}", Self::DOCKER_COMPOSE_TEMPLATE_DIR, Self::ENV_TEMPLATE_FILE)
195198
}
196199
}
197200

src/infrastructure/templating/prometheus/template/renderer/prometheus_config.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ pub struct PrometheusConfigRenderer {
4949
}
5050

5151
impl PrometheusConfigRenderer {
52-
const PROMETHEUS_TEMPLATE_PATH: &'static str = "prometheus/prometheus.yml.tera";
52+
/// Template filename for the Prometheus Tera template
53+
const PROMETHEUS_TEMPLATE_FILE: &'static str = "prometheus.yml.tera";
54+
55+
/// Output filename for the rendered Prometheus config file
56+
const PROMETHEUS_OUTPUT_FILE: &'static str = "prometheus.yml";
57+
58+
/// Directory path for Prometheus templates
59+
const PROMETHEUS_TEMPLATE_DIR: &'static str = "prometheus";
5360

5461
/// Creates a new Prometheus config renderer
5562
///
@@ -82,9 +89,11 @@ impl PrometheusConfigRenderer {
8289
output_dir: &Path,
8390
) -> Result<(), PrometheusConfigRendererError> {
8491
// 1. Load template from template manager
85-
let template_path = self
86-
.template_manager
87-
.get_template_path(Self::PROMETHEUS_TEMPLATE_PATH)?;
92+
let template_path = self.template_manager.get_template_path(&format!(
93+
"{}/{}",
94+
Self::PROMETHEUS_TEMPLATE_DIR,
95+
Self::PROMETHEUS_TEMPLATE_FILE
96+
))?;
8897

8998
// 2. Read template content
9099
let template_content = std::fs::read_to_string(&template_path).map_err(|source| {
@@ -98,7 +107,7 @@ impl PrometheusConfigRenderer {
98107
let template = PrometheusTemplate::new(template_content, context.clone())?;
99108

100109
// 4. Render to output file
101-
let output_path = output_dir.join("prometheus.yml");
110+
let output_path = output_dir.join(Self::PROMETHEUS_OUTPUT_FILE);
102111
template.render_to_file(&output_path)?;
103112

104113
Ok(())

src/infrastructure/templating/tracker/template/renderer/tracker_config.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ pub struct TrackerConfigRenderer {
5454
}
5555

5656
impl TrackerConfigRenderer {
57-
const TRACKER_TEMPLATE_PATH: &'static str = "tracker/tracker.toml.tera";
57+
/// Template filename for the Tracker Tera template
58+
const TRACKER_TEMPLATE_FILE: &'static str = "tracker.toml.tera";
59+
60+
/// Output filename for the rendered Tracker config file
61+
const TRACKER_OUTPUT_FILE: &'static str = "tracker.toml";
62+
63+
/// Directory path for Tracker templates
64+
const TRACKER_TEMPLATE_DIR: &'static str = "tracker";
5865

5966
/// Creates a new tracker config renderer
6067
///
@@ -93,7 +100,7 @@ impl TrackerConfigRenderer {
93100
// 1. Load template from template manager
94101
let template_path = self
95102
.template_manager
96-
.get_template_path(Self::TRACKER_TEMPLATE_PATH)?;
103+
.get_template_path(&format!("{}/{}", Self::TRACKER_TEMPLATE_DIR, Self::TRACKER_TEMPLATE_FILE))?;
97104

98105
// 2. Read template content
99106
let template_content = std::fs::read_to_string(&template_path).map_err(|source| {
@@ -107,7 +114,7 @@ impl TrackerConfigRenderer {
107114
let template = TrackerTemplate::new(template_content, context.clone())?;
108115

109116
// 4. Render to output file
110-
let output_path = output_dir.join("tracker.toml");
117+
let output_path = output_dir.join(Self::TRACKER_OUTPUT_FILE);
111118
template.render_to_file(&output_path)?;
112119

113120
Ok(())

0 commit comments

Comments
 (0)