frontmatter, mainmatter, backmatter
This commit is contained in:
parent
efc2644f84
commit
9189053bbf
|
@ -1,5 +1,7 @@
|
||||||
# Summary
|
# Summary
|
||||||
|
|
||||||
|
[Introduction](misc/introduction.md)
|
||||||
|
|
||||||
- [mdBook](README.md)
|
- [mdBook](README.md)
|
||||||
- [Command Line Tool](cli/cli-tool.md)
|
- [Command Line Tool](cli/cli-tool.md)
|
||||||
- [init](cli/init.md)
|
- [init](cli/init.md)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Introduction
|
||||||
|
|
||||||
|
A frontmatter chapter.
|
|
@ -8,38 +8,43 @@ use book::chapter::Chapter;
|
||||||
pub struct Book {
|
pub struct Book {
|
||||||
metadata: BookMetadata,
|
metadata: BookMetadata,
|
||||||
|
|
||||||
preface: Vec<Chapter>,
|
//preface: Vec<Chapter>,
|
||||||
chapters: Vec<Chapter>,
|
frontmatter: Vec<Chapter>,
|
||||||
appendix: Vec<Chapter>,
|
//chapters: Vec<Chapter>,
|
||||||
|
mainmatter: Vec<Chapter>,
|
||||||
|
//appendix: Vec<Chapter>,
|
||||||
|
backmatter: Vec<Chapter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Book {
|
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 {
|
pub fn new(title: &str) -> Self {
|
||||||
Book {
|
Book {
|
||||||
metadata: BookMetadata::new(title),
|
metadata: BookMetadata::new(title),
|
||||||
|
|
||||||
preface: Vec::new(),
|
frontmatter: Vec::new(),
|
||||||
chapters: Vec::new(),
|
mainmatter: Vec::new(),
|
||||||
appendix: Vec::new(),
|
backmatter: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new chapter at the end of the book
|
/// Adds a new mainmatter chapter
|
||||||
pub fn add_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
pub fn add_mainmatter_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
||||||
self.chapters.push(chapter);
|
self.mainmatter.push(chapter);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new preface chapter to the book, the preface chapters are in the order they were added
|
/// Adds a new frontmatter chapter
|
||||||
pub fn add_preface_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
pub fn add_frontmatter_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
||||||
self.preface.push(chapter);
|
self.frontmatter.push(chapter);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a new appendix chapter to the book, they are in de order they are added
|
/// Adds a new backmatter chapter
|
||||||
pub fn add_appendix_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
pub fn add_backmatter_chapter(&mut self, chapter: Chapter) -> &mut Self {
|
||||||
self.appendix.push(chapter);
|
self.backmatter.push(chapter);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +62,9 @@ impl Book {
|
||||||
pub fn get_chapter(&self, section: &[usize]) -> Option<&Chapter> {
|
pub fn get_chapter(&self, section: &[usize]) -> Option<&Chapter> {
|
||||||
match section.len() {
|
match section.len() {
|
||||||
0 => None,
|
0 => None,
|
||||||
1 => self.chapters.get(section[0]),
|
1 => self.mainmatter.get(section[0]),
|
||||||
_ => {
|
_ => {
|
||||||
self.chapters
|
self.mainmatter
|
||||||
.get(section[0])
|
.get(section[0])
|
||||||
.and_then(|ch| ch.get_sub_chapter(§ion[1..]))
|
.and_then(|ch| ch.get_sub_chapter(§ion[1..]))
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue