aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontend/mod.rs2
-rw-r--r--src/frontend/pages/home.rs12
-rw-r--r--src/frontend/pages/layout.rs20
-rw-r--r--src/frontend/pages/mod.rs19
-rw-r--r--src/frontend/style/master.css0
-rw-r--r--src/frontend/style/mod.rs2
-rw-r--r--src/main.rs24
7 files changed, 79 insertions, 0 deletions
diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs
new file mode 100644
index 0000000..99c22f8
--- /dev/null
+++ b/src/frontend/mod.rs
@@ -0,0 +1,2 @@
+pub mod style;
+pub mod pages;
diff --git a/src/frontend/pages/home.rs b/src/frontend/pages/home.rs
new file mode 100644
index 0000000..b7f1a12
--- /dev/null
+++ b/src/frontend/pages/home.rs
@@ -0,0 +1,12 @@
+use crate::frontend::pages::{layout::Layout, HtmlTemplate};
+use actix_web::{get, Responder};
+
+#[get("/")]
+async fn page_home() -> impl Responder {
+ HtmlTemplate(Layout {
+ title: "Home - Jellything",
+ main: markup::new! {
+ h1 { "It works!" }
+ },
+ })
+}
diff --git a/src/frontend/pages/layout.rs b/src/frontend/pages/layout.rs
new file mode 100644
index 0000000..283721b
--- /dev/null
+++ b/src/frontend/pages/layout.rs
@@ -0,0 +1,20 @@
+use markup::Render;
+
+markup::define! {
+ Layout<'a, Main: Render>(title: &'a str, main: Main) {
+ @markup::doctype()
+ html {
+ head {
+ title { @title }
+ link[rel="stylesheet", href="/assets/style.css"];
+ }
+ body {
+ header { "Grain" }
+ #main {
+ @main
+ }
+ footer { span { "jellything" } }
+ }
+ }
+ }
+}
diff --git a/src/frontend/pages/mod.rs b/src/frontend/pages/mod.rs
new file mode 100644
index 0000000..08e0e77
--- /dev/null
+++ b/src/frontend/pages/mod.rs
@@ -0,0 +1,19 @@
+use actix_web::{body::BoxBody, http::StatusCode, HttpResponseBuilder, Responder};
+
+pub mod home;
+pub mod layout;
+
+struct HtmlTemplate<T>(pub T);
+
+impl<T: markup::Render> Responder for HtmlTemplate<T> {
+ type Body = BoxBody;
+
+ fn respond_to(self, req: &actix_web::HttpRequest) -> actix_web::HttpResponse<Self::Body> {
+ let mut out = String::new();
+ self.0.render(&mut out).unwrap();
+
+ HttpResponseBuilder::new(StatusCode::OK)
+ .body(out)
+ .respond_to(req)
+ }
+}
diff --git a/src/frontend/style/master.css b/src/frontend/style/master.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/frontend/style/master.css
diff --git a/src/frontend/style/mod.rs b/src/frontend/style/mod.rs
new file mode 100644
index 0000000..180fe0e
--- /dev/null
+++ b/src/frontend/style/mod.rs
@@ -0,0 +1,2 @@
+
+pub const CSS_BUNDLE: &'static str = include_str!("master.css");
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..5f49165
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,24 @@
+use crate::frontend::style::CSS_BUNDLE;
+use actix_web::{get, web, App, HttpServer, Responder};
+use frontend::pages::home::page_home;
+
+pub mod frontend;
+
+#[get("/assets/style.css")]
+async fn assets_style() -> impl Responder {
+ CSS_BUNDLE
+}
+
+#[get("/{name}")]
+async fn hello(name: web::Path<String>) -> impl Responder {
+ format!("Hello {}!", &name)
+}
+
+#[actix_web::main]
+async fn main() -> std::io::Result<()> {
+ env_logger::init_from_env("LOG");
+ HttpServer::new(|| App::new().service(page_home).service(hello))
+ .bind(("127.0.0.1", 8080))?
+ .run()
+ .await
+}