1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-05-28 09:56:23 +02:00

add odt feature flag

closes #61 by making odt output optional
This commit is contained in:
stefan0xC 2022-02-24 10:01:35 +01:00
parent a45a1d53ec
commit e6883109f3
5 changed files with 8 additions and 1 deletions

View File

@ -41,6 +41,7 @@ default = ["binary", "proofread", "syntect"]
proofread = ["caribon", "reqwest", "url", "serde", "serde", "serde_json", "serde_derive"]
binary = ["clap", "simplelog", "tempdir", "console", "indicatif", "textwrap"]
nightly = ["punkt", "hyphenation"]
odt = []
[build-dependencies]
crowbook-intl = "0.2"

View File

@ -29,6 +29,7 @@ use crate::lang;
use crate::latex::{Latex, Pdf, ProofLatex, ProofPdf};
use crate::misc;
use crate::number::Number;
#[cfg(feature = "odt")]
use crate::odt::Odt;
use crate::parser::Features;
use crate::parser::Parser;
@ -239,12 +240,13 @@ impl Book {
Box::new(ProofPdf {}),
)
.add_format("epub", lformat!("EPUB"), Box::new(Epub {}))
.add_format("odt", lformat!("ODT"), Box::new(Odt {}))
.add_format(
"html.if",
lformat!("HTML (interactive fiction)"),
Box::new(HtmlIf {}),
);
#[cfg(feature = "odt")]
book.add_format("odt", lformat!("ODT"), Box::new(Odt {}));
book
}

View File

@ -145,6 +145,7 @@ mod html_single;
mod lang;
mod latex;
mod number;
#[cfg(feature = "odt")]
mod odt;
mod parser;
mod renderer;

View File

@ -67,6 +67,7 @@ pub mod epub3 {
pub static TITLE: &str = include_str!("../../templates/epub3/titlepage.xhtml");
}
#[cfg(features = "odt")]
pub mod odt {
pub static CONTENT: &str = include_str!("../../templates/odt/content.xml");
pub static ODT: &[u8] = include_bytes!("../../templates/odt/template.odt");

View File

@ -106,6 +106,7 @@ This is forbidden because we are supposed \
}
/// Unzip a file and deletes it afterwards
#[cfg(features = "odt")]
pub fn unzip(&mut self, file: &str) -> Result<()> {
let output = Command::new("unzip")
.current_dir(&self.path)
@ -191,6 +192,7 @@ This is forbidden because we are supposed \
}
/// zip all files in zipper's tmp dir to a given file name and write to odt file
#[cfg(features = "odt")]
pub fn generate_odt(&mut self, command_name: &str, odt_file: &mut dyn Write) -> Result<String> {
let mut command = Command::new(command_name);
command.arg("-r");