Use upstream Tera. Emit warning on conflicting templates.

This commit is contained in:
Sergio Benitez 2017-01-26 12:47:20 -08:00
parent c61e740572
commit 8fd19cce4f
3 changed files with 13 additions and 7 deletions

View File

@ -36,4 +36,4 @@ handlebars = { version = "^0.24", optional = true, features = ["serde_type"] }
glob = { version = "^0.2", optional = true }
lazy_static = { version = "^0.2", optional = true }
# tera = { version = "^0.6", optional = true }
tera = { git = "https://github.com/SergioBenitez/tera", optional = true }
tera = { git = "https://github.com/Keats/tera", optional = true }

View File

@ -238,20 +238,26 @@ fn discover_templates() -> HashMap<String, TemplateInfo> {
"handlebars_templates" => handlebars_templates,
];
let mut templates = HashMap::new();
let mut templates: HashMap<String, TemplateInfo> = HashMap::new();
for &(ext, _) in &engines {
let mut glob_path: PathBuf = TEMPLATE_DIR.join("**").join("*");
glob_path.set_extension(ext);
for path in glob(glob_path.to_str().unwrap()).unwrap().filter_map(Result::ok) {
let (rel_path, name, data_type) = split_path(&path);
let info = TemplateInfo {
if let Some(info) = templates.get(&*name) {
warn_!("Template name '{}' does not have a unique path.", name);
info_!("Existing path: {:?}", info.full_path);
info_!("Additional path: {:?}", path);
warn_!("Using existing path for template '{}'.", name);
continue;
}
templates.insert(name, TemplateInfo {
full_path: path.to_path_buf(),
path: rel_path,
extension: ext.to_string(),
data_type: data_type,
};
templates.insert(name, info);
});
}
}

View File

@ -23,7 +23,7 @@ pub unsafe fn register(templates: &[(&str, &TemplateInfo)]) -> bool {
// Collect into a tuple of (name, path) for Tera.
let tera_templates = templates.iter()
.map(|&(name, info)| (name, &info.full_path))
.map(|&(name, info)| (&info.full_path, Some(name)))
.collect::<Vec<_>>();
// Finally try to tell Tera about all of the templates.