fs
};
-use yaserde::*;
-use yaserde_derive::*;
+use quick_xml::de::from_str;
+use serde::Deserialize;
+use serde_derive::Deserialize;
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(root = "zakform")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "zakform")]
pub struct ZakForm {
- #[yaserde(rename = "element")]
+ #[serde(rename = "element")]
pub elements: Vec<ZakFormElement>
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "element")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "element")]
pub struct ZakFormElement {
- #[yaserde(attribute, rename = "type")]
+ #[serde(rename = "@type")]
pub etype: String,
pub id: String,
- pub label: String,
- #[yaserde(rename = "long-name")]
- pub long_name: String,
- #[yaserde(rename = "dbtype")]
+ pub label: Option<String>,
+ #[serde(rename = "long-name")]
+ pub long_name: Option<String>,
+ #[serde(rename = "type")]
pub dbtype: String,
- #[yaserde(rename = "maxlength")]
+ #[serde(rename = "maxlength")]
pub max_length: i32,
pub rows: i32,
pub format: Option<ZakFormElementFormat>,
- #[yaserde(rename = "default-value")]
+ #[serde(rename = "default-value")]
pub default_value: String,
pub editable: String,
- #[yaserde(rename = "to-load")]
+ #[serde(rename = "to-load")]
pub to_load: String,
- #[yaserde(rename = "to-save")]
+ #[serde(rename = "to-save")]
pub to_save: String,
pub placeholder: String,
- #[yaserde(rename = "option")]
+ #[serde(rename = "option")]
pub options: Vec<ZakFormElementSelectOption>,
- #[yaserde(rename = "zak-cgi-options")]
+ #[serde(rename = "zak-cgi-options")]
pub zakcgi_options: Option<ZakFormElementRadioOptions>,
- #[yaserde(rename = "zak-cgi-text")]
+ #[serde(rename = "zak-cgi-text")]
pub zakcgi_text: String,
- #[yaserde(rename = "zak-cgi-inline")]
+ #[serde(rename = "zak-cgi-inline")]
pub zakcgi_inline: String,
- #[yaserde(rename = "filter")]
+ #[serde(rename = "filter")]
pub filters: Vec<ZakFormElementFilter>,
- #[yaserde(rename = "validator")]
+ #[serde(rename = "validator")]
pub validators: Vec<ZakFormElementValidator>,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "format")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "format")]
pub struct ZakFormElementFormat {
- #[yaserde(attribute)]
+ #[serde(rename = "@thousands_separator")]
pub thousands_separator: String,
- #[yaserde(attribute)]
+ #[serde(rename = "@decimals")]
pub decimals: i32,
- #[yaserde(text)]
+ #[serde(rename = "$text")]
pub format: String,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "filter")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "filter")]
pub struct ZakFormElementFilter {
- #[yaserde(attribute, rename = "type")]
+ #[serde(rename = "@type")]
pub ftype: String,
- #[yaserde(text)]
+ #[serde(rename = "$text")]
pub text: String,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "validator")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "validator")]
pub struct ZakFormElementValidator {
- #[yaserde(attribute, rename = "type")]
+ #[serde(rename = "@type")]
pub vtype: String,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "option")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "option")]
pub struct ZakFormElementSelectOption {
pub id: String,
- #[yaserde(text)]
+ #[serde(rename = "$text")]
pub text: String,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "zak-cgi-options")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "zak-cgi-options")]
pub struct ZakFormElementRadioOptions {
- #[yaserde(rename = "option")]
+ #[serde(rename = "option")]
pub options: Vec<ZakFormElementRadioOption>,
}
-#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
-#[yaserde(rename = "option")]
+#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
+#[serde(default, rename = "option")]
pub struct ZakFormElementRadioOption {
pub value: String,
pub content: String,
let content = fs::read_to_string(formfile).expect("something went wrong reading the file");
- let form: ZakForm = de::from_str(&content).unwrap();
+ let form: ZakForm = from_str(&content).unwrap();
println!("{:?}", form);
println!("let mut f = zakform::form::Form::new();");
for e in form.elements {
+ println!("");
+
match e.etype.as_str() {
"zak_form_cgi_form_element_text" => { println!(r#"let mut fi = zakform::fields::FieldText::new("{}")"#, e.id); },
"zak_form_cgi_form_element_text_area" => { println!(r#"let mut fi = zakform::fields::FieldTextArea::new("{}")"#, e.id); },
_ => { continue; },
};
- if e.label != "" {
- println!(r#"fi.set_label("{}")"#, e.label);
+ if let Some(l) = e.label {
+ if l != "" {
+ println!(r#"fi.set_label("{}")"#, l);
+ }
}
if e.max_length > 0 {