preparing structs

This commit is contained in:
Gambhiro 2016-12-20 21:25:44 +00:00
parent 9189053bbf
commit bfdc70c1f0
3 changed files with 83 additions and 8 deletions

View File

@ -8,11 +8,8 @@ use book::chapter::Chapter;
pub struct Book { pub struct Book {
metadata: BookMetadata, metadata: BookMetadata,
//preface: Vec<Chapter>,
frontmatter: Vec<Chapter>, frontmatter: Vec<Chapter>,
//chapters: Vec<Chapter>,
mainmatter: Vec<Chapter>, mainmatter: Vec<Chapter>,
//appendix: Vec<Chapter>,
backmatter: Vec<Chapter>, backmatter: Vec<Chapter>,
} }

View File

@ -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 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 /// the location of the markdown file containing the content and eventually sub-chapters
/// TODO use in template: author, description, index, class
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Chapter { pub struct Chapter {
/// The title of the chapter.
title: String, 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<Chapter>, sub_chapters: Vec<Chapter>,
} }
impl Chapter { impl Chapter {
/// Creates a new chapter with the given title and source file and no sub-chapters /// 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 { Chapter {
title: title.to_owned(), title: title.to_owned(),
file: file.to_owned(), file: file.to_owned(),
sub_chapters: Vec::new(), 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 { pub fn title(&self) -> &str {
&self.title &self.title
} }
pub fn file(&self) -> &path::Path { pub fn file(&self) -> &Path {
&self.file &self.file
} }
pub fn sub_chapters(&self) -> &[Chapter] { pub fn sub_chapters(&self) -> &[Chapter] {

View File

@ -1,12 +1,32 @@
use std::path::PathBuf;
/// TODO use in template: subtitle, description, publisher, number_format, section_names
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BookMetadata { pub struct BookMetadata {
/// The title of the book.
pub title: String, 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, pub description: String,
/// TODO Publisher's info
pub publisher: Publisher,
pub language: Language, pub language: Language,
authors: Vec<Author>, authors: Vec<Author>,
translators: Vec<Author>, translators: Vec<Author>,
/// TODO Chapter numbering scheme
number_format: NumberFormat,
/// TODO Section names for nested Vec<Chapter> structures, such as `[
/// "Part", "Chapter", "Section" ]`
section_names: Vec<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -21,6 +41,38 @@ pub struct Language {
code: String, 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 { impl BookMetadata {
pub fn new(title: &str) -> Self { pub fn new(title: &str) -> Self {
@ -32,6 +84,12 @@ impl BookMetadata {
authors: Vec::new(), authors: Vec::new(),
translators: Vec::new(), translators: Vec::new(),
// TODO placeholder values for now
subtitle: "".to_string(),
publisher: Publisher::default(),
number_format: NumberFormat::Arabic,
section_names: vec![],
} }
} }