summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/dev_mode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/handlebars/examples/dev_mode.rs')
-rw-r--r--vendor/handlebars/examples/dev_mode.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/vendor/handlebars/examples/dev_mode.rs b/vendor/handlebars/examples/dev_mode.rs
new file mode 100644
index 000000000..99017474f
--- /dev/null
+++ b/vendor/handlebars/examples/dev_mode.rs
@@ -0,0 +1,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;
+}