From 8476a3d03dd47da15c18bb4b9fe55852d454484c Mon Sep 17 00:00:00 2001 From: Adam Solove Date: Mon, 11 Jan 2016 10:08:27 -0500 Subject: [PATCH] First experiment with building a new renderer. --- src/book/mdbook.rs | 4 ++-- src/renderer/mod.rs | 4 +++- src/renderer/pandoc/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/renderer/pandoc/mod.rs diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs index 2209bc36..d779ecc5 100644 --- a/src/book/mdbook.rs +++ b/src/book/mdbook.rs @@ -8,7 +8,7 @@ use std::process::Command; use {BookConfig, BookItem, theme, parse, utils}; use book::BookItems; -use renderer::{Renderer, HtmlHandlebars}; +use renderer::{Renderer, HtmlHandlebars, Pandoc}; pub struct MDBook { @@ -38,7 +38,7 @@ impl MDBook { .set_src(&root.join("src")) .set_dest(&root.join("book")) .to_owned(), - renderer: Box::new(HtmlHandlebars::new()), + renderer: Box::new(Pandoc::new()), } } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 8216db27..f64b263d 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -1,5 +1,7 @@ pub use self::renderer::Renderer; pub use self::html_handlebars::HtmlHandlebars; +pub use self::pandoc::Pandoc; pub mod renderer; -mod html_handlebars; +mod pandoc; +mod html_handlebars; \ No newline at end of file diff --git a/src/renderer/pandoc/mod.rs b/src/renderer/pandoc/mod.rs new file mode 100644 index 00000000..1a4362af --- /dev/null +++ b/src/renderer/pandoc/mod.rs @@ -0,0 +1,36 @@ +use renderer::Renderer; +use book::MDBook; +use book::bookitem::BookItem; + +use std::error::Error; + +enum PandocOutput { + Epub, + Pdf +} + +pub struct Pandoc { + output: PandocOutput +} + +impl Pandoc { + pub fn new() -> Pandoc { + Pandoc { output: PandocOutput::Epub } + } +} + +impl Renderer for Pandoc { + fn render(&self, book: &MDBook) -> Result<(), Box> { + + for item in book.iter() { + match *item { + BookItem::Chapter(ref title, _) => { + println!("{}", title) + }, + _ => println!("Something I don't understand") + } + } + + Ok(()) + } +} \ No newline at end of file