From: Andrea Zagli Date: Wed, 1 Oct 2025 09:50:16 +0000 (+0200) Subject: c2rs: added with_attachments. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=290d59a492fcc6b550373f4a26cf03f5b3ebf7fc;p=rust%2Fzakform c2rs: added with_attachments. --- diff --git a/src/bin/c2rs.rs b/src/bin/c2rs.rs index 5c8d8ca..dc7830a 100644 --- a/src/bin/c2rs.rs +++ b/src/bin/c2rs.rs @@ -170,12 +170,13 @@ fn main() { writeln!(output, "use zakform::fields::{{TField, FOption}};"); writeln!(output, ""); - writeln!(output, "pub fn get_form() -> (zakform::form::Form, String) {{"); + writeln!(output, "pub fn get_form() -> (zakform::form::Form, String, String) {{"); writeln!(output, ""); writeln!(output, "let mut f = zakform::form::Form::new();"); writeln!(output, ""); writeln!(output, "let mut with_validators = String::new();"); + writeln!(output, "let mut with_attachments = String::new();"); let mut struct_db = String::new(); let mut struct_form = String::new(); @@ -312,7 +313,7 @@ fn main() { }; } - for (i, validator) in e.validators.into_iter().enumerate() { + for (i, validator) in e.validators.iter().enumerate() { match validator.vtype.as_str() { "zak_form_element_validator_notempty" => { writeln!(output, r#"fi.add_validator(Box::new(zakform::validators::ValidatorNotEmpty::new("{}_notempty")));"#, e.id); }, "zak_form_element_validator_date" => { @@ -353,11 +354,26 @@ fn main() { } writeln!(output, "f.add_field(Box::new(fi));"); - writeln!(output, r#"with_validators.push_str(",'{}'");"#, e.id); + + if !e.validators.is_empty() { + writeln!(output, r#"with_validators.push_str(",'{}'");"#, e.id); + } + + if e.etype == "zak_form_cgi_form_element_file" { + writeln!(output, r#"with_attachments.push_str(",'{}'");"#, e.id); + } } writeln!(output, ""); - writeln!(output, "(f, with_validators)"); + writeln!(output, r#"if with_validators.starts_with(",") {{ + with_validators.remove(0); + }}"#); + writeln!(output, r#"if with_attachments.starts_with(",") {{ + with_attachments.remove(0); + }}"#); + + writeln!(output, ""); + writeln!(output, "(f, with_validators, with_attachments)"); writeln!(output, "}}"); /* db struct */