>
{
let mut handlebars = Handlebars::new ();
handlebars.set_strict_mode (true);
+ let asset_root = asset_root.join ("handlebars/server");
+
for (k, v) in vec! [
("file_server_dir", "file_server_dir.html"),
("file_server_root", "file_server_root.html"),
].into_iter () {
- handlebars.register_template_file (k, format! ("ptth_handlebars/{}", v))?;
+ handlebars.register_template_file (k, asset_root.join (v))?;
}
Ok (handlebars)
@@ -770,7 +780,7 @@ mod tests {
let mut rt = Runtime::new ().unwrap ();
rt.block_on (async {
- let handlebars = load_templates ().unwrap ();
+ let handlebars = load_templates (&PathBuf::new ()).unwrap ();
let server_info = ServerInfo {
server_name: "PTTH File Server".to_string (),
};
@@ -879,7 +889,9 @@ mod tests {
"Hello world, this is a complicated very simple example.
\n"
),
].into_iter () {
- assert_eq! (expected, &render_markdown (input.as_bytes ()).unwrap ());
+ let mut out = String::default ();
+ render_markdown (input.as_bytes (), &mut out).unwrap ();
+ assert_eq! (expected, &out);
}
}
}
diff --git a/src/server/mod.rs b/src/server/mod.rs
index b6bc761..7171c68 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -128,10 +128,13 @@ pub struct Config {
pub async fn run_server (
config_file: ConfigFile,
shutdown_oneshot: oneshot::Receiver <()>,
- hidden_path: Option
+ hidden_path: Option ,
+ asset_root: Option
)
-> Result <(), Box >
{
+ let asset_root = asset_root.unwrap_or_else (|| PathBuf::new ());
+
use std::convert::TryInto;
if crate::password_is_bad (config_file.api_key.clone ()) {
@@ -154,7 +157,7 @@ pub async fn run_server (
.default_headers (headers)
.timeout (Duration::from_secs (40))
.build ().unwrap ();
- let handlebars = file_server::load_templates ()?;
+ let handlebars = file_server::load_templates (&asset_root).expect ("Can't load Handlebars templates");
let state = Arc::new (ServerState {
config: Config {