Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from sunng87/feature/template-source
Dev mode and template sources
- Loading branch information
Showing
17 changed files
with
436 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>My Laptop</title> | ||
</head> | ||
<body> | ||
<p>My current laptop is {{brand}}: <b>{{model}}</b></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
let goals = params[0]; | ||
|
||
len(goals) | ||
goals.len() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.