Get book contents and pass to pandoc for epub version.

This commit is contained in:
Adam Solove 2016-01-11 21:19:22 -05:00
parent 8476a3d03d
commit 7da175bba3
1 changed files with 19 additions and 13 deletions

View File

@ -3,34 +3,40 @@ use book::MDBook;
use book::bookitem::BookItem; use book::bookitem::BookItem;
use std::error::Error; use std::error::Error;
use std::process::Command;
enum PandocOutput { pub struct Pandoc;
Epub,
Pdf
}
pub struct Pandoc {
output: PandocOutput
}
impl Pandoc { impl Pandoc {
pub fn new() -> Pandoc { pub fn new() -> Pandoc {
Pandoc { output: PandocOutput::Epub } Pandoc
} }
} }
impl Renderer for Pandoc { impl Renderer for Pandoc {
fn render(&self, book: &MDBook) -> Result<(), Box<Error>> { fn render(&self, book: &MDBook) -> Result<(), Box<Error>> {
let mut paths = vec!();
for item in book.iter() { for item in book.iter() {
match *item { match *item {
BookItem::Chapter(ref title, _) => { BookItem::Chapter(_, ref ch) => {
println!("{}", title) paths.push(book.get_src().join(&ch.path).into_os_string());
}, },
_ => println!("Something I don't understand") _ => println!("FIXME: don't understand this kind of BookItem")
} }
} }
Ok(()) let output = Command::new("pandoc")
.arg("-S")
.arg("-osample.epub")
.args(&paths)
.output();
match output {
Ok(_) => Ok(()),
Err(e) => Err(Box::new(e))
}
// FIXME: why doesn't this work
// output.map(|_| ()).map_err(|e| Box::new(e))
} }
} }