From 9189053bbfbc40f6f61c06ae2442788e2004bfe7 Mon Sep 17 00:00:00 2001 From: Gambhiro Date: Tue, 20 Dec 2016 20:44:38 +0000 Subject: [PATCH] frontmatter, mainmatter, backmatter --- book-example/src/SUMMARY.md | 2 ++ book-example/src/misc/introduction.md | 3 ++ src/book/book.rs | 41 +++++++++++++++------------ 3 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 book-example/src/misc/introduction.md diff --git a/book-example/src/SUMMARY.md b/book-example/src/SUMMARY.md index ff3911c7..8d7bdcdd 100644 --- a/book-example/src/SUMMARY.md +++ b/book-example/src/SUMMARY.md @@ -1,5 +1,7 @@ # Summary +[Introduction](misc/introduction.md) + - [mdBook](README.md) - [Command Line Tool](cli/cli-tool.md) - [init](cli/init.md) diff --git a/book-example/src/misc/introduction.md b/book-example/src/misc/introduction.md new file mode 100644 index 00000000..36495382 --- /dev/null +++ b/book-example/src/misc/introduction.md @@ -0,0 +1,3 @@ +# Introduction + +A frontmatter chapter. diff --git a/src/book/book.rs b/src/book/book.rs index 18572545..54020362 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -8,38 +8,43 @@ use book::chapter::Chapter; pub struct Book { metadata: BookMetadata, - preface: Vec, - chapters: Vec, - appendix: Vec, + //preface: Vec, + frontmatter: Vec, + //chapters: Vec, + mainmatter: Vec, + //appendix: Vec, + backmatter: Vec, } impl Book { - /// Creates a new book with the given title, chapters are added with the `add_chapter` method + /// Creates a new book with the given title, chapters are added with the + /// `add_frontmatter_chapter`, `add_mainmatter_chapter`, + /// `add_backmatter_chapter` methods pub fn new(title: &str) -> Self { Book { metadata: BookMetadata::new(title), - preface: Vec::new(), - chapters: Vec::new(), - appendix: Vec::new(), + frontmatter: Vec::new(), + mainmatter: Vec::new(), + backmatter: Vec::new(), } } - /// Adds a new chapter at the end of the book - pub fn add_chapter(&mut self, chapter: Chapter) -> &mut Self { - self.chapters.push(chapter); + /// Adds a new mainmatter chapter + pub fn add_mainmatter_chapter(&mut self, chapter: Chapter) -> &mut Self { + self.mainmatter.push(chapter); self } - /// Adds a new preface chapter to the book, the preface chapters are in the order they were added - pub fn add_preface_chapter(&mut self, chapter: Chapter) -> &mut Self { - self.preface.push(chapter); + /// Adds a new frontmatter chapter + pub fn add_frontmatter_chapter(&mut self, chapter: Chapter) -> &mut Self { + self.frontmatter.push(chapter); self } - /// Adds a new appendix chapter to the book, they are in de order they are added - pub fn add_appendix_chapter(&mut self, chapter: Chapter) -> &mut Self { - self.appendix.push(chapter); + /// Adds a new backmatter chapter + pub fn add_backmatter_chapter(&mut self, chapter: Chapter) -> &mut Self { + self.backmatter.push(chapter); self } @@ -57,9 +62,9 @@ impl Book { pub fn get_chapter(&self, section: &[usize]) -> Option<&Chapter> { match section.len() { 0 => None, - 1 => self.chapters.get(section[0]), + 1 => self.mainmatter.get(section[0]), _ => { - self.chapters + self.mainmatter .get(section[0]) .and_then(|ch| ch.get_sub_chapter(§ion[1..])) },