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

update handlebars to version 5.1

This commit is contained in:
Alessandro Campeis 2024-03-04 13:05:13 +01:00
parent 2f7a1db615
commit e5fc327af0
No known key found for this signature in database
GPG Key ID: F68E280DB2378672
5 changed files with 46 additions and 18 deletions

34
Cargo.lock generated
View File

@ -984,7 +984,7 @@ dependencies = [
"fast_chemail", "fast_chemail",
"fnv", "fnv",
"futures-util", "futures-util",
"handlebars", "handlebars 4.5.0",
"http 0.2.9", "http 0.2.9",
"indexmap 2.1.0", "indexmap 2.1.0",
"mime", "mime",
@ -3168,24 +3168,24 @@ dependencies = [
[[package]] [[package]]
name = "fluent-template-macros" name = "fluent-template-macros"
version = "0.8.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dec7592cd1f45c1afe9084ce59c62a3a7c266c125c4c2ec97e95b0563c4aa914" checksum = "0c58fd7421bad2b89506827409317a3088b74d0d637202003f2e87efdc43ae8e"
dependencies = [ dependencies = [
"flume 0.10.14", "flume 0.10.14",
"ignore", "ignore",
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.48",
"unic-langid", "unic-langid",
] ]
[[package]] [[package]]
name = "fluent-templates" name = "fluent-templates"
version = "0.8.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c3ef2c2152757885365abce32ddf682746062f1b6b3c0824a29fbed6ee4d080" checksum = "fc023356542b155925aa5e433806ddd33acb46f0218541f869b342676332cd79"
dependencies = [ dependencies = [
"arc-swap", "arc-swap",
"fluent", "fluent",
@ -3194,7 +3194,7 @@ dependencies = [
"fluent-syntax", "fluent-syntax",
"fluent-template-macros", "fluent-template-macros",
"flume 0.10.14", "flume 0.10.14",
"handlebars", "handlebars 5.1.0",
"heck", "heck",
"ignore", "ignore",
"intl-memoizer", "intl-memoizer",
@ -3678,6 +3678,20 @@ name = "handlebars"
version = "4.5.0" version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225" checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225"
dependencies = [
"log",
"pest",
"pest_derive",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "handlebars"
version = "5.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab283476b99e66691dee3f1640fea91487a8d81f50fb5ecc75538f8f8879a1e4"
dependencies = [ dependencies = [
"log", "log",
"pest", "pest",
@ -7601,7 +7615,7 @@ dependencies = [
"actix-web", "actix-web",
"actix-web-lab", "actix-web-lab",
"fluent-templates", "fluent-templates",
"handlebars", "handlebars 5.1.0",
"serde", "serde",
"serde_json", "serde_json",
] ]
@ -7611,7 +7625,7 @@ name = "templating-handlebars"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"handlebars", "handlebars 5.1.0",
"serde_json", "serde_json",
] ]
@ -8261,7 +8275,7 @@ version = "1.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 1.0.0",
"rand 0.8.5", "rand 0.8.5",
"static_assertions", "static_assertions",
] ]

View File

@ -6,7 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
actix-web.workspace = true actix-web.workspace = true
actix-web-lab.workspace = true actix-web-lab.workspace = true
fluent-templates = { version = "0.8", features = ["handlebars"] } fluent-templates = { version = "0.9", features = ["handlebars"] }
handlebars = { version = "4.5", features = ["dir_source"] } handlebars = { version = "5.1", features = ["dir_source"] }
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true

View File

@ -10,7 +10,7 @@ use actix_web::{
}; };
use actix_web_lab::{extract::Path, respond::Html}; use actix_web_lab::{extract::Path, respond::Html};
use fluent_templates::{static_loader, FluentLoader, Loader as _}; use fluent_templates::{static_loader, FluentLoader, Loader as _};
use handlebars::Handlebars; use handlebars::{DirectorySourceOptions, Handlebars};
use serde_json::json; use serde_json::json;
mod lang_choice; mod lang_choice;
@ -57,7 +57,14 @@ async fn main() -> io::Result<()> {
// register template dir with Handlebars registry // register template dir with Handlebars registry
handlebars handlebars
.register_templates_directory(".html", "./templates") .register_templates_directory(
"./static/templates",
DirectorySourceOptions {
tpl_extension: ".html".to_owned(),
hidden: false,
temporary: false,
},
)
.unwrap(); .unwrap();
// register Fluent helper with Handlebars registry // register Fluent helper with Handlebars registry
@ -85,7 +92,7 @@ fn error_handlers() -> ErrorHandlers<BoxBody> {
// Error handler for a 404 Page not found error. // Error handler for a 404 Page not found error.
fn not_found<B>(res: ServiceResponse<B>) -> Result<ErrorHandlerResponse<BoxBody>> { fn not_found<B>(res: ServiceResponse<B>) -> Result<ErrorHandlerResponse<BoxBody>> {
let lang = LangChoice::from_req(res.request()).lang_id(); let lang = LangChoice::from_req(res.request()).lang_id();
let error = LOCALES.lookup(&lang, "error-not-found").unwrap(); let error = LOCALES.lookup(&lang, "error-not-found");
let response = get_error_response(&res, &error); let response = get_error_response(&res, &error);

View File

@ -5,5 +5,5 @@ edition = "2021"
[dependencies] [dependencies]
actix-web.workspace = true actix-web.workspace = true
handlebars = { version = "4.5", features = ["dir_source"] } handlebars = { version = "5.1", features = ["dir_source"] }
serde_json.workspace = true serde_json.workspace = true

View File

@ -8,7 +8,7 @@ use actix_web::{
middleware::{ErrorHandlerResponse, ErrorHandlers}, middleware::{ErrorHandlerResponse, ErrorHandlers},
web, App, HttpResponse, HttpServer, Result, web, App, HttpResponse, HttpServer, Result,
}; };
use handlebars::Handlebars; use handlebars::{DirectorySourceOptions, Handlebars};
use serde_json::json; use serde_json::json;
// Macro documentation can be found in the actix_web_codegen crate // Macro documentation can be found in the actix_web_codegen crate
@ -41,7 +41,14 @@ async fn main() -> io::Result<()> {
// Application Builder as an atomic reference-counted pointer. // Application Builder as an atomic reference-counted pointer.
let mut handlebars = Handlebars::new(); let mut handlebars = Handlebars::new();
handlebars handlebars
.register_templates_directory(".html", "./static/templates") .register_templates_directory(
"./static/templates",
DirectorySourceOptions {
tpl_extension: ".html".to_owned(),
hidden: false,
temporary: false,
},
)
.unwrap(); .unwrap();
let handlebars_ref = web::Data::new(handlebars); let handlebars_ref = web::Data::new(handlebars);