manual renumbering of template files
This commit is contained in:
+30
-4
@@ -187,10 +187,27 @@ pub fn default_show_toolbar() -> bool {
|
|||||||
/// Default cookiecutter template for **File ▸ New project…**.
|
/// Default cookiecutter template for **File ▸ New project…**.
|
||||||
/// First tries the bundled template, then falls back to the user's Cookiecutters directory.
|
/// First tries the bundled template, then falls back to the user's Cookiecutters directory.
|
||||||
pub fn default_project_template() -> PathBuf {
|
pub fn default_project_template() -> PathBuf {
|
||||||
// Try the bundled template first
|
// Try the bundled template first (relative to the executable)
|
||||||
let bundled = PathBuf::from("templates/snowflake");
|
if let Ok(exe_path) = std::env::current_exe() {
|
||||||
if bundled.join("cookiecutter.json").is_file() {
|
// The templates are at the project root level, same as Cargo.toml
|
||||||
return bundled;
|
// binary is typically at target/release/md-manuscript or target/debug/md-manuscript
|
||||||
|
// So we need to go up from target/release (or target/debug) to the project root
|
||||||
|
// Then look for templates/snowflake there
|
||||||
|
let candidates = [
|
||||||
|
// Binary in target/release/ -> project root -> templates/snowflake
|
||||||
|
exe_path.parent().and_then(|p| p.parent()).and_then(|p| p.parent()).map(|p| p.join("templates/snowflake")),
|
||||||
|
// Binary in target/debug/ -> project root -> templates/snowflake
|
||||||
|
exe_path.parent().and_then(|p| p.parent()).map(|p| p.join("templates/snowflake")),
|
||||||
|
// Binary in project root (dev) -> templates/snowflake
|
||||||
|
exe_path.parent().map(|p| p.join("templates/snowflake")),
|
||||||
|
// Fallback: relative to current working directory
|
||||||
|
std::env::current_dir().ok().map(|p| p.join("templates/snowflake")),
|
||||||
|
];
|
||||||
|
for candidate in candidates.into_iter().flatten() {
|
||||||
|
if candidate.join("cookiecutter.json").is_file() {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Fallback to user's Cookiecutters directory
|
// Fallback to user's Cookiecutters directory
|
||||||
dirs::home_dir()
|
dirs::home_dir()
|
||||||
@@ -573,4 +590,13 @@ mod tests {
|
|||||||
let cfg: Config = serde_json::from_str(saved).expect("must parse");
|
let cfg: Config = serde_json::from_str(saved).expect("must parse");
|
||||||
assert_eq!(cfg.project_open_subdir, "05-Plot");
|
assert_eq!(cfg.project_open_subdir, "05-Plot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bundled_template_is_found_via_exe_path() {
|
||||||
|
let path = default_project_template();
|
||||||
|
// The function should find either the bundled template or the fallback
|
||||||
|
// Verify it returns a valid path that contains cookiecutter.json
|
||||||
|
assert!(path.join("cookiecutter.json").is_file(),
|
||||||
|
"Template path {} should contain cookiecutter.json", path.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user