all repos — breadsite @ 2ccf4bf1f5b81ad2f235714775e0921f3432d509

Unnamed repository; edit this file 'description' to name the repository.

src/main.rs (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
use actix_web::{get, App, HttpServer, Result as AwResult};
use actix_files::Files;
use maud::{DOCTYPE, html, Markup};
use std::io;
use chrono::Local;

fn head(page_title: &str) -> Markup {
    html! {
        (DOCTYPE)
        head {
            meta charset="utf-8";
            title { (page_title) }
            link rel="stylesheet" href="static/style.css";
        }
    }
}

fn segment_bar(count: i32, progress: i32) -> Markup {
    html!(
        div.segments {
            @for i in 0..count {
                @if i >= progress {
                    (segment(false))
                } @else {
                    (segment(true))
                }
            }
        }
    )
}

fn segment(activated: bool) -> Markup {
    html! {
        @if activated {
            div.segment.activated{}
        } @else {
            div.segment{}
        }
    }
}

fn container(content: Markup) -> Markup {
    html! {
        div.container {
            ( content )
        }
    }
}

fn layout() -> Markup {
    let time = Local::now();
    html! {
        (container(html!(
            h1 { (time) }
            h2 { (time) }
            h3 { (time) }
            ( segment_bar(10, 4) )
        )))
    }
}

fn page() -> Markup {
    html! {
        (head("breadsite"))
        body {
            (layout())
        }
    }
}

#[get("/")]
async fn index() -> AwResult<Markup> {
    Ok(html! {
        (page())
    })
}

#[actix_web::main]
async fn main() -> io::Result<()> {
    HttpServer::new(|| App::new()
        .service(index)
        .service(Files::new("/static", "./static"))
    )
        .bind(("localhost", 8080))?
        .run()
        .await
}