diff --git a/doc/assets/bookdata.graphml b/doc/assets/bookdata.graphml new file mode 100644 index 00000000..a1722780 --- /dev/null +++ b/doc/assets/bookdata.graphml @@ -0,0 +1,614 @@ + + + + + + + + + + + + + + + + + + + + + + + Config + + + + + + + + + + + + Book Content + + + + + + + + + + + CLI Args + + + + + + + + + + + + + + + + book.toml + + + + + + + + + + + + + + + + SUMMARY.md + + + + + + + + + + + + + + + + markdown +chapters + + + + + + + + + + + + + + + + template assets + + + + + + + + + + + + + + + + BookConfig + lang +project_root +book_dest +book_src +template_path + + + + + + + + + + + + + + + + + + + Book + config +metadata +toc + + + + + + + + + + + + + + + + + + + Renderer + render(book) + + + + + + + + + + + + + + + + + + + MDBook + project_root +books +renderer + + + + + + + + + + + + + + + + + + + images + + + + + + + + + + + + + + + + BookMetadata + title +author +publisher + + + + + + + + + + + + + + + + + + + Vec<Chapter> + title +file + + + + + + + + + + + + + + + + + + + YAML headers +(optional) + + + + + + + + + + + + + + + + + + summary +parser + + + + + + + + + + + + + + + + + + Vec<TocItem> + content +sub_items + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + behaviour control, +paths, target format + + + + + + + + + + + + + + paths + + + + + + + + + + + + + + metadata + + + + + + + + + + + + + + + + + + + + chapter list + + + + + + + + + + + + + + chapter attributes +chapter content + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + renderer specific +data + + + + + + + + + + + + template path + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/assets/bookdata.png b/doc/assets/bookdata.png new file mode 100644 index 00000000..f206399a Binary files /dev/null and b/doc/assets/bookdata.png differ diff --git a/doc/assets/structs-reorganized.png b/doc/assets/structs-reorganized.png new file mode 100644 index 00000000..cd33bb9c Binary files /dev/null and b/doc/assets/structs-reorganized.png differ diff --git a/doc/assets/structs-reorganized.pum b/doc/assets/structs-reorganized.pum new file mode 100644 index 00000000..6dc4de93 --- /dev/null +++ b/doc/assets/structs-reorganized.pum @@ -0,0 +1,129 @@ +@startuml + +class book::MDBook { + project_root : PathBuf + + books : HashMap<&'a str, Book> + + renderer : Box + livereload : Option + indent_spaces: i32 + multilingual: bool + + new(root) +} + +class book::book.Book { + config : BookConfig + metadata : BookMetadata + + chapters: Vec + + new(title) +} + +class book::bookconfig.BookConfig { + lang : Language + + project_root : PathBuf + book_dest : PathBuf + book_src : PathBuf + template_path : PathBuf + + new(root) +} + +class book::chapter.Chapter { +title +file +author +description +css_class +index : Vec + +new(title, file) +} + +namespace book::toc { + +class TocItem { + content : TocContent + sub_items: Vec + new(content) +} + +enum TocContent { + Frontmatter "Chapter" + Mainmatter "Chapter" + Backmatter "Chapter" + Insert "Chapter" + Spacer +} + +} + +namespace book::metadata { + +class BookMetadata { + title + subtitle + description + publisher + language + authors + translators + number_format + section_names + new(title) +} + +class Author { + name + email + new(name) +} + +class Language { + name + code +} + +class Publisher { + name + url + logo_src +} + +enum NumberFormat { + Arabic + Roman + Word +} + +} + +class renderer::html_handlebars::HtmlHandlebars { + new() + render(book: MDBook) +} + +class theme::Theme { + index + css + favicon + js + highlight_css + tomorrow_night_css + highlight_js + jquery + new(src) +} + +book::book-[hidden]->book::bookconfig +book::book-[hidden]->book::chapter +book::book-[hidden]->book::toc +book::book-[hidden]->book::metadata + +renderer::html_handlebars::HtmlHandlebars-[hidden]->theme::Theme + +@enduml diff --git a/doc/assets/structs.png b/doc/assets/structs.png new file mode 100644 index 00000000..c250d832 Binary files /dev/null and b/doc/assets/structs.png differ diff --git a/doc/assets/structs.pum b/doc/assets/structs.pum new file mode 100644 index 00000000..3637ee69 --- /dev/null +++ b/doc/assets/structs.pum @@ -0,0 +1,142 @@ +@startuml + +class book::MDBook { + root + dest + src + theme_path + title + author + description + content : Vec + books : HashMap<&'a str, Book> + renderer + livereload +} + +class book::book.Book { + metadata + frontmatter + mainmatter + backmatter + + new(title) +} + +class book::bookconfig.BookConfig { + root + dest + src + theme_path + title + author + description + indent_spaces + multilingual + + new(root) +} + +class book::chapter.Chapter { + title + file + author + description + index + class + sub_chapters + + new(title, file) +} + +namespace book::bookitem { + +enum BookItem { + Chapter "String, Chapter" + Affix "Chapter" + Spacer +} + +class BookItems { + items : &'a [BookItem] + current_index + stack : Vec<"&'a [BookItem], usize"> +} + +class Chapter { + name + path + sub_items + + new(name, path) +} + +} + +namespace book::metadata { + +class BookMetadata { + title + subtitle + description + publisher + language + authors + translators + number_format + section_names + new(title) +} + +class Author { + name + email + new(name) +} + +class Language { + name + code +} + +class Publisher { + name + url + logo_src +} + +enum NumberFormat { + Arabic + Roman + Word +} + +} + +class renderer::html_handlebars::HtmlHandlebars { + new() + render(book: MDBook) +} + +class theme::Theme { + index + css + favicon + js + highlight_css + tomorrow_night_css + highlight_js + jquery + new(src) +} + +book::book-[hidden]->book::bookconfig +book::book-[hidden]->book::chapter +book::book-[hidden]->book::bookitem +book::book-[hidden]->book::metadata + +book::bookitem.BookItems-[hidden]->book::bookitem.BookItem + +renderer::html_handlebars::HtmlHandlebars-[hidden]->theme::Theme + +@enduml diff --git a/doc/doc.md b/doc/doc.md new file mode 100644 index 00000000..961f4926 --- /dev/null +++ b/doc/doc.md @@ -0,0 +1,94 @@ +# Doc + +Diagrams are with [yEd](http://www.yworks.com/products/yed) +and [plantuml](http://plantuml.com). + +## Data + +`MDBook::new(root)` parses CLI args and `book.toml` to create: + +- app config settings +- `Book` for each language + +Each `Book` is given their config setting with their source- and destination +paths. + +The renderer can then render each book. + +To render the TOC, renderer gets a Vec from summary parser. + +The renderer walks through the Vec. It can match content kinds in an enum and +this way knows whether to render: + +- front- back- or mainmatter +- spacer elements (vertical space in TOC but no chapter output) +- insert chapters (no TOC link, but the chapter is part of the reading sequence) + +![book data](assets/bookdata.png) + +### Renderer + +Takes a book, which knows: + +- metadata +- toc with chapters +- config for paths +- template assets (`template_path`) + +For generating pages: + +Book metadata, `BookMetadata` (title, author, publisher, etc.). Just recognize +those properties which can be easily anticipated. + +If Renderer needs more specific data, it can be supplied in `book.toml`. It's +the Renderer's job to open that and parse it out. + +Chapters are represented in a `Vec`, each item has the chapter content +as payload. + +If the user wants to store attributes that are not anticipated with structs, +they can go in a hashmap with string keys, let them be accessible from the +templates with helpers. + +For generating output: + +- template assets, `template-path`, renderer does whatever it wants with it +- config (root, dest, etc. folders) + +Renderer is seleceted by CLI or default (html). Each book is passed to this +renderer. + +### Config + +Takes data from: + +- CLI args +- book.toml + +## Structs + +### Reorganized + +![structs reorganized](assets/structs-reorganized.png) + +### Currently + +![structs](assets/structs.png) + +## Notes + +Take config paths for as many things as possible. Let the user organize their +project folder differently, or allow `mdbook` to function in existing projects +with already established folders. + +Add config path for `SUMMARY.md`. Default is good to be in `src/`, it allows +chapter links to work when reading the file on Github. + +The init command should copy the assets folder by default, it is better to make +this choice for new users. + +The specific assets (CSS, templates, etc.) are closely coupled with the book +content when the user is writing it. If the templates change when mdbook +develops, this changes the output in a way the user doesn't expect, maybe even +breaking their book. +