use regex::Regex;
pub struct LaravelViewConverter;
impl LaravelViewConverter {
pub fn convert(blade_php_content: &str) -> String {
let mut content = blade_php_content.to_string();
let loop_re = Regex::new(r#"\$loop->([A-Za-z0-9_]+)"#).unwrap();
content = loop_re.replace_all(&content, "$$loop.$1").to_string();
let arrow_chain_re = Regex::new(r#"(\$[A-Za-z0-9_]+(?:->[A-Za-z0-9_]+)+)"#).unwrap();
content = arrow_chain_re
.replace_all(&content, |caps: ®ex::Captures| {
let matched = caps.get(1).unwrap().as_str();
matched.replace("->", ".")
})
.to_string();
let bracket_re = Regex::new(r#"\$([A-Za-z0-9_]+)\s*\[\s*['"]([A-Za-z0-9_]+)['"]\s*\]"#).unwrap();
content = bracket_re.replace_all(&content, "$$$1.$2").to_string();
content
}
}