Fix fallout from Tera dependency update.

This commit is contained in:
Sergio Benitez 2016-12-19 21:04:40 -08:00
parent e7fe962546
commit 5540201236
1 changed files with 12 additions and 4 deletions

View File

@ -6,9 +6,9 @@ use super::serde::Serialize;
use super::{TemplateInfo, TEMPLATE_DIR};
lazy_static! {
static ref TERA: tera::Tera = {
static ref TERA: Result<tera::Tera, String> = {
let path: PathBuf = [&*TEMPLATE_DIR, "**", "*.tera"].iter().collect();
tera::Tera::new(path.to_str().unwrap())
tera::Tera::new(path.to_str().unwrap()).map_err(|e| format!("{:?}", e))
};
}
@ -17,13 +17,21 @@ pub const EXT: &'static str = "tera";
pub fn render<T>(name: &str, info: &TemplateInfo, context: &T) -> Option<String>
where T: Serialize
{
let tera = match *TERA {
Ok(ref tera) => tera,
Err(ref e) => {
error_!("Tera failed to initialize: {}.", e);
return None;
}
};
let template_name = &info.path.to_string_lossy();
if TERA.get_template(template_name).is_err() {
if tera.get_template(template_name).is_err() {
error_!("Tera template '{}' does not exist.", template_name);
return None;
};
match TERA.value_render(template_name, &context) {
match tera.value_render(template_name, &context) {
Ok(string) => Some(string),
Err(e) => {
error_!("Error rendering Tera template '{}': {}", name, e);