fix: 🐛 file parsing error on variable pattern spacing corrected

This commit is contained in:
2025-02-23 11:44:19 +01:00
parent 01417a7ac7
commit 727d8d770b
3 changed files with 28 additions and 19 deletions

View File

@@ -6,3 +6,8 @@ edition = "2021"
[dependencies]
inquire = "0.7.5"
regex = "1.11.1"
[[bin]]
edition = "2021"
name = "code_templates"
path = "src/main.rs"

View File

@@ -19,11 +19,15 @@ pub fn apply_name_template(template: &str, filename: &str) -> String {
}
}
// FIXME: admit space between `{}` and name|upperCase name...
pub fn apply_all_templates_to_string(mut input: String, replacement: &str) -> String {
let get_template_names_regex = Regex::new(r"(\{\{(name|upperCase name|lowerCase name|camelCase name|pascalCase name|snakeCase name|upperSnakeCase name|kebabCase name|lowerDotCase name)\}\})").unwrap();
let get_template_names_regex = Regex::new(r"(\{\{[\s]*(name|upperCase name|lowerCase name|camelCase name|pascalCase name|snakeCase name|upperSnakeCase name|kebabCase name|lowerDotCase name)[\s]*\}\})").unwrap();
input = get_template_names_regex
.replace_all(&input, |captured: &regex::Captures| {
format!("{}", apply_name_template(&captured[1], replacement),)
format!(
"{}",
apply_name_template(&captured[1].replace(" ", ""), replacement),
)
})
.into_owned();