summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/dev_mode.rs
blob: 99017474f8248e4bbf6cb989a4ec17319ba19509 (plain)
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
use std::sync::Arc;

use handlebars::Handlebars;
use serde_json::json;
use warp::{self, Filter};

#[tokio::main]
async fn main() {
    let mut reg = Handlebars::new();
    // enable dev mode for template reloading
    reg.set_dev_mode(true);
    // register a template from the file
    // modified the file after the server starts to see things changing
    reg.register_template_file("tpl", "./examples/dev_mode/template.hbs")
        .unwrap();

    let hbs = Arc::new(reg);
    let route = warp::get().map(move || {
        let result = hbs
            .render("tpl", &json!({"model": "t14s", "brand": "Thinkpad"}))
            .unwrap_or_else(|e| e.to_string());
        warp::reply::html(result)
    });

    println!("Edit ./examples/dev_mode/template.hbs and request http://localhost:3030 to see the change on the run.");
    warp::serve(route).run(([127, 0, 0, 1], 3030)).await;
}