diff --git a/src/book/bookitem.rs b/src/book/bookitem.rs deleted file mode 100644 index 7fe7ab55..00000000 --- a/src/book/bookitem.rs +++ /dev/null @@ -1,87 +0,0 @@ -use serde::{Serialize, Serializer}; -use serde::ser::SerializeStruct; -use std::path::PathBuf; - - -#[derive(Debug, Clone)] -pub enum BookItem { - Chapter(String, Chapter), // String = section - Affix(Chapter), - Spacer, -} - -#[derive(Debug, Clone)] -pub struct Chapter { - pub name: String, - pub path: PathBuf, - pub sub_items: Vec, -} - -#[derive(Debug, Clone)] -pub struct BookItems<'a> { - pub items: &'a [BookItem], - pub current_index: usize, - pub stack: Vec<(&'a [BookItem], usize)>, -} - - -impl Chapter { - pub fn new(name: String, path: PathBuf) -> Self { - - Chapter { - name: name, - path: path, - sub_items: vec![], - } - } -} - - -impl Serialize for Chapter { - fn serialize(&self, serializer: S) -> ::std::result::Result - where S: Serializer - { - let mut struct_ = serializer.serialize_struct("Chapter", 2)?; - struct_.serialize_field("name", &self.name)?; - struct_.serialize_field("path", &self.path)?; - struct_.end() - } -} - - - -// Shamelessly copied from Rustbook -// (https://github.com/rust-lang/rust/blob/master/src/rustbook/book.rs) -impl<'a> Iterator for BookItems<'a> { - type Item = &'a BookItem; - - fn next(&mut self) -> Option<&'a BookItem> { - loop { - if self.current_index >= self.items.len() { - match self.stack.pop() { - None => return None, - Some((parent_items, parent_idx)) => { - self.items = parent_items; - self.current_index = parent_idx + 1; - }, - } - } else { - let cur = &self.items[self.current_index]; - - match *cur { - BookItem::Chapter(_, ref ch) | - BookItem::Affix(ref ch) => { - self.stack.push((self.items, self.current_index)); - self.items = &ch.sub_items[..]; - self.current_index = 0; - }, - BookItem::Spacer => { - self.current_index += 1; - }, - } - - return Some(cur); - } - } - } -} diff --git a/src/book/mod.rs b/src/book/mod.rs index 77987b40..a85c2257 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -1,4 +1,3 @@ -pub mod bookitem; pub mod book; pub mod summary; diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index d2b46779..b8457868 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -2,10 +2,11 @@ use renderer::html_handlebars::helpers; use preprocess; use renderer::Renderer; use book::MDBook; -use book::bookitem::{BookItem, Chapter}; use config::PlaypenConfig; -use {utils, theme}; use theme::{Theme, playpen_editor}; +use book::book::{BookItem, Chapter}; +use utils; +use theme::{self, Theme}; use errors::*; use regex::{Regex, Captures}; @@ -32,8 +33,22 @@ impl HtmlHandlebars { -> Result<()> { // FIXME: This should be made DRY-er and rely less on mutable state match *item { +<<<<<<< HEAD BookItem::Chapter(_, ref ch) | BookItem::Affix(ref ch) if !ch.path.as_os_str().is_empty() => { +======= + BookItem::Chapter(ref ch) => { + if ch.path != PathBuf::new() { + + let path = ctx.book.get_source().join(&ch.path); + + debug!("[*]: Opening file: {:?}", path); + let mut f = File::open(&path)?; + let mut content: String = String::new(); + + debug!("[*]: Reading file"); + f.read_to_string(&mut content)?; +>>>>>>> Removed old bookitem.md, now everyone uses the correct BookItem let path = ctx.book.get_source().join(&ch.path); let content = utils::fs::file_to_string(&path)?; @@ -395,14 +410,7 @@ fn make_data(book: &MDBook) -> Result let mut chapter = BTreeMap::new(); match *item { - BookItem::Affix(ref ch) => { - chapter.insert("name".to_owned(), json!(ch.name)); - let path = ch.path.to_str().ok_or_else(|| { - io::Error::new(io::ErrorKind::Other, "Could not convert path to str") - })?; - chapter.insert("path".to_owned(), json!(path)); - }, - BookItem::Chapter(ref s, ref ch) => { + BookItem::Chapter(ref ch) => { chapter.insert("section".to_owned(), json!(s)); chapter.insert("name".to_owned(), json!(ch.name)); let path = ch.path.to_str().ok_or_else(|| { @@ -410,7 +418,7 @@ fn make_data(book: &MDBook) -> Result })?; chapter.insert("path".to_owned(), json!(path)); }, - BookItem::Spacer => { + BookItem::Separator => { chapter.insert("spacer".to_owned(), json!("_spacer_")); },