From 7b35cd32c7405d80c2523f2515859299cd35376b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 19 Dec 2019 03:25:56 +0900 Subject: [PATCH] Update `tera` to 1.0 (#212) --- template_tera/Cargo.toml | 2 +- template_tera/src/main.rs | 6 ++---- todo/Cargo.toml | 2 +- todo/src/api.rs | 2 +- todo/src/main.rs | 4 +--- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/template_tera/Cargo.toml b/template_tera/Cargo.toml index 71ad8b9..607801c 100644 --- a/template_tera/Cargo.toml +++ b/template_tera/Cargo.toml @@ -7,6 +7,6 @@ edition = "2018" [dependencies] env_logger = "0.6" -tera = "0.11" +tera = "1.0" actix-web = "2.0.0-alpha.6" actix-rt = "1.0.0" diff --git a/template_tera/src/main.rs b/template_tera/src/main.rs index fac0ac7..c2123ed 100644 --- a/template_tera/src/main.rs +++ b/template_tera/src/main.rs @@ -1,9 +1,7 @@ -#[macro_use] -extern crate tera; - use std::collections::HashMap; use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer}; +use tera::Tera; // store tera template in application state async fn index( @@ -31,7 +29,7 @@ async fn main() -> std::io::Result<()> { HttpServer::new(|| { let tera = - compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")); + Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap(); App::new() .data(tera) diff --git a/todo/Cargo.toml b/todo/Cargo.toml index ae1f359..43ac6b4 100644 --- a/todo/Cargo.toml +++ b/todo/Cargo.toml @@ -17,7 +17,7 @@ log = "0.4.3" serde = "1.0.69" serde_derive = "1.0.69" serde_json = "1.0.22" -tera = "0.11.8" +tera = "1.0" [dependencies.diesel] features = ["postgres", "r2d2"] diff --git a/todo/src/api.rs b/todo/src/api.rs index 990af65..dd1d826 100644 --- a/todo/src/api.rs +++ b/todo/src/api.rs @@ -26,7 +26,7 @@ pub async fn index( let rendered = tmpl .render("index.html.tera", &context) - .map_err(|e| error::ErrorInternalServerError(e.description().to_owned()))?; + .map_err(|e| error::ErrorInternalServerError(e))?; Ok(HttpResponse::Ok().body(rendered)) } diff --git a/todo/src/main.rs b/todo/src/main.rs index 5fc6097..54481e4 100644 --- a/todo/src/main.rs +++ b/todo/src/main.rs @@ -4,8 +4,6 @@ extern crate diesel; extern crate log; #[macro_use] extern crate serde_derive; -#[macro_use] -extern crate tera; use std::{env, io}; @@ -37,7 +35,7 @@ async fn main() -> io::Result<()> { let app = move || { debug!("Constructing the App"); - let templates: Tera = compile_templates!("templates/**/*"); + let templates: Tera = Tera::new("/templates/**/*").unwrap(); let session_store = CookieSession::signed(SESSION_SIGNING_KEY).secure(false);