renamed directory + created BookItem

This commit is contained in:
Mathieu David 2015-07-16 19:26:16 +02:00
parent ad01c37432
commit 4fe0bc2de5
7 changed files with 51 additions and 7 deletions

21
src/book/bookitem.rs Normal file
View File

@ -0,0 +1,21 @@
use std::path::PathBuf;
pub struct BookItem {
name: String,
path: PathBuf,
sub_items: Vec<BookItem>,
}
impl BookItem {
fn new(name: String, path: PathBuf) -> Self {
BookItem {
name: name,
path: path,
sub_items: vec![],
}
}
}

View File

@ -3,10 +3,14 @@ use std::fs::{self, File, metadata};
use std::io::Write; use std::io::Write;
use std::io::Error; use std::io::Error;
use mdbook::bookconfig::BookConfig; use book::bookconfig::BookConfig;
use book::bookitem::BookItem;
pub struct MDBook { pub struct MDBook {
title: String,
author: String,
config: BookConfig, config: BookConfig,
pub content: Vec<BookItem>
} }
impl MDBook { impl MDBook {
@ -24,6 +28,9 @@ impl MDBook {
} }
MDBook { MDBook {
title: String::from(""),
author: String::from(""),
content: vec![],
config: BookConfig::new() config: BookConfig::new()
.set_src(path.join("src")) .set_src(path.join("src"))
.set_dest(path.join("book")), .set_dest(path.join("book")),
@ -80,13 +87,15 @@ impl MDBook {
return Ok(()); return Ok(());
} }
pub fn build(&self, dir: &PathBuf) -> Result<(), Error> { pub fn build(&self) -> Result<(), Error> {
Ok(()) Ok(())
} }
// Builder functions
pub fn set_dest(mut self, dest: PathBuf) -> Self { pub fn set_dest(mut self, dest: PathBuf) -> Self {
self.config = self.config.set_dest(dest); self.config = self.config.set_dest(dest);
self self
@ -97,4 +106,14 @@ impl MDBook {
self 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
}
} }

6
src/book/mod.rs Normal file
View File

@ -0,0 +1,6 @@
pub mod mdbook;
mod bookconfig;
mod bookitem;
use self::bookconfig::BookConfig;
use self::bookitem::BookItem;

View File

@ -1,3 +1,3 @@
mod mdbook; mod book;
pub use mdbook::mdbook::MDBook; pub use book::mdbook::MDBook;

View File

@ -146,7 +146,7 @@ fn build(args: Vec<String>) {
let dir = std::env::current_dir().unwrap(); let dir = std::env::current_dir().unwrap();
let book = MDBook::new(&dir); let book = MDBook::new(&dir);
if let Err(e) = book.build(&dir) { if let Err(e) = book.build() {
println!("Error: {}", e); println!("Error: {}", e);
} }
} }

View File

@ -1,2 +0,0 @@
pub mod mdbook;
mod bookconfig;