From 4ae77d771a55968c30909e4678ce17c53818f8d1 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Tue, 4 Aug 2015 01:25:41 +0200 Subject: [PATCH] Moved book.json from src to root. Now src can be set to whatever you want. Closes #27 --- book-example/{src => }/book.json | 0 src/book/bookconfig.rs | 6 +++--- src/book/mdbook.rs | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) rename book-example/{src => }/book.json (100%) diff --git a/book-example/src/book.json b/book-example/book.json similarity index 100% rename from book-example/src/book.json rename to book-example/book.json diff --git a/src/book/bookconfig.rs b/src/book/bookconfig.rs index c6af9d99..d40fbaca 100644 --- a/src/book/bookconfig.rs +++ b/src/book/bookconfig.rs @@ -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 }, }; diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs index a158cf7e..bb624b9c 100644 --- a/src/book/mdbook.rs +++ b/src/book/mdbook.rs @@ -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, renderer: Box, } @@ -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 }