wild-doc

Example

```rust use wild_doc::*;

let dir="./wd-test/"; if std::path::Path::new(dir).exists(){ std::fs::removedirall(dir).unwrap(); } std::fs::createdirall(dir).unwrap();

let mut wd=WildDoc::new( dir ,IncludeLocal::new("./include/") ).unwrap();

//update data. /wd.run(br#" Noah US Liam US Olivia UK "#,b"").unwrap();/

let updatexml=br#" "#; wd.run(updatexml,br#"{ "name":"Noah" ,"from":"US" }"#).unwrap(); wd.run(updatexml,br#"{ "name":"Liam" ,"from":"US" }"#).unwrap(); wd.run(updatexml,br#"{ "name":"Olivia" ,"from":"UK" }"#).unwrap();

//select data. let r=wd.run(br#"

find persons.
"#,b"").unwrap(); println!("{}",std::str::from_utf8(r.body()).unwrap());

//seaech data let r=wd.run(br#"

find persons from the US.
"#,b"").unwrap(); println!("{}",std::str::from_utf8(r.body()).unwrap());

//use javascript let r=wd.run(br#"

    const ymd=function(){
        const now=new Date();
        return now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
    };
    wd.general.uk="UK";
    wd.general.ymd=function(){
        const now=new Date();
        return now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
    };
    wd.general.result_options['test']="OK";
?>
<wd:search name="p" collection="person">
    <field name="country" method="match" value:js="wd.general.uk" />
</wd:search>
<wd:result var="q" search="p">
    <div>
        <wd:print value:js="wd.general.ymd()" />
    </div>
    <div>
        find <wd:print value:js="q.len" /> persons from the <wd:print value:js="wd.general.uk" />.
    </div>
    <ul>
        <wd:for var="person" in:var="q.rows"><li>
            <wd:print value:var="person.row" /> : <wd:print value:var="person.field.name" /> : <wd:print value:var="personn.field.country" />
        </li></wd:for>
    </ul>
</wd:result><global var="result_options" value:js="wd.general.result_options" />

"#,b"").unwrap(); println!("{} : {}",std::str::fromutf8(r.body()).unwrap(),r.optionsjson());

//search in update section. wd.run(br#" hoge: Renamed "#,b"").unwrap(); let r=wd.run(br#"

find persons.
"#,b"").unwrap(); println!("{}",std::str::from_utf8(r.body()).unwrap());

//use WebAPI let r=wd.run(br#"

    wd.general.result_options={};

    wd.general.a="OK";
    wd.stack.push({
        hoge:{
            hoge:"A"
        }
        ,a:1
    });
    console.log(crypto.randomUUID());
    wd.result_options.test="TEST";
    wd.result_options.test2=crypto.randomUUID();
?>
a:<wd:print value:js="wd.general.a" />
v:<wd:print value:var="a" />
input:<wd:print value:var="input.name" />
<?js
    wd.stack.pop();
    wd.general.a="OK2";
    wd.general.b=1>2;
?>
a:<wd:print value:js="wd.general.a" />
v:<wd:print value:js="wd.general.b" /><global var="result_options" value:js="wd.result_options" />

"#,br#"{ "name":"Ken" ,"from":"US" }"#).unwrap(); println!("{} : {}",std::str::fromutf8(r.body()).unwrap(),r.optionsjson()); ```

Include file

layout.xml

xml <html> <head> <title>HTML include test</title> </head> <body> <wd:include src:var="body_path" /> </body> </html>

body.xml

xml BODY

rust

rust let r=wd.run(br#"<wd:local body_path="body.xml"> <wd:include src="layout.xml" /> <wd:local>"#,b""); println!("{}",r);

output

html <html> <head> <title>HTML include test</title> </head> <body> BODY </body> </html>

Use python

Specify features in Cargo.toml. toml wild-doc = { version = "x" , path = "../wild-doc" ,features=[ "js","py" ] }

code

rust //use WebAPI let r=wd.run(br#"<?py hoge=100 def get_200(): return 200 ?><wd:print value:py="get_200()" />"#,b"").unwrap();