diff --git a/Cargo.lock b/Cargo.lock index c6ae309..42c2af9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,7 +351,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "form-generator" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "askama", diff --git a/Cargo.toml b/Cargo.toml index e108aeb..72b20e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "form-generator" -version = "0.1.0" +version = "0.1.1" edition = "2024" [dependencies] diff --git a/flake.nix b/flake.nix index 869c1cd..43d1a50 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ { packages.default = pkgs.rustPlatform.buildRustPackage { pname = "form-generator"; - version = "0.1.0"; + version = "0.1.1"; src = ./.; cargoLock = { diff --git a/src/main.rs b/src/main.rs index 13ca5c0..428b75a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,6 @@ struct FieldDef { #[derive(Debug, Deserialize)] struct AppConfig { - json_output: String, submit_button: String, fields: Vec, } @@ -60,6 +59,7 @@ struct ResponseEntry { struct AppState { cfg: Arc, file_lock: Arc>, + output_file: String, } #[tokio::main] @@ -74,7 +74,7 @@ async fn main() -> anyhow::Result<()> { tracing::info!( "Loaded config: '{}', writing answers to '{}' with {} fields", cli.config_path, - cfg.json_output, + cli.output_file, cfg.fields.len() ); @@ -105,6 +105,7 @@ async fn main() -> anyhow::Result<()> { let state = AppState { cfg: Arc::new(cfg), file_lock: Arc::new(Mutex::new(())), + output_file: cli.output_file.clone(), }; let app = Router::new() @@ -160,7 +161,7 @@ async fn submit( }; let _guard = state.file_lock.lock().await; - let path = &state.cfg.json_output; + let path = &state.output_file; let mut existing: Vec = match std::fs::read_to_string(path) { Ok(raw) => serde_json::from_str(&raw).unwrap_or(Vec::new()), diff --git a/templates/form.html b/templates/form.html index a1ea6d4..0e37090 100644 --- a/templates/form.html +++ b/templates/form.html @@ -4,7 +4,7 @@ {% block content %}
-
+ {% for f in fields %} {% if f.html_before.is_some() %} {{ f.html_before.as_ref().unwrap() | safe }}