1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Update tera to 1.0 (#212)

This commit is contained in:
Yuki Okushi 2019-12-19 03:25:56 +09:00 committed by GitHub
parent b12b006c03
commit 7b35cd32c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 10 deletions

View File

@ -7,6 +7,6 @@ edition = "2018"
[dependencies] [dependencies]
env_logger = "0.6" env_logger = "0.6"
tera = "0.11" tera = "1.0"
actix-web = "2.0.0-alpha.6" actix-web = "2.0.0-alpha.6"
actix-rt = "1.0.0" actix-rt = "1.0.0"

View File

@ -1,9 +1,7 @@
#[macro_use]
extern crate tera;
use std::collections::HashMap; use std::collections::HashMap;
use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer}; use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer};
use tera::Tera;
// store tera template in application state // store tera template in application state
async fn index( async fn index(
@ -31,7 +29,7 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(|| {
let tera = let tera =
compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")); Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap();
App::new() App::new()
.data(tera) .data(tera)

View File

@ -17,7 +17,7 @@ log = "0.4.3"
serde = "1.0.69" serde = "1.0.69"
serde_derive = "1.0.69" serde_derive = "1.0.69"
serde_json = "1.0.22" serde_json = "1.0.22"
tera = "0.11.8" tera = "1.0"
[dependencies.diesel] [dependencies.diesel]
features = ["postgres", "r2d2"] features = ["postgres", "r2d2"]

View File

@ -26,7 +26,7 @@ pub async fn index(
let rendered = tmpl let rendered = tmpl
.render("index.html.tera", &context) .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)) Ok(HttpResponse::Ok().body(rendered))
} }

View File

@ -4,8 +4,6 @@ extern crate diesel;
extern crate log; extern crate log;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use]
extern crate tera;
use std::{env, io}; use std::{env, io};
@ -37,7 +35,7 @@ async fn main() -> io::Result<()> {
let app = move || { let app = move || {
debug!("Constructing the App"); 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); let session_store = CookieSession::signed(SESSION_SIGNING_KEY).secure(false);