1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-11-18 00:13:55 +01:00

started to work on odt rendering but it's a pain:(

This commit is contained in:
Elisabeth Henry 2016-02-20 22:52:10 +01:00
parent 81c2b69d4a
commit d474bce3d6
3 changed files with 23 additions and 2 deletions

@ -56,7 +56,7 @@ will thus generate baz.pdf in directory foo and not in current directory.")
.long("--to")
.short("t")
.takes_value(true)
.possible_values(&["epub", "pdf", "html", "tex"])
.possible_values(&["epub", "pdf", "html", "tex", "odt"])
.value_name("FORMAT")
.help("Generate specific format"))
.arg(Arg::with_name("BOOK")
@ -96,6 +96,7 @@ will thus generate baz.pdf in directory foo and not in current directory.")
"tex" => book.output_tex = value,
"html" => book.output_html = value,
"pdf" => book.output_pdf = value,
"odt" => book.output_odt = value,
_ => unreachable!()
}
}
@ -105,6 +106,7 @@ will thus generate baz.pdf in directory foo and not in current directory.")
"tex" => &book.output_tex,
"html" => &book.output_html,
"pdf" => &book.output_pdf,
"odt" => &book.output_odt,
_ => unreachable!()
} {
if let Err(err) = match format {
@ -112,6 +114,7 @@ will thus generate baz.pdf in directory foo and not in current directory.")
"tex" => book.render_tex(file),
"html" => book.render_html(file),
"pdf" => book.render_pdf(file),
"odt" => book.render_odt(file),
_ => unreachable!()
} {
println!("{}", err);

@ -5,7 +5,8 @@ use token::Token;
use epub::EpubRenderer;
use html::HtmlRenderer;
use latex::LatexRenderer;
use templates::{epub,html, epub3};
use odt::OdtRenderer;
use templates::{epub,html,epub3};
use std::fs::File;
use std::io::{Write,Read};
@ -41,6 +42,7 @@ pub struct Book {
pub output_html: Option<String>,
pub output_pdf: Option<String>,
pub output_tex: Option<String>,
pub output_odt: Option<String>,
pub temp_dir: String,
// internal structure
@ -87,6 +89,7 @@ impl Book {
output_html: None,
output_pdf: None,
output_tex: None,
output_odt: None,
tex_command: String::from("pdflatex"),
epub_css: None,
epub_template: None,
@ -288,6 +291,19 @@ impl Book {
Ok(())
}
/// Render book to epub according to book options
pub fn render_odt(&self, file: &str) -> Result<()> {
if self.verbose {
println!("Attempting to generate Odt...");
}
let mut odt = OdtRenderer::new(&self);
let result = try!(odt.render_book());
let mut f = try!(File::create(file).map_err(|_| Error::Render("could not create ODT file")));
try!(f.write_all(&result.as_bytes()).map_err(|_| Error::Render("problem when writing to ODT file")));
println!("Successfully generated ODT file: {}", file);
Ok(())
}
/// Render book to html according to book options
pub fn render_html(&self, file: &str) -> Result<()> {
if self.verbose {

@ -30,6 +30,7 @@ pub mod error;
pub mod book;
pub mod epub;
pub mod latex;
pub mod odt;
pub use html::HtmlRenderer;
pub use parser::Parser;
@ -40,6 +41,7 @@ pub use error::{Result, Error};
pub use book::Book;
pub use epub::EpubRenderer;
pub use latex::LatexRenderer;
pub use odt::OdtRenderer;
mod zipper;
mod templates;