1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pub use rdxl_static_macros::*;

pub struct DotHtml {
   pub content: String,
}

pub enum Dot {
   Html(DotHtml)
}

pub struct DotLhs {
   pub filepath: String,
}

fn build_dirs(dir: &std::path::Path) -> std::io::Result<Vec<(DotLhs,Dot)>> {
    use std::io::Read;
    let mut dots = Vec::new();
    if dir.is_dir() {
        for entry in std::fs::read_dir(dir)? {
            let entry = entry?;
            let path = entry.path();
            if path.is_dir() {
                build_dirs(&path)?;
            } else {
                let mut file = std::fs::File::open(&path).expect(&format!("Unable to open file: {:?}", path));
                let mut src = String::new();
                file.read_to_string(&mut src).expect(&format!("Unable to read file: {:?}", path));

                let file_content = syn::parse_file(&src)
                                   .expect(&format!("Unable to parse file: {:?}", path));

                for i in file_content.items.iter() {
                   if let syn::Item::Fn(f) = i {
                      println!("cargo:warning=maybe dot-fn {}", f.sig.ident.to_string());
                   }
                }
                println!("cargo:warning=extract dots from file: {:?}", path);
                //extract dots from file
            }
        }
    }
    Ok(dots)
}

pub fn build() {
   let _dots = build_dirs(&std::path::Path::new("src")).expect("could not extract dots from source directory");
   std::fs::File::create("src/site.rs").expect("could not create src/site.rs");
}