From be037a6b35056ec8aa8f75e56becd009bc7c01f2 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 15 Apr 2021 00:32:28 +0300 Subject: Add template support We are now serving static HTML alongside Gradecoin REST --- Cargo.lock | 136 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/handlers.rs | 19 ++++++- src/routes.rs | 6 ++- templates/css.html | 8 +++ templates/footer.html | 2 + templates/header.html | 11 ++++ templates/menu.html | 5 ++ templates/welcome.html | 8 +++ 9 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 templates/css.html create mode 100644 templates/footer.html create mode 100644 templates/header.html create mode 100644 templates/menu.html create mode 100644 templates/welcome.html diff --git a/Cargo.lock b/Cargo.lock index b548774..649c923 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,58 @@ dependencies = [ "memchr", ] +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "askama" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d298738b6e47e1034e560e5afe63aa488fea34e25ec11b855a76f0d7b8e73134" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", +] + +[[package]] +name = "askama_derive" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2925c4c290382f9d2fa3d1c1b6a63fa1427099721ecca4749b154cc9c25522" +dependencies = [ + "askama_shared", + "proc-macro2", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c108c1a94380c89d2215d0ac54ce09796823cca0fd91b299cfff3b33e346fb" + +[[package]] +name = "askama_shared" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2582b77e0f3c506ec4838a25fa8a5f97b9bed72bb6d3d272ea1c031d8bd373bc" +dependencies = [ + "askama_escape", + "humansize", + "nom", + "num-traits", + "percent-encoding", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + [[package]] name = "atty" version = "0.2.14" @@ -81,6 +133,18 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bitvec" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "blake2" version = "0.9.1" @@ -277,6 +341,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + [[package]] name = "futures" version = "0.3.14" @@ -376,6 +446,7 @@ name = "gradecoin" version = "0.1.0" dependencies = [ "aes", + "askama", "base64 0.13.0", "blake2", "block-modes", @@ -495,6 +566,12 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +[[package]] +name = "humansize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" + [[package]] name = "humantime" version = "1.3.0" @@ -615,6 +692,19 @@ dependencies = [ "spin", ] +[[package]] +name = "lexical-core" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21f866863575d0e1d654fbeeabdc927292fdf862873dc3c96c6f753357e13374" +dependencies = [ + "arrayvec", + "bitflags", + "cfg-if 1.0.0", + "ryu", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.93" @@ -744,6 +834,19 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nom" +version = "6.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" +dependencies = [ + "bitvec", + "funty", + "lexical-core", + "memchr", + "version_check", +] + [[package]] name = "num-bigint" version = "0.2.6" @@ -967,6 +1070,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + [[package]] name = "rand" version = "0.7.3" @@ -1278,6 +1387,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "subtle" version = "2.4.0" @@ -1307,6 +1422,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.2.0" @@ -1431,6 +1552,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.1" @@ -1744,6 +1874,12 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" + [[package]] name = "zeroize" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index b5733b2..b505ba4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ base64 = "0.13.0" sha2 = "0.9.3" block-modes = "0.7.0" aes = "0.6.0" +askama = "0.10.5" [dev-dependencies] serde_test = "1.0.117" diff --git a/src/handlers.rs b/src/handlers.rs index a8c9947..b3a6fa8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,5 +1,6 @@ -/// API handlers, the ends of each filter chain use aes::Aes128; +/// API handlers, the ends of each filter chain +use askama::Template; use base64; use blake2::{Blake2s, Digest}; use block_modes::block_padding::Pkcs7; @@ -599,3 +600,19 @@ fn authorize_proposer(jwt_token: String, user_pem: &String) -> Result { + title: &'a str, + body: &'a str, +} + +pub async fn welcome_handler() -> Result { + let template = WelcomeTemplate { + title: "Welcome", + body: "To The Bookstore!", + }; + let res = template.render().unwrap(); + Ok(warp::reply::html(res)) +} diff --git a/src/routes.rs b/src/routes.rs index 280de35..f8d9605 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -7,7 +7,10 @@ use crate::schema::Db; /// Every route combined pub fn consensus_routes(db: Db) -> impl Filter + Clone { - transaction_list(db.clone()) + let welcome_route = warp::path::end().and_then(handlers::welcome_handler); + + welcome_route + .or(transaction_list(db.clone())) .or(register_user(db.clone())) .or(auth_transaction_propose(db.clone())) .or(auth_block_propose(db.clone())) @@ -60,4 +63,3 @@ pub fn auth_block_propose(db: Db) -> impl Filter + td, th { + padding: 8px; + } + th { + text-align: left; + } + diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 0000000..2ab5c0d --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,2 @@ + + diff --git a/templates/header.html b/templates/header.html new file mode 100644 index 0000000..fffbefe --- /dev/null +++ b/templates/header.html @@ -0,0 +1,11 @@ + + + Bookstore + {% include "css.html" %} + + +
+

Bookstore

+
+ {% include "menu.html" %} +
diff --git a/templates/menu.html b/templates/menu.html new file mode 100644 index 0000000..0f4e85f --- /dev/null +++ b/templates/menu.html @@ -0,0 +1,5 @@ + diff --git a/templates/welcome.html b/templates/welcome.html new file mode 100644 index 0000000..ca60f33 --- /dev/null +++ b/templates/welcome.html @@ -0,0 +1,8 @@ +{% include "header.html" %} +
+

{{title}}

+
+ {{body}} +
+
+{% include "footer.html" %} -- cgit v1.2.3-70-g09d2