summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/dev_mode.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/handlebars/examples/dev_mode.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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;
+}