Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow template to have tmpl extension #2456

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions crates/templates/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,18 @@ impl Run {
let template_parser = Self::template_parser();
let contents = paths
.iter()
.map(std::fs::read)
.map(|c| {
c.map_err(|e| e.into())
.and_then(|cc| TemplateContent::infer_from_bytes(cc, &template_parser))
})
.map(|path| TemplateContent::infer_from_bytes(std::fs::read(path)?, &template_parser))
.collect::<Result<Vec<_>, _>>()?;
let pairs = paths.into_iter().zip(contents).collect();
// Strip optional .tmpl extension
// Templates can use this if they don't want to store files with their final extensions
let paths = paths.into_iter().map(|p| {
if p.extension().map(|e| e == "tmpl").unwrap_or_default() {
Copy link
Collaborator

@lann lann Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an option now (Rust 1.70):

Suggested change
if p.extension().map(|e| e == "tmpl").unwrap_or_default() {
if p.extension().is_some_and(|e| e == "tmpl") {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we documenting Spin's MSRV? CI is testing 1.74 but the contributing docs say 1.68. I assume the contributing docs are just out of date?

p.with_extension("")
} else {
p
}
});
let pairs = paths.zip(contents).collect();
Ok(pairs)
}

Expand Down
Loading