reworked code and added ability to build slides
This commit is contained in:
@@ -2,28 +2,34 @@ use std::process;
|
||||
|
||||
use super::Builder;
|
||||
|
||||
pub struct AsciiDoctorBuilder;
|
||||
fn asciidoctor(postfix: &str, in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
let result = process::Command::new(format!("asciidoctor{postfix}"))
|
||||
.arg(format!("{in_path}"))
|
||||
.arg(format!("--out-file={out_path}"))
|
||||
.output();
|
||||
|
||||
impl Builder for AsciiDoctorBuilder {
|
||||
fn build(&self, in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
let result = process::Command::new("asciidoctor")
|
||||
.arg(format!("{in_path}"))
|
||||
.arg(format!("--out-file={out_path}"))
|
||||
.output();
|
||||
|
||||
if let Ok(success) = result {
|
||||
if success.stderr.len() == 0 {
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err(AsciiDoctorBuilder::from_utf8(success.stderr));
|
||||
}
|
||||
if let Ok(success) = result {
|
||||
if success.stderr.len() == 0 {
|
||||
return Ok(());
|
||||
} else {
|
||||
return Err("command failed to execute".to_string());
|
||||
println!("something went wrong");
|
||||
return Err(AsciiDoctorDocsBuilder::from_utf8(success.stderr));
|
||||
}
|
||||
} else {
|
||||
println!("{}", result.unwrap_err());
|
||||
return Err("asciidoctor not installed. You may need to run docki setup!".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
impl AsciiDoctorBuilder {
|
||||
pub struct AsciiDoctorDocsBuilder;
|
||||
|
||||
impl Builder for AsciiDoctorDocsBuilder {
|
||||
fn build(&self, in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
return asciidoctor("", in_path, out_path);
|
||||
}
|
||||
}
|
||||
|
||||
impl AsciiDoctorDocsBuilder {
|
||||
fn from_utf8(input: Vec<u8>) -> String {
|
||||
return match String::from_utf8(input) {
|
||||
Ok(m) => m,
|
||||
@@ -31,3 +37,11 @@ impl AsciiDoctorBuilder {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AsciiDoctorSlideBuilder;
|
||||
|
||||
impl Builder for AsciiDoctorSlideBuilder {
|
||||
fn build(&self, in_path: &str, out_path: &str) -> Result<(), String> {
|
||||
return asciidoctor("-revealjs-linux", in_path, out_path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user