Skip to content

Commit 1f4f1cd

Browse files
committed
Egregious kludge for Liquid templates not being valid file paths on Windows
Signed-off-by: itowlson <[email protected]>
1 parent 762e7d2 commit 1f4f1cd

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

crates/templates/src/run.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ impl Run {
8484
self.build_renderer_raw(interaction).await.into()
8585
}
8686

87-
fn allow_overwrite(&self) -> bool {
88-
// If the template variant asks to be generated into the app root,
89-
// we assume that it knows what it's doing and intends to avoid
90-
// overwriting. This is true for the one use case we have, although
91-
// we need to track if it's a flawed assumption in general cases.
92-
self.options.allow_overwrite || self.template.use_root(&self.options.variant)
93-
}
94-
9587
// The 'raw' in this refers to the output type, which is an ugly representation
9688
// of cancellation: Ok(Some(...)) means a result, Ok(None) means cancelled, Err
9789
// means error. Why have this ugly representation? Because it makes it terser to
@@ -165,6 +157,14 @@ impl Run {
165157
}
166158
}
167159

160+
fn allow_overwrite(&self) -> bool {
161+
// If the template variant asks to be generated into the app root,
162+
// we assume that it knows what it's doing and intends to avoid
163+
// overwriting. This is true for the one use case we have, although
164+
// we need to track if it's a flawed assumption in general cases.
165+
self.options.allow_overwrite || self.template.use_root(&self.options.variant)
166+
}
167+
168168
fn included_files(
169169
&self,
170170
from: &Path,
@@ -203,6 +203,11 @@ impl Run {
203203
return crate::renderer::TemplateablePath::Plain(path);
204204
}
205205

206+
// Windows file paths can't contain the pipe character used in templates.
207+
// This masterful workaround will definitely not confuse anybody or cause
208+
// any weird hiccups in six months time.
209+
let path_str = path_str.replace("!!", "|");
210+
206211
match parser.parse(&path_str) {
207212
Ok(t) => crate::renderer::TemplateablePath::Template(t),
208213
Err(_) => crate::renderer::TemplateablePath::Plain(path),

0 commit comments

Comments
 (0)