fix: 🐛 file parsing error on variable pattern spacing corrected
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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: ®ex::Captures| {
|
||||
format!("{}", apply_name_template(&captured[1], replacement),)
|
||||
format!(
|
||||
"{}",
|
||||
apply_name_template(&captured[1].replace(" ", ""), replacement),
|
||||
)
|
||||
})
|
||||
.into_owned();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user