From a65abad80da4f98fff6998f275728439c0e6a417 Mon Sep 17 00:00:00 2001 From: Juan Aguilar Santillana Date: Tue, 28 Apr 2020 21:18:18 +0200 Subject: [PATCH] Update yarte version to 0.8 --- Cargo.toml | 3 +- template_yarte/Cargo.toml | 8 ++- template_yarte/build.rs | 2 +- template_yarte/src/main.rs | 63 +++++++++---------- .../templates/deep/more/card/form.hbs | 3 - .../templates/deep/more/deep/welcome.hbs | 3 + .../templates/deep/more/doc/head.hbs | 3 + 7 files changed, 44 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b01e3a4a..dbd700d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,8 @@ members = [ "rustls", "shutdown-server", "server-sent-events", - "simple-auth-server", +# Depency clang outdate bindgen@0.48 +# "simple-auth-server", "state", "static_index", "template_askama", diff --git a/template_yarte/Cargo.toml b/template_yarte/Cargo.toml index 96f4279e..379dd6c1 100644 --- a/template_yarte/Cargo.toml +++ b/template_yarte/Cargo.toml @@ -10,10 +10,12 @@ workspace = ".." [dependencies] env_logger = "0.7" -yarte = { version = "0.7", features = ["with-actix-web"] } +yarte = { version = "0.8", features = ["html-min"] } actix-rt = "1.0" actix-web = "2.0.0" -[build-dependencies] -yarte = { version = "0.7", features = ["with-actix-web"] } +[build-dependencies.yarte_helpers] +version = "0.8" +default-features = false +features = ["config"] diff --git a/template_yarte/build.rs b/template_yarte/build.rs index 2074d9f3..7745f71b 100644 --- a/template_yarte/build.rs +++ b/template_yarte/build.rs @@ -1,3 +1,3 @@ fn main() { - yarte::recompile::when_changed(); + yarte_helpers::recompile::when_changed(); } diff --git a/template_yarte/src/main.rs b/template_yarte/src/main.rs index 1e3fe9be..1a9ffba6 100644 --- a/template_yarte/src/main.rs +++ b/template_yarte/src/main.rs @@ -1,17 +1,29 @@ use std::collections::HashMap; -use actix_web::{get, middleware::Logger, web, App, HttpServer, Responder}; -use yarte::Template; +use actix_web::{ + error::ErrorInternalServerError, get, middleware::Logger, web, App, Error, + HttpResponse, HttpServer, +}; +use yarte::TemplateMin; -#[derive(Template)] -#[template(path = "index.hbs", err = "Some error message", mode = "html-min")] +#[derive(TemplateMin)] +#[template(path = "index")] struct IndexTemplate { query: web::Query>, } #[get("/")] -async fn index(query: web::Query>) -> impl Responder { +async fn index( + query: web::Query>, +) -> Result { IndexTemplate { query } + .call() + .map(|body| { + HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(body) + }) + .map_err(|_| ErrorInternalServerError("Some error message")) } #[actix_rt::main] @@ -49,17 +61,11 @@ mod test { assert_eq!( bytes, Bytes::from_static( - "\ - \ - Actix web\ -

Welcome!

\ -

What is your name?

\ -
\ - Name: \ -
Last name: \ -

\ -
\ - " + "Actix \ + web

Welcome!

What is your name?

Name: \ +
Last name:

" .as_ref() ) ); @@ -78,12 +84,9 @@ mod test { assert_eq!( bytes, Bytes::from_static( - "\ - \ - Actix web\ - \ -

Hi, foo bar!

Welcome

\ - " + "Actix \ + web

Hi, foo bar!

Welcome

" .as_ref() ) ); @@ -111,17 +114,11 @@ mod test { assert_eq!( bytes, Bytes::from_static( - "\ - \ - Actix web\ -

Welcome!

\ -

What is your name?

\ -
\ - Name: \ -
Last name: \ -

\ -
\ - " + "Actix \ + web

Welcome!

What is your name?

Name: \ +
Last name:

" .as_ref() ) ); diff --git a/template_yarte/templates/deep/more/card/form.hbs b/template_yarte/templates/deep/more/card/form.hbs index dbf4213d..75b0c84a 100644 --- a/template_yarte/templates/deep/more/card/form.hbs +++ b/template_yarte/templates/deep/more/card/form.hbs @@ -3,10 +3,7 @@ !}} {{> ../deep/welcome id = "welcome", tag = "h1", tail = '!' ~}}
- {{! Title !}}

What is your name?

- - {{! Form !}}
{{! Input name !}} Name:
diff --git a/template_yarte/templates/deep/more/deep/welcome.hbs b/template_yarte/templates/deep/more/deep/welcome.hbs index e0fe08b1..fea7606d 100644 --- a/template_yarte/templates/deep/more/deep/welcome.hbs +++ b/template_yarte/templates/deep/more/deep/welcome.hbs @@ -5,4 +5,7 @@ - id - tail !}} +{{#unless tag.is_match(r"^p|(h[1-6])$") && !id.is_empty() }} + {{$ "Need static args: tag: str /^h[1-6]$/, id: str" }} +{{/unless }} <{{ tag }} id="{{ id }}" class="welcome">Welcome{{ tail }} diff --git a/template_yarte/templates/deep/more/doc/head.hbs b/template_yarte/templates/deep/more/doc/head.hbs index f8b95f3e..20764911 100644 --- a/template_yarte/templates/deep/more/doc/head.hbs +++ b/template_yarte/templates/deep/more/doc/head.hbs @@ -1,3 +1,6 @@ +{{# unless title.is_str() && !title.is_empty() }} + {{$ "Need static args: title: str" }} +{{/unless}} {{ title }}