Skip to content

Commit c5d7226

Browse files
committed
Allow template to have tmpl extension
Signed-off-by: Ryan Levick <[email protected]>
1 parent cbb2cb9 commit c5d7226

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

crates/templates/src/run.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,18 @@ impl Run {
344344
let template_parser = Self::template_parser();
345345
let contents = paths
346346
.iter()
347-
.map(std::fs::read)
348-
.map(|c| {
349-
c.map_err(|e| e.into())
350-
.and_then(|cc| TemplateContent::infer_from_bytes(cc, &template_parser))
351-
})
347+
.map(|path| TemplateContent::infer_from_bytes(std::fs::read(path)?, &template_parser))
352348
.collect::<Result<Vec<_>, _>>()?;
353-
let pairs = paths.into_iter().zip(contents).collect();
349+
// Strip optional .tmpl extension
350+
// Templates can use this if they don't want to store files with their final extensions
351+
let paths = paths.into_iter().map(|p| {
352+
if p.extension().map(|e| e == "tmpl").unwrap_or_default() {
353+
p.with_extension("")
354+
} else {
355+
p
356+
}
357+
});
358+
let pairs = paths.zip(contents).collect();
354359
Ok(pairs)
355360
}
356361

0 commit comments

Comments
 (0)