Moved book.json from src to root. Now src can be set to whatever you want. Closes #27

This commit is contained in:
Mathieu David 2015-08-04 01:25:41 +02:00
parent 91b0a99d81
commit 4ae77d771a
3 changed files with 7 additions and 5 deletions

View File

@ -27,15 +27,15 @@ impl BookConfig {
}
}
pub fn read_config(&mut self) -> &mut Self {
pub fn read_config(&mut self, root: &Path) -> &mut Self {
debug!("[fn]: read_config");
// If the file does not exist, return early
let mut config_file = match File::open(self.src.join("book.json")) {
let mut config_file = match File::open(root.join("book.json")) {
Ok(f) => f,
Err(_) => {
debug!("[*]: Failed to open {:?}", self.src.join("book.json"));
debug!("[*]: Failed to open {:?}", root.join("book.json"));
return self
},
};

View File

@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};
use std::fs::{self, File, metadata};
use std::io::Write;
use std::error::Error;
@ -11,6 +11,7 @@ use renderer::HtmlHandlebars;
pub struct MDBook {
config: BookConfig,
root: PathBuf,
pub content: Vec<BookItem>,
renderer: Box<Renderer>,
}
@ -30,6 +31,7 @@ impl MDBook {
}
MDBook {
root: path.to_path_buf(),
content: vec![],
config: BookConfig::new()
.set_src(&path.join("src"))
@ -120,7 +122,7 @@ impl MDBook {
// Builder functions
pub fn read_config(mut self) -> Self {
self.config.read_config();
self.config.read_config(&self.root);
self
}