extern crate tera;

use std::path::PathBuf;

use super::serde::Serialize;
use super::{TemplateInfo, TEMPLATE_DIR};

lazy_static! {
    static ref TERA: Result<tera::Tera, String> = {
        let path: PathBuf = [&*TEMPLATE_DIR, "**", "*.tera"].iter().collect();
        tera::Tera::new(path.to_str().unwrap()).map_err(|e| format!("{:?}", e))
    };
}

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() {
        error_!("Tera template '{}' does not exist.", template_name);
        return None;
    };

    match tera.value_render(template_name, &context) {
        Ok(string) => Some(string),
        Err(e) => {
            error_!("Error rendering Tera template '{}': {}", name, e);
            None
        }
    }
}

extern crate tera;

use std::path::PathBuf;

use super::serde::Serialize;
use super::{TemplateInfo, TEMPLATE_DIR};

lazy_static! {
    static ref TERA: tera::Tera = {
        let path: PathBuf = [&*TEMPLATE_DIR, "**", "*.tera"].iter().collect();
        tera::Tera::new(path.to_str().unwrap())
    };
}

pub const EXT: &'static str = "tera";

pub fn render<T>(name: &str, info: &TemplateInfo, context: &T) -> Option<String>
    where T: Serialize
{
    let template_name = &info.path.to_string_lossy();
    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) {
        Ok(string) => Some(string),
        Err(e) => {
            error_!("Error rendering Tera template '{}': {}", name, e);
            None
        }
    }
}

--- 
+++ 
@@ -6,9 +6,9 @@
 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 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);
Fix fallout from Tera dependency update.
