commit 593cfb02dd05f04dc86493c2e40bc6df5acd86d0 Author: Tait Hoyem Date: Tue Jul 26 10:53:30 2022 -0600 Inital commit diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2129a21 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "localdriver" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rocket = "0.5.0-rc.2" + +[dependencies.rocket_dyn_templates] +version = "0.1.0-rc.2" +features = ["tera"] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..20bc1f7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,50 @@ +#[macro_use] extern crate rocket; +use rocket::tokio::time::{sleep, Duration}; +use rocket::form::Form; +use rocket_dyn_templates::{Template, context}; + +#[derive(FromForm)] +struct Note<'r> { + title: &'r str, + description: &'r str, +} + +#[post("/form", data="")] +async fn form(note: Form>) -> String { + format!("New note: {} with description\n{}.", note.title, note.description) +} + +#[get("/hello/")] +async fn hello(name: &str) -> String { + format!("Hello, {}", name) +} + +fn test1() -> Vec { + Vec::new() +} + +#[get("/")] +async fn index() -> Template { + let notes: Vec> = Vec::new(); + notes.append(Note{ title: "Test", description: "Test" }); + Template::render("index", context!{ + title: "Home", + name: "Tait Hoyem" + }) +} + +#[get("/delay/")] +async fn delay(seconds: u64) -> String { + sleep(Duration::from_secs(seconds)).await; + format!("Waited for {} seconds", seconds) +} + +#[rocket::main] +async fn main() -> Result<(), rocket::Error> { + let _rocket = rocket::build() + .mount("/", routes![index, delay, hello, form]) + .attach(Template::fairing()) + .launch() + .await?; + Ok(()) +} diff --git a/templates/footer.html.tera b/templates/footer.html.tera new file mode 100644 index 0000000..a75386c --- /dev/null +++ b/templates/footer.html.tera @@ -0,0 +1 @@ +© Local Driver Technologies, Inc. diff --git a/templates/header.html.tera b/templates/header.html.tera new file mode 100644 index 0000000..70aa7a5 --- /dev/null +++ b/templates/header.html.tera @@ -0,0 +1,3 @@ + diff --git a/templates/index.html.tera b/templates/index.html.tera new file mode 100644 index 0000000..0bcdb3d --- /dev/null +++ b/templates/index.html.tera @@ -0,0 +1,9 @@ +{% extends "master" %} +{% block content %} +

Hello world, {{ name }}

+
    + {% for n in note %} +
  • {{ n.title }}
  • + {% endfor %} +
+{% endblock %} diff --git a/templates/master.html.tera b/templates/master.html.tera new file mode 100644 index 0000000..b6f8c94 --- /dev/null +++ b/templates/master.html.tera @@ -0,0 +1,17 @@ + + + + {{ title }} | example.org + + +
+ {% include "header" %} +
+
+ {% block content %}{% endblock %} +
+ + +