Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/compile/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2861,11 +2861,11 @@ pub async fn compile_shared(
///
/// Handles the full setup — collecting extensions, building the compile context,
/// generating the stage prefix and template parameters, computing AWF/MCPG
/// values — and delegates to [`compile_shared`]. The caller supplies:
/// values — and delegates to [`compile_shared`]. The caller supplies:
///
/// - `cfg`: target-specific settings (template string, integrity / debug flags).
/// - `header_fn`: a function that generates the leading comment block prepended
/// to the compiled YAML. The two template compilers use different header
/// to the compiled YAML. The two template compilers use different header
/// layouts, so this lets each compiler keep its own generator while sharing
/// all of the boilerplate setup.
///
Expand Down Expand Up @@ -2927,9 +2927,15 @@ pub async fn compile_template_target(
};

let yaml = compile_shared(
input_path, output_path, front_matter, markdown_body,
&extensions, &ctx, config,
).await?;
input_path,
output_path,
front_matter,
markdown_body,
&extensions,
&ctx,
config,
)
.await?;

let header = header_fn(input_path, output_path, front_matter);
Ok(format!("{}{}", header, yaml))
Expand Down
11 changes: 4 additions & 7 deletions src/compile/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use std::path::Path;

use super::Compiler;
use super::common::{
compile_template_target, TemplateTargetConfig,
generate_header_comment,
compile_template_target, generate_header_comment, TemplateTargetConfig,
};
use super::types::FrontMatter;

Expand Down Expand Up @@ -52,16 +51,15 @@ impl Compiler for JobCompiler {
debug_pipeline,
},
generate_job_header,
).await
)
.await
}
}

/// Generate the header comment block for job-level templates.
fn generate_job_header(input_path: &Path, output_path: &Path, front_matter: &FrontMatter) -> String {
let base_header = generate_header_comment(input_path);
let mut lock_path = output_path
.to_string_lossy()
.replace('\\', "/");
let mut lock_path = output_path.to_string_lossy().replace('\\', "/");
// Strip redundant leading "./" (same normalization as generate_header_comment)
while lock_path.starts_with("./") {
lock_path = lock_path[2..].to_string();
Expand Down Expand Up @@ -102,7 +100,6 @@ fn generate_job_header(input_path: &Path, output_path: &Path, front_matter: &Fro

#[cfg(test)]
mod tests {
use super::*;
use crate::compile::common::generate_stage_prefix;

#[test]
Expand Down
10 changes: 4 additions & 6 deletions src/compile/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use std::path::Path;

use super::Compiler;
use super::common::{
compile_template_target, TemplateTargetConfig,
generate_header_comment,
compile_template_target, generate_header_comment, TemplateTargetConfig,
};
use super::types::FrontMatter;

Expand Down Expand Up @@ -60,16 +59,15 @@ impl Compiler for StageCompiler {
debug_pipeline,
},
generate_stage_header,
).await
)
.await
}
}

/// Generate the header comment block for stage-level templates.
fn generate_stage_header(input_path: &Path, output_path: &Path, front_matter: &FrontMatter) -> String {
let base_header = generate_header_comment(input_path);
let mut lock_path = output_path
.to_string_lossy()
.replace('\\', "/");
let mut lock_path = output_path.to_string_lossy().replace('\\', "/");
while lock_path.starts_with("./") {
lock_path = lock_path[2..].to_string();
}
Expand Down
Loading