From 4fe0bc2de51c475c883df8065d360dd2d4014f8e Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 16 Jul 2015 19:26:16 +0200 Subject: [PATCH] renamed directory + created BookItem --- src/{mdbook => book}/bookconfig.rs | 0 src/book/bookitem.rs | 21 +++++++++++++++++++++ src/{mdbook => book}/mdbook.rs | 23 +++++++++++++++++++++-- src/book/mod.rs | 6 ++++++ src/lib.rs | 4 ++-- src/main.rs | 2 +- src/mdbook/mod.rs | 2 -- 7 files changed, 51 insertions(+), 7 deletions(-) rename src/{mdbook => book}/bookconfig.rs (100%) create mode 100644 src/book/bookitem.rs rename src/{mdbook => book}/mdbook.rs (84%) create mode 100644 src/book/mod.rs delete mode 100644 src/mdbook/mod.rs diff --git a/src/mdbook/bookconfig.rs b/src/book/bookconfig.rs similarity index 100% rename from src/mdbook/bookconfig.rs rename to src/book/bookconfig.rs diff --git a/src/book/bookitem.rs b/src/book/bookitem.rs new file mode 100644 index 00000000..cc993073 --- /dev/null +++ b/src/book/bookitem.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; + +pub struct BookItem { + name: String, + path: PathBuf, + sub_items: Vec, +} + + +impl BookItem { + + fn new(name: String, path: PathBuf) -> Self { + + BookItem { + name: name, + path: path, + sub_items: vec![], + } + } + +} diff --git a/src/mdbook/mdbook.rs b/src/book/mdbook.rs similarity index 84% rename from src/mdbook/mdbook.rs rename to src/book/mdbook.rs index d0721bd2..0d585048 100644 --- a/src/mdbook/mdbook.rs +++ b/src/book/mdbook.rs @@ -3,10 +3,14 @@ use std::fs::{self, File, metadata}; use std::io::Write; use std::io::Error; -use mdbook::bookconfig::BookConfig; +use book::bookconfig::BookConfig; +use book::bookitem::BookItem; pub struct MDBook { + title: String, + author: String, config: BookConfig, + pub content: Vec } impl MDBook { @@ -24,6 +28,9 @@ impl MDBook { } MDBook { + title: String::from(""), + author: String::from(""), + content: vec![], config: BookConfig::new() .set_src(path.join("src")) .set_dest(path.join("book")), @@ -80,13 +87,15 @@ impl MDBook { return Ok(()); } - pub fn build(&self, dir: &PathBuf) -> Result<(), Error> { + pub fn build(&self) -> Result<(), Error> { Ok(()) } + + // Builder functions pub fn set_dest(mut self, dest: PathBuf) -> Self { self.config = self.config.set_dest(dest); self @@ -97,4 +106,14 @@ impl MDBook { self } + pub fn set_title(mut self, title: String) -> Self { + self.title = title; + self + } + + pub fn set_author(mut self, author: String) -> Self { + self.author = author; + self + } + } diff --git a/src/book/mod.rs b/src/book/mod.rs new file mode 100644 index 00000000..ac310a28 --- /dev/null +++ b/src/book/mod.rs @@ -0,0 +1,6 @@ +pub mod mdbook; +mod bookconfig; +mod bookitem; + +use self::bookconfig::BookConfig; +use self::bookitem::BookItem; diff --git a/src/lib.rs b/src/lib.rs index 2bdfccc4..7c0f6b72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ -mod mdbook; +mod book; -pub use mdbook::mdbook::MDBook; +pub use book::mdbook::MDBook; diff --git a/src/main.rs b/src/main.rs index 7aae7f86..a1c01b70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,7 +146,7 @@ fn build(args: Vec) { let dir = std::env::current_dir().unwrap(); let book = MDBook::new(&dir); - if let Err(e) = book.build(&dir) { + if let Err(e) = book.build() { println!("Error: {}", e); } } diff --git a/src/mdbook/mod.rs b/src/mdbook/mod.rs deleted file mode 100644 index c6cd178f..00000000 --- a/src/mdbook/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod mdbook; -mod bookconfig;