From: Ian Jackson Date: Tue, 29 Dec 2020 02:05:04 +0000 (+0000) Subject: debug template injection X-Git-Tag: otter-0.2.0~93 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=051feec0b4a22e4eccfff880c55ddc75cdf2fba0;p=otter.git debug template injection Signed-off-by: Ian Jackson --- diff --git a/src/bin/daemon-otter.rs b/src/bin/daemon-otter.rs index 25cd534d..7626d799 100644 --- a/src/bin/daemon-otter.rs +++ b/src/bin/daemon-otter.rs @@ -12,7 +12,9 @@ use rocket_contrib::serve::StaticFiles; use otter::imports::*; #[derive(Serialize,Debug)] -struct FrontPageRenderContext { } +struct FrontPageRenderContext { + debug_js_inject: Arc, +} #[derive(Copy,Clone,Debug)] enum ResourceLocation { Main, Wasm(&'static str), } @@ -63,6 +65,7 @@ struct LoadingRenderContext<'r> { nick: String, layout: PresentationLayout, ptoken: &'r RawTokenVal, + debug_js_inject: Arc, } #[get("/")] #[throws(OE)] @@ -88,11 +91,14 @@ fn loading(layout: Option, ia: PlayerQueryString) nick: gpl.nick.clone(), game: g.name.to_string(), ptoken: &ia.raw_token, + debug_js_inject: config().debug_js_inject.clone(), layout, }; Template::render("loading", &c) } else { - let c = FrontPageRenderContext { }; + let c = FrontPageRenderContext { + debug_js_inject: config().debug_js_inject.clone(), + }; Template::render("front", &c) } } diff --git a/src/config.rs b/src/config.rs index 1f9bee4e..416e15e3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -34,6 +34,7 @@ pub struct ServerConfigSpec { pub bundled_sources: Option, pub shapelibs: Option>, pub sendmail: Option, + pub debug_js_inject_file: Option, } #[derive(Debug,Clone)] @@ -57,6 +58,7 @@ pub struct ServerConfig { pub bundled_sources: String, pub shapelibs: Vec, pub sendmail: String, + pub debug_js_inject: Arc, } impl TryFrom for WholeServerConfig { @@ -68,6 +70,7 @@ impl TryFrom for WholeServerConfig { http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, log, bundled_sources, shapelibs, sendmail, + debug_js_inject_file, } = spec; let defpath = |specd: Option, leaf: &str| -> String { @@ -127,11 +130,18 @@ impl TryFrom for WholeServerConfig { let log = LogSpecification::from_toml(&log) .context("log specification")?; + let debug_js_inject = Arc::new(match &debug_js_inject_file { + Some(f) => fs::read_to_string(f) + .with_context(|| f.clone()).context("debug_js_inject_file")?, + None => "".into(), + }); + let server = ServerConfig { save_dir, command_socket, debug, http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, bundled_sources, shapelibs, sendmail, + debug_js_inject, }; WholeServerConfig { server: Arc::new(server), diff --git a/templates/front.tera b/templates/front.tera index be885ab4..70571e65 100644 --- a/templates/front.tera +++ b/templates/front.tera @@ -1,6 +1,7 @@ Otter +{{ debug_js_inject }} diff --git a/templates/loading.tera b/templates/loading.tera index 5f3cd2a8..55da37e9 100644 --- a/templates/loading.tera +++ b/templates/loading.tera @@ -6,6 +6,7 @@ {{ game | escape }} - {{ nick | escape }} - Otter +{{ debug_js_inject }} diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index ec94fc26..f2840464 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -6,13 +6,16 @@ use otter_webdriver_tests::*; #[throws(AE)] fn main(){ - let (mut su, inst) = setup(module_path!()).always_context("setup")?; - let [alice, bob] : [Window; 2] = - su.setup_static_users(&inst)?.try_into().unwrap(); - debug!("ok {:?} {:?}", alice, bob); + { + let (mut su, inst) = setup(module_path!()).always_context("setup")?; + let [alice, bob] : [Window; 2] = + su.setup_static_users(&inst)?.try_into().unwrap(); + debug!("ok {:?} {:?}", alice, bob); - su.w(&alice)?.synch()?; + su.w(&alice)?.synch()?; - sleep(750 * MS); - debug!("finishing"); + sleep(750 * MS); + debug!("finishing"); + } + info!("ok"); }