aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-08-22 17:02:30 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-08-22 17:02:30 +0200
commit3267754478ea1b83c3da653c4a5f9706c9fdce05 (patch)
tree30ad507bddf03dce50d833040948c904b2dffa2c
parent2b8fdbe9200d6950bfd10f42e5af0e424effafd8 (diff)
downloadramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.tar.gz
ramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.tar.bz2
ramaskrik-social-3267754478ea1b83c3da653c4a5f9706c9fdce05.zip
Use Tera templates to render pages.
-rw-r--r--Cargo.lock179
-rw-r--r--Cargo.toml2
-rw-r--r--src/controllers/room.rs17
-rw-r--r--src/lib.rs3
-rw-r--r--templates/room/list.tera13
5 files changed, 209 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c2813ea..22a994f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -228,6 +228,12 @@ dependencies = [
]
[[package]]
+name = "deunicode"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
+
+[[package]]
name = "devise"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -305,6 +311,16 @@ dependencies = [
]
[[package]]
+name = "error-chain"
+version = "0.12.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
+dependencies = [
+ "backtrace",
+ "version_check 0.9.2",
+]
+
+[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -416,6 +432,12 @@ checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
[[package]]
name = "glob"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
+
+[[package]]
+name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
@@ -465,6 +487,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
[[package]]
+name = "humansize"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
+
+[[package]]
name = "hyper"
version = "0.10.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -607,6 +635,12 @@ dependencies = [
]
[[package]]
+name = "maplit"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
+
+[[package]]
name = "matches"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -810,6 +844,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
+name = "pest"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
+dependencies = [
+ "ucd-trie",
+]
+
+[[package]]
+name = "pest_derive"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
+dependencies = [
+ "pest",
+ "pest_generator",
+]
+
+[[package]]
+name = "pest_generator"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55"
+dependencies = [
+ "pest",
+ "pest_meta",
+ "proc-macro2 1.0.19",
+ "quote 1.0.7",
+ "syn 1.0.39",
+]
+
+[[package]]
+name = "pest_meta"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
+dependencies = [
+ "maplit",
+ "pest",
+ "sha-1",
+]
+
+[[package]]
name = "polyval"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -988,7 +1065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb852e6da168fb948a8f2b798ba2e2f0e4fc860eae0efa9cf2bf0f5466bb0425"
dependencies = [
"devise",
- "glob",
+ "glob 0.3.0",
"indexmap",
"quote 0.6.13",
"rocket_http",
@@ -1003,6 +1080,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3946ca815127041d8f64455561031d058c22ae1b135251502c5ea523cf9e14b"
dependencies = [
"diesel",
+ "glob 0.3.0",
"log 0.4.11",
"notify",
"r2d2",
@@ -1010,6 +1088,7 @@ dependencies = [
"rocket_contrib_codegen",
"serde",
"serde_json",
+ "tera",
]
[[package]]
@@ -1115,6 +1194,18 @@ dependencies = [
]
[[package]]
+name = "sha-1"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
+dependencies = [
+ "block-buffer",
+ "digest",
+ "fake-simd",
+ "opaque-debug",
+]
+
+[[package]]
name = "sha2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1133,6 +1224,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
+name = "slug"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
+dependencies = [
+ "deunicode",
+]
+
+[[package]]
name = "smallvec"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1191,6 +1291,27 @@ dependencies = [
]
[[package]]
+name = "tera"
+version = "0.11.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3"
+dependencies = [
+ "chrono",
+ "error-chain",
+ "glob 0.2.11",
+ "humansize",
+ "lazy_static",
+ "pest",
+ "pest_derive",
+ "regex",
+ "serde",
+ "serde_json",
+ "slug",
+ "unic-segment",
+ "url",
+]
+
+[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1243,6 +1364,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
+name = "ucd-trie"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
+
+[[package]]
+name = "unic-char-property"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce36d3f7ce754afdbccccf8ff0dd0134e50fb44aaae579f96218856e9e5dbd1e"
+dependencies = [
+ "unic-char-range",
+]
+
+[[package]]
+name = "unic-char-range"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9ab85fab42ad1b26cafc03bf891f69cb4d6e15f491030e89a0122197baa8ae8"
+
+[[package]]
+name = "unic-common"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff8d4a7ade929ef7d971e16ced21a8cd56a63869aa6032dfb8cb083cf7d077bf"
+
+[[package]]
+name = "unic-segment"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9ca47cbb09fb5fcd066b5867d11dc528302fa465277882797d6a836e1ee6f9e"
+dependencies = [
+ "unic-ucd-segment",
+]
+
+[[package]]
+name = "unic-ucd-segment"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48f1a08ce0409a9e391b88d1930118eec48af12742fc538bcec55f775865776e"
+dependencies = [
+ "unic-char-property",
+ "unic-char-range",
+ "unic-ucd-version",
+]
+
+[[package]]
+name = "unic-ucd-version"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf1f5e6c6c53c2d0ece4a5964bc55fcff8602153063cb4fab20958ff32998ff6"
+dependencies = [
+ "unic-common",
+]
+
+[[package]]
name = "unicase"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 1593886..7e25b9e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,7 @@ serde = { version = "1.0.115", features = ["derive"] }
[dependencies.rocket_contrib]
version = "0.4.5"
default-features = false
-features = ["json", "serve", "diesel_postgres_pool"]
+features = ["json", "serve", "diesel_postgres_pool", "tera_templates"]
[dev-dependencies]
lazy_static = "~1.3.0"
diff --git a/src/controllers/room.rs b/src/controllers/room.rs
index 419afae..43d3e60 100644
--- a/src/controllers/room.rs
+++ b/src/controllers/room.rs
@@ -24,9 +24,22 @@ use crate::{
use rocket::get;
use rocket_contrib::{
json::Json,
+ templates::Template,
};
+use serde::Serialize;
-#[get("/")]
-pub fn get_rooms(db: db::Connection) -> Json<Vec<models::Room>> {
+#[derive(Serialize)]
+struct Context {
+ rooms : Vec<models::Room>,
+}
+
+#[get("/", rank = 1)]
+pub fn list_rooms(db: db::Connection) -> Template {
+ let ctx = Context { rooms: db.get_rooms().unwrap() };
+ Template::render("room/list", &ctx)
+}
+
+#[get("/", format = "application/json", rank = 2)]
+pub fn get_rooms_json(db: db::Connection) -> Json<Vec<models::Room>> {
Json(db.get_rooms().unwrap())
}
diff --git a/src/lib.rs b/src/lib.rs
index c836273..3b35594 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,8 +42,9 @@ pub fn build_rocket(db_url: &str) -> Result<rocket::Rocket, Box<dyn Error>> {
Ok(rocket::custom(config)
.attach(db::Connection::fairing())
+ .attach(rocket_contrib::templates::Template::fairing())
.mount("/", rocket_contrib::serve::StaticFiles::from("./public"))
- .mount("/rooms", routes![room::get_rooms])
+ .mount("/rooms", routes![room::get_rooms_json, room::list_rooms])
.mount("/films", routes![film::get_films])
.mount("/screenings", routes![screening::get_aggregated_screenings]))
}
diff --git a/templates/room/list.tera b/templates/room/list.tera
new file mode 100644
index 0000000..fddad57
--- /dev/null
+++ b/templates/room/list.tera
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Room list</title>
+</head>
+<body>
+<h1>Rooms</h1>
+
+{% if rooms | length <= 0%}
+No rooms defined.
+{% endif %}
+</body>
+</html>