diff --git a/doc-generator/markdown/en/docs/latest/index.yaml b/doc-generator/markdown/en/docs/latest/index.yaml new file mode 100644 index 0000000..e1c5e98 --- /dev/null +++ b/doc-generator/markdown/en/docs/latest/index.yaml @@ -0,0 +1,13 @@ +path: "" +name: "" +has_index: true +children: +- path: index + +- path: flow-control + name: Flow control + has_index: true + children: + - path: arrays + - path: conditionals + diff --git a/doc-generator/markdown/en/stdlib/latest/index.toml b/doc-generator/markdown/en/stdlib/latest/index.toml index 8666146..9499ae0 100644 --- a/doc-generator/markdown/en/stdlib/latest/index.toml +++ b/doc-generator/markdown/en/stdlib/latest/index.toml @@ -1 +1,7 @@ -entry-point = "index" \ No newline at end of file +entry-point = "index" + +[prelude] +section-name = "Prelude" +children = [ + "String" +] diff --git a/doc-generator/markdown/en/stdlib/latest/index.yaml b/doc-generator/markdown/en/stdlib/latest/index.yaml new file mode 100644 index 0000000..1a68e74 --- /dev/null +++ b/doc-generator/markdown/en/stdlib/latest/index.yaml @@ -0,0 +1 @@ +path: "" \ No newline at end of file diff --git a/doc-generator/src/pages/mod.rs b/doc-generator/src/pages/mod.rs index a04095b..d56827b 100644 --- a/doc-generator/src/pages/mod.rs +++ b/doc-generator/src/pages/mod.rs @@ -1,4 +1,4 @@ -use std::{path::Path, fs}; +use std::{fs, path::Path}; use yaml_rust::{Yaml, YamlLoader}; @@ -61,12 +61,10 @@ fn generate_pages_tree(values: &Yaml) -> Node { let children_nodes: Vec = children .into_iter() - .map(|values| { - generate_pages_tree(values) - }) + .map(|values| generate_pages_tree(values)) .collect(); - Node::Folder(Folder { + Node::Folder(Folder { path, name, has_index, @@ -79,27 +77,71 @@ fn generate_pages_tree(values: &Yaml) -> Node { } } -fn generate_pages_html(file_tree: &Node) -> String { +fn generate_pages_html(file_tree: &Node, current_path: &Path) -> String { match file_tree { Node::File(file) => { - String::from("File :D") + if file.path == "index" { + format!( + "
  • + Index +
  • ", + current_path.to_str().unwrap() + ) + } else if file.path == "" { + String::from("") + } else { + format!( + "
  • + {} +
  • ", + current_path.to_str().unwrap(), + file.path, + file.path + ) + } } Node::Folder(folder) => { - String::from("Folder :D") + let mut new_path = current_path.to_path_buf(); + new_path.push(folder.path); + + let sub_nodes_html: Vec = folder + .children + .iter() + .map(|n| generate_pages_html(n, &new_path)) + .collect(); + + // This is true for the root of the YAML file + if folder.path == "" { + format!("", sub_nodes_html.join("")) + } else { + format!( + "
  • +
    {}
    +
      {}
    +
  • ", + folder.name, + sub_nodes_html.join("") + ) + } } } } -pub fn generate_pages(yaml_folder: &Path) -> String { - let mut yaml_path = yaml_folder.canonicalize().unwrap(); +pub fn generate_pages(yaml_folder: &Path, input_folder: &Path) -> String { + let mut yaml_path = yaml_folder.canonicalize().unwrap(); yaml_path.push("index.yaml"); let yaml_bytes = fs::read(yaml_path).expect("File index.yaml MUST exist"); let yaml = String::from_utf8(yaml_bytes).expect("YAML index file MUST be valid UTF-8"); - let yaml_docs = YamlLoader::load_from_str(yaml.as_str()).expect("YAML file MUST contain valid YAML"); + let yaml_docs = + YamlLoader::load_from_str(yaml.as_str()).expect("YAML file MUST contain valid YAML"); let yaml = &yaml_docs[0]; + let input_folder = input_folder.canonicalize().unwrap(); + let yaml_folder_2 = yaml_folder.canonicalize().unwrap(); + let web_absolute_path = yaml_folder_2.strip_prefix(input_folder).unwrap(); + let root_node = generate_pages_tree(yaml); - generate_pages_html(&root_node) + generate_pages_html(&root_node, web_absolute_path) } diff --git a/doc-generator/src/processor.rs b/doc-generator/src/processor.rs index 9032f56..6d6896f 100644 --- a/doc-generator/src/processor.rs +++ b/doc-generator/src/processor.rs @@ -59,7 +59,8 @@ pub fn search_config_file(current_path: &Path, input_folder: &Path, output_folde } fn process_toml(current_path: &Path, input_folder: &Path, output_folder: &Path) { - println!("YAML:{}", crate::pages::generate_pages(current_path)); + let file_tree_html = crate::pages::generate_pages(current_path, input_folder); + let mut toml_file_path = current_path.canonicalize().unwrap(); toml_file_path.push("index.toml"); @@ -81,7 +82,7 @@ fn process_toml(current_path: &Path, input_folder: &Path, output_folder: &Path) let mut file = current_path.canonicalize().unwrap(); file.push(format!("{}.md", entry_point)); - compile_md_file(&file, input_folder, output_folder) + compile_md_file(&file, input_folder, output_folder, &file_tree_html) .expect("FS: entry-point file MUST point to a valid file"); // Subsequent keys should have schema: @@ -114,7 +115,7 @@ fn process_toml(current_path: &Path, input_folder: &Path, output_folder: &Path) file.push(key.clone()); file.push(format!("{}.md", file_name)); - compile_md_file(&file, input_folder, output_folder) + compile_md_file(&file, input_folder, output_folder, &file_tree_html) .expect(format!("Error compiling file {}", file.display()).as_str()); } } @@ -127,6 +128,7 @@ fn compile_md_file( file: &PathBuf, input_folder: &Path, output_folder: &Path, + file_tree_html: &String, ) -> Result<(), String> { // /home/fernando/misti/docs/markdown let input_folder = input_folder.canonicalize().unwrap(); @@ -164,7 +166,8 @@ fn compile_md_file( let final_output = template_contents .replace("{{markdown}}", &html_text) - .replace("{{sidebar}}", &sidebar_html); + .replace("{{sidebar}}", &sidebar_html) + .replace("{{pages}}", &file_tree_html); // // Write to disk diff --git a/doc-generator/static/template.html b/doc-generator/static/template.html index 09f3d7c..54f3557 100644 --- a/doc-generator/static/template.html +++ b/doc-generator/static/template.html @@ -24,7 +24,7 @@
    @@ -39,9 +39,12 @@

    Misti

    - {{pages}} + +
    -