diff --git a/src/book/book.rs b/src/book/book.rs index 54020362..6b6ce03b 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -8,11 +8,8 @@ use book::chapter::Chapter; pub struct Book { metadata: BookMetadata, - //preface: Vec, frontmatter: Vec, - //chapters: Vec, mainmatter: Vec, - //appendix: Vec, backmatter: Vec, } diff --git a/src/book/chapter.rs b/src/book/chapter.rs index db8ce3ea..7afb3610 100644 --- a/src/book/chapter.rs +++ b/src/book/chapter.rs @@ -1,24 +1,44 @@ -use std::path; +use std::path::{Path, PathBuf}; +use book::metadata::Author; /// The Chapter struct holds the title of the chapter as written in the SUMMARY.md file, /// the location of the markdown file containing the content and eventually sub-chapters + +/// TODO use in template: author, description, index, class + #[derive(Debug, Clone)] pub struct Chapter { + /// The title of the chapter. title: String, - file: path::PathBuf, + /// Path to chapter's markdown file. + file: PathBuf, + + /// TODO The author of the chapter, or the book. + author: Author, + /// TODO The description of the chapter. + description: String, + /// TODO Index number of the chapter in its level. This is the Vec index + 1. + index: i32, + /// TODO CSS class that will be added to the page-level wrap div to allow customized chapter styles. + class: String, sub_chapters: Vec, } - impl Chapter { /// Creates a new chapter with the given title and source file and no sub-chapters - pub fn new(title: &str, file: &path::Path) -> Self { + pub fn new(title: &str, file: &Path) -> Self { Chapter { title: title.to_owned(), file: file.to_owned(), sub_chapters: Vec::new(), + + // TODO placeholder values for now + author: Author::new(""), + description: "".to_string(), + index: 0, + class: "".to_string(), } } @@ -42,7 +62,7 @@ impl Chapter { pub fn title(&self) -> &str { &self.title } - pub fn file(&self) -> &path::Path { + pub fn file(&self) -> &Path { &self.file } pub fn sub_chapters(&self) -> &[Chapter] { diff --git a/src/book/metadata.rs b/src/book/metadata.rs index 0be79be7..6fe837cd 100644 --- a/src/book/metadata.rs +++ b/src/book/metadata.rs @@ -1,12 +1,32 @@ +use std::path::PathBuf; + +/// TODO use in template: subtitle, description, publisher, number_format, section_names + #[derive(Debug, Clone)] pub struct BookMetadata { + /// The title of the book. pub title: String, + + /// TODO The subtitle, when titles are in the form of "The Immense Journey: An + /// Imaginative Naturalist Explores the Mysteries of Man and Nature" + pub subtitle: String, + + /// TODO A brief description or summary. pub description: String, + /// TODO Publisher's info + pub publisher: Publisher, + pub language: Language, authors: Vec, translators: Vec, + + /// TODO Chapter numbering scheme + number_format: NumberFormat, + /// TODO Section names for nested Vec structures, such as `[ + /// "Part", "Chapter", "Section" ]` + section_names: Vec, } #[derive(Debug, Clone)] @@ -21,6 +41,38 @@ pub struct Language { code: String, } +/// TODO use Publisher in template. + +#[derive(Debug, Clone)] +pub struct Publisher { + name: String, + /// link to the sublisher's site + url: String, + /// path to publisher's logo image + logo_src: PathBuf, +} + +impl Publisher { + pub fn default() -> Publisher { + Publisher { + name: "".to_string(), + url: "".to_string(), + logo_src: PathBuf::new(), + } + } +} + +/// TODO use NumberFormat when rendering chapter titles. + +#[derive(Debug, Clone)] +pub enum NumberFormat { + /// 19 + Arabic, + /// XIX + Roman, + /// Nineteen + Word, +} impl BookMetadata { pub fn new(title: &str) -> Self { @@ -32,6 +84,12 @@ impl BookMetadata { authors: Vec::new(), translators: Vec::new(), + + // TODO placeholder values for now + subtitle: "".to_string(), + publisher: Publisher::default(), + number_format: NumberFormat::Arabic, + section_names: vec![], } }