--- /dev/null
+use std::{
+ env,
+ fs
+};
+
+use yaserde::*;
+use yaserde_derive::*;
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(root = "zakform")]
+pub struct ZakForm {
+ #[yaserde(rename = "element")]
+ pub elements: Vec<ZakFormElement>
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "element")]
+pub struct ZakFormElement {
+ #[yaserde(attribute, rename = "type")]
+ pub etype: String,
+ pub id: String,
+ pub label: String,
+ #[yaserde(rename = "long-name")]
+ pub long_name: String,
+ #[yaserde(rename = "dbtype")]
+ pub dbtype: String,
+ #[yaserde(rename = "maxlength")]
+ pub max_length: i32,
+ pub rows: i32,
+ pub format: Option<ZakFormElementFormat>,
+ #[yaserde(rename = "default-value")]
+ pub default_value: String,
+ pub editable: String,
+ #[yaserde(rename = "to-load")]
+ pub to_load: String,
+ #[yaserde(rename = "to-save")]
+ pub to_save: String,
+ pub placeholder: String,
+
+ #[yaserde(rename = "zak-cgi-options")]
+ pub zakcgi_options: Option<ZakFormElementRadioOptions>,
+
+ #[yaserde(rename = "zak-cgi-text")]
+ pub zakcgi_text: String,
+
+ #[yaserde(rename = "zak-cgi-inline")]
+ pub zakcgi_inline: String,
+
+ #[yaserde(rename = "filter")]
+ pub filters: Vec<ZakFormElementFilter>,
+
+ #[yaserde(rename = "validator")]
+ pub validators: Vec<ZakFormElementValidator>,
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "format")]
+pub struct ZakFormElementFormat {
+ #[yaserde(attribute)]
+ pub thousands_separator: String,
+ #[yaserde(attribute)]
+ pub decimals: i32,
+ #[yaserde(text)]
+ pub format: String,
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "filter")]
+pub struct ZakFormElementFilter {
+ #[yaserde(attribute, rename = "type")]
+ pub ftype: String,
+ #[yaserde(text)]
+ pub text: String,
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "validator")]
+pub struct ZakFormElementValidator {
+ #[yaserde(attribute, rename = "type")]
+ pub vtype: String,
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "zak-cgi-options")]
+pub struct ZakFormElementRadioOptions {
+ #[yaserde(rename = "option")]
+ pub options: Vec<ZakFormElementRadioOption>,
+}
+
+#[derive(Default, Debug, Clone, PartialEq, YaDeserialize)]
+#[yaserde(rename = "option")]
+pub struct ZakFormElementRadioOption {
+ pub value: String,
+ pub content: String,
+}
+
+fn main() {
+ let formfile = env::args().nth(1).expect("no form file given");
+
+ let content = fs::read_to_string(formfile).expect("something went wrong reading the file");
+
+ let form: ZakForm = de::from_str(&content).unwrap();
+
+ println!("{:?}", form);
+
+ println!("let mut f = zakform::form::Form::new();");
+
+ for e in form.elements {
+ 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); },
+ "zak_form_cgi_form_element_radio" => { println!(r#"let mut fi = zakform::fields::FieldRadio::new("{}")"#, e.id); },
+ "zak_form_cgi_form_element_select" => { println!(r#"let mut fi = zakform::fields::FieldSelect::new("{}")"#, e.id); },
+ _ => { continue; },
+ };
+
+ if e.label != "" {
+ println!(r#"fi.set_label("{}")"#, e.label);
+ }
+
+ if e.max_length > 0 {
+ println!("fi.set_maxlen({})", e.max_length);
+ }
+ if e.rows > 0 {
+ println!("fi.set_rows({})", e.rows);
+ }
+
+ match e.format {
+ Some(f) => {
+
+ },
+ None => { },
+ };
+
+ for filter in e.filters {
+ match filter.ftype.as_str() {
+ "zak_form_element_filter_trim" => { println!("fi.add_filter(zakform::filters::filter_trim);"); },
+ "zak_form_element_filter_luc" => {
+ match filter.text.as_str() {
+ "upper" => { println!("fi.add_filter(zakform::filters::filter_uppercase);"); },
+ "lower" => { println!("fi.add_filter(zakform::filters::filter_lowercase);"); },
+ "camel" => { println!("fi.add_filter(zakform::filters::filter_camelcase);"); },
+ _ => { },
+ };
+ },
+ _ => { },
+ };
+ }
+
+ println!("f.add_field(Box::new(fi);");
+ }
+}