Updated deprecated handlebars syntax on the fly
@@ -20,7 +20,6 @@ pub mod package;
pub mod test_helpers;
use std::{fmt,
- fs::read_to_string,
ops::{Deref,
DerefMut},
result};
@@ -109,11 +108,15 @@ impl TemplateRenderer {
lazy_static! {
static ref RE: Regex =
- Regex::new(r"\{\{[^}]+[^.]\[[^}]*\}\}").expect("Failed to compile template \
+ Regex::new(r"(\{\{[^}]+[^.])(\[[^}]*\}\})").expect("Failed to compile template \
deprecation regex");
}
- if let Ok(template_string) = read_to_string(path) {
+ let template_string =
+ std::fs::read_to_string(path).map_err(|e| {
+ TemplateFileError::IOError(e, name.to_owned())
+ })?;
+
template_string.split("\n")
.enumerate()
.filter(|(_i, v)| RE.is_match(&v))
@@ -127,9 +130,13 @@ impl TemplateRenderer {
*******************************************************\n\n",
path.display(), i, v)
});
- }
- self.0.register_template_file(name, path)
+ // Replace the deprecated syntax with the good syntax. This should make it easier to upgrade
+ // the handlebars crate without breaking folks.
+ let updated_template_string = RE.replace_all(&template_string, "$1.$2");
+ self.0
+ .register_template_string(name, updated_template_string)?;
+ Ok(())
}
}
