From aab943de6bbb61e45586733a40dc96ec8e79b2e1 Mon Sep 17 00:00:00 2001 From: landon Date: Wed, 16 Sep 2026 18:14:17 -0500 Subject: [PATCH] manual renumbering of template files --- src/config.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8d1f670..ee68859 100644 --- a/src/config.rs +++ b/src/config.rs @@ -187,10 +187,27 @@ pub fn default_show_toolbar() -> bool { /// Default cookiecutter template for **File ▸ New project…**. /// First tries the bundled template, then falls back to the user's Cookiecutters directory. pub fn default_project_template() -> PathBuf { - // Try the bundled template first - let bundled = PathBuf::from("templates/snowflake"); - if bundled.join("cookiecutter.json").is_file() { - return bundled; + // Try the bundled template first (relative to the executable) + if let Ok(exe_path) = std::env::current_exe() { + // The templates are at the project root level, same as Cargo.toml + // 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 dirs::home_dir() @@ -573,4 +590,13 @@ mod tests { let cfg: Config = serde_json::from_str(saved).expect("must parse"); 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()); + } }