First experiment with building a new renderer.

This commit is contained in:
Adam Solove 2016-01-11 10:08:27 -05:00
parent e286b208da
commit 8476a3d03d
3 changed files with 41 additions and 3 deletions

View File

@ -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()),
}
}

View File

@ -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;

View File

@ -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<Error>> {
for item in book.iter() {
match *item {
BookItem::Chapter(ref title, _) => {
println!("{}", title)
},
_ => println!("Something I don't understand")
}
}
Ok(())
}
}